Files
OrcaSlicer/src/slic3r/GUI/PrinterWebView.hpp
T
a6dbf2502d Device tab blank for webui printers after switching language (#14547)
* Save device url in all cases and load printer url after hot-reload finishes

* Recreate web view from scratch as only URL fix seems not robust enough

* Add the same robust browser recreation for WebViewDialog

It should eliminate possible issue with blank Home and other pages
in the same way as Printer page

* Remove redundant fallback leftover

* Fix webview reset state and replay Project info on page reload

The first-show webview reset now runs only on Windows, reloads the last
printer URL and resets the Project page's ready state. The Project tab
replays its 3MF info whenever the page reloads, so it no longer goes
blank after a theme switch or a slow first load. The Device tab no longer
loads an extra time on first open, and the Home tab no longer navigates
twice. NeedsRecreateOnShow() logs is_recreating_gui so one language
switch shows whether the reset ever fires.

* Build plugin pages on first show

A language switch rebuilt every plugin page's browser while the main
window was being recreated, which left plugin tabs blank on Windows.
Plugin pages are now lazy pages, never prebuilt, and are removed left
to right so removing pages never builds one only to destroy it.

A plugin page's script now starts when its tab is first opened;
messages posted before that are dropped.

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
Co-authored-by: SoftFever <103989404+SoftFever@users.noreply.github.com>
2026-10-03 20:06:50 +08:00

81 lines
1.7 KiB
C++

#ifndef slic3r_PrinterWebView_hpp_
#define slic3r_PrinterWebView_hpp_
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include <wx/setup.h>
#include <wx/event.h>
#include <wx/webview.h>
#include <wx/string.h>
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h"
#include "wx/numdlg.h"
#include "wx/infobar.h"
#include "wx/filesys.h"
#include "wx/fs_arc.h"
#include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#include <wx/panel.h>
#include <wx/tbarbase.h>
#include "wx/textctrl.h"
#include <wx/timer.h>
#include <memory>
#include "Lazy.hpp"
namespace Slic3r {
namespace GUI {
class PrinterWebViewHandler;
class PrinterWebView : public wxPanel, public LazyInstance<PrinterWebView> {
public:
PrinterWebView(wxWindow *parent);
virtual ~PrinterWebView();
void load_url(wxString& url, wxString apikey = "");
void UpdateState();
void OnClose(wxCloseEvent& evt);
void OnError(wxWebViewEvent& evt);
void OnLoaded(wxWebViewEvent& evt);
void OnNewWindow(wxWebViewEvent& evt);
void OnScriptMessage(wxWebViewEvent& evt);
void reload();
void update_mode();
bool Show(bool show = true) override;
private:
friend class PrinterWebViewHandler;
void SendAPIKey();
void create_browser();
void reset_browser();
wxWebView* m_browser;
long m_zoomFactor;
wxString m_apikey;
bool m_apikey_sent;
// Last url passed to load_url(), reloaded after reset_browser().
wxString m_url;
wxString m_url_deferred;
std::unique_ptr<PrinterWebViewHandler> m_handler;
bool m_reset_on_show{false};
// DECLARE_EVENT_TABLE()
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */