Files
OrcaSlicer/src/slic3r/GUI/PrinterWebView.hpp
T
Lam Wei Lun 37e3ce6013 Keep the web Device page loaded when its tab is reselected
Selecting the web Device tab, or changing the printer preset, called
load_url with the same URL. That navigated the webview again and reloaded
the printer UI, dropping its in-page state such as zoom.

PrinterWebView now remembers the URL, API key and host type of its last
finished load and skips navigation when all three match. A host type change
still reloads, since it selects the page handler. A failed load is not
remembered, so the next selection retries.

Fixes #16752
2026-10-22 17:36:31 +08:00

86 lines
2.0 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"
#include "libslic3r/PrintConfig.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;
// Host type the page was loaded for; it selects the handler, so a change needs a reload.
PrintHostType m_host_type{htOctoPrint};
// True once the page for m_url has finished loading in m_browser.
bool m_url_loaded{false};
std::unique_ptr<PrinterWebViewHandler> m_handler;
bool m_reset_on_show{false};
// DECLARE_EVENT_TABLE()
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */