Files
OrcaSlicer/src/slic3r/GUI/WebViewDialog.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

183 lines
5.2 KiB
C++

#ifndef slic3r_WebViewDialog_hpp_
#define slic3r_WebViewDialog_hpp_
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include <wx/setup.h>
#include <wx/string.h>
#include <wx/event.h>
#include <string>
#include <functional>
#include <wx/dialog.h>
#include <wx/accel.h>
#include <wx/webview.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 "Lazy.hpp"
namespace Slic3r {
class NetworkAgent;
namespace GUI {
class WebViewPanel : public wxPanel, public LazyInstance<WebViewPanel>
{
public:
WebViewPanel(wxWindow *parent);
virtual ~WebViewPanel();
void load_url(wxString& url);
void UpdateState();
void OnIdle(wxIdleEvent& evt);
void OnUrl(wxCommandEvent& evt);
void OnBack(wxCommandEvent& evt);
void OnForward(wxCommandEvent& evt);
void OnStop(wxCommandEvent& evt);
void OnReload(wxCommandEvent& evt);
void OnNavigationRequest(wxWebViewEvent& evt);
void OnNavigationComplete(wxWebViewEvent& evt);
void OnDocumentLoaded(wxWebViewEvent& evt);
void OnTitleChanged(wxWebViewEvent &evt);
void OnNewWindow(wxWebViewEvent& evt);
void OnScriptMessage(wxWebViewEvent& evt);
void OnScriptResponseMessage(wxCommandEvent& evt);
void OnViewSourceRequest(wxCommandEvent& evt);
void OnViewTextRequest(wxCommandEvent& evt);
void OnToolsClicked(wxCommandEvent& evt);
void OnError(wxWebViewEvent& evt);
void OnCut(wxCommandEvent& evt);
void OnCopy(wxCommandEvent& evt);
void OnPaste(wxCommandEvent& evt);
void OnUndo(wxCommandEvent& evt);
void OnRedo(wxCommandEvent& evt);
void OnMode(wxCommandEvent& evt);
void RunScript(const wxString& javascript);
void OnRunScriptString(wxCommandEvent& evt);
void OnRunScriptInteger(wxCommandEvent& evt);
void OnRunScriptDouble(wxCommandEvent& evt);
void OnRunScriptBool(wxCommandEvent& evt);
void OnRunScriptObject(wxCommandEvent& evt);
void OnRunScriptArray(wxCommandEvent& evt);
void OnRunScriptDOM(wxCommandEvent& evt);
void OnRunScriptUndefined(wxCommandEvent& evt);
void OnRunScriptNull(wxCommandEvent& evt);
void OnRunScriptDate(wxCommandEvent& evt);
void OnRunScriptMessage(wxCommandEvent& evt);
void OnRunScriptCustom(wxCommandEvent& evt);
void OnAddUserScript(wxCommandEvent& evt);
void OnSetCustomUserAgent(wxCommandEvent& evt);
void OnClearSelection(wxCommandEvent& evt);
void OnDeleteSelection(wxCommandEvent& evt);
void OnSelectAll(wxCommandEvent& evt);
void OnLoadScheme(wxCommandEvent& evt);
void OnUseMemoryFS(wxCommandEvent& evt);
void OnEnableContextMenu(wxCommandEvent& evt);
void OnEnableDevTools(wxCommandEvent& evt);
void OnClose(wxCloseEvent& evt);
wxTimer * m_LoginUpdateTimer{nullptr};
void OnFreshLoginStatus(wxTimerEvent &event);
public:
void SendRecentList(int images);
void SetLoginPanelVisibility(bool bshow);
void SendDesignStaffpick(bool on);
void OpenModelDetail(std::string id, NetworkAgent *agent);
void SendLoginInfo();
void ShowNetpluginTip();
void SendCloudProvidersInfo();
void get_design_staffpick(int offset, int limit, std::function<void(std::string)> callback);
int get_model_mall_detail_url(std::string *url, std::string id);
void update_mode();
bool Show(bool show = true) override;
private:
void create_browser();
void reset_browser();
wxWebView* m_browser;
wxString m_home_url;
bool m_reset_on_show{false};
wxButton * m_button_stop;
wxTextCtrl *m_url;
#if !BBL_RELEASE_TO_PUBLIC
// Created only by the internal-build toolbar in the constructor.
wxBoxSizer *bSizer_toolbar;
wxButton * m_button_back;
wxButton * m_button_forward;
wxButton * m_button_reload;
wxButton * m_button_tools;
#endif //BBL_RELEASE_TO_PUBLIC
wxMenu* m_tools_menu;
wxMenuItem* m_tools_handle_navigation;
wxMenuItem* m_tools_handle_new_window;
wxMenuItem* m_edit_cut;
wxMenuItem* m_edit_copy;
wxMenuItem* m_edit_paste;
wxMenuItem* m_edit_undo;
wxMenuItem* m_edit_redo;
wxMenuItem* m_edit_mode;
wxMenuItem* m_script_string;
wxMenuItem* m_script_integer;
wxMenuItem* m_script_double;
wxMenuItem* m_script_bool;
wxMenuItem* m_script_object;
wxMenuItem* m_script_array;
wxMenuItem* m_script_dom;
wxMenuItem* m_script_undefined;
wxMenuItem* m_script_null;
wxMenuItem* m_script_date;
wxMenuItem* m_script_message;
wxMenuItem* m_script_custom;
wxMenuItem* m_selection_clear;
wxMenuItem* m_selection_delete;
wxMenuItem* m_context_menu;
wxMenuItem* m_dev_tools;
wxInfoBar *m_info;
long m_zoomFactor;
// Last executed JavaScript snippet, for convenience.
wxString m_javascript;
wxString m_response_js;
DECLARE_EVENT_TABLE()
};
class SourceViewDialog : public wxDialog
{
public:
SourceViewDialog(wxWindow* parent, wxString source);
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */