mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-13 19:01:21 +00:00
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>
This commit is contained in:
co-authored by
SoftFever
Noisyfox
SoftFever
parent
8a6377f087
commit
a6dbf2502d
@@ -1,6 +1,7 @@
|
||||
#include "PluginPages.hpp"
|
||||
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "slic3r/GUI/GUI.hpp"
|
||||
#include "slic3r/GUI/Notebook.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/Widgets/Button.hpp"
|
||||
@@ -183,8 +184,10 @@ void PluginPages::initialize(Notebook* parent)
|
||||
|
||||
void PluginPages::shutdown()
|
||||
{
|
||||
while (!m_pages.empty())
|
||||
remove_page(m_pages.begin()->first);
|
||||
// Removing the selected tab selects the tab to its left. In tab order that is a built-in tab,
|
||||
// never an unbuilt plugin page that is removed next and would be built only to be destroyed.
|
||||
for (const PluginCapabilityId& id : std::vector<PluginCapabilityId>(m_order))
|
||||
remove_page(id);
|
||||
m_parent = nullptr;
|
||||
}
|
||||
|
||||
@@ -225,8 +228,7 @@ bool PluginPages::create_page(const PluginCapabilityId& id)
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to get icon for plugin " << id.plugin_key;
|
||||
}
|
||||
|
||||
auto* page = new PluginPage(m_parent, std::move(capability));
|
||||
|
||||
wxBitmap bitmap;
|
||||
if (!icon.empty()) {
|
||||
try {
|
||||
boost::filesystem::path icon_path(icon);
|
||||
@@ -234,7 +236,7 @@ bool PluginPages::create_page(const PluginCapabilityId& id)
|
||||
if (extension == ".svg" || extension == ".png")
|
||||
icon_path.replace_extension();
|
||||
|
||||
page->set_icon(create_scaled_bitmap(icon_path.string(), m_parent, 20));
|
||||
bitmap = create_scaled_bitmap(icon_path.string(), m_parent, 20);
|
||||
} catch (const std::exception& error) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to load icon for plugin " << id.plugin_key << ": " << error.what();
|
||||
} catch (...) {
|
||||
@@ -242,7 +244,15 @@ bool PluginPages::create_page(const PluginCapabilityId& id)
|
||||
}
|
||||
}
|
||||
|
||||
m_pages.emplace(id, page);
|
||||
// Built the first time its tab is shown, so a language switch never creates the page's browser
|
||||
// while the main window is being rebuilt. Never prebuilt: the idle queue cannot drop a page
|
||||
// that remove_page() destroys.
|
||||
auto* page = new GUI::LazyPage<PluginPage>(m_parent, GUI::into_u8(page_tab_id(id)), -1,
|
||||
[capability = std::move(capability)](wxWindow* parent) {
|
||||
return new PluginPage(parent, capability);
|
||||
});
|
||||
|
||||
m_pages.emplace(id, Page{page, bitmap});
|
||||
m_order.push_back(id);
|
||||
return true;
|
||||
}
|
||||
@@ -271,16 +281,10 @@ void PluginPages::on_plugin_register(const std::string& plugin_key)
|
||||
|
||||
void PluginPages::on_plugin_deregister(const std::string& plugin_key)
|
||||
{
|
||||
for (auto it = m_pages.begin(); it != m_pages.end();) {
|
||||
if (it->first.plugin_key != plugin_key) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
const PluginCapabilityId id = it->first;
|
||||
++it;
|
||||
remove_page(id);
|
||||
}
|
||||
// In tab order, as in shutdown().
|
||||
for (const PluginCapabilityId& id : std::vector<PluginCapabilityId>(m_order))
|
||||
if (id.plugin_key == plugin_key)
|
||||
remove_page(id);
|
||||
}
|
||||
|
||||
void PluginPages::remove_page(const PluginCapabilityId& id)
|
||||
@@ -289,8 +293,10 @@ void PluginPages::remove_page(const PluginCapabilityId& id)
|
||||
if (it == m_pages.end())
|
||||
return;
|
||||
|
||||
PluginPage* page = it->second;
|
||||
page->detach_capability();
|
||||
GUI::LazyPage<PluginPage>* page = it->second.page;
|
||||
// Only a built page has installed a message sender on the capability.
|
||||
if (PluginPage* built = page->get())
|
||||
built->detach_capability();
|
||||
|
||||
m_pages.erase(it);
|
||||
m_order.erase(std::remove(m_order.begin(), m_order.end(), id), m_order.end());
|
||||
@@ -348,26 +354,27 @@ void PluginPages::relayout()
|
||||
bool up_to_date = page_count >= tab_ids.size();
|
||||
for (size_t i = 0; up_to_date && i < tab_ids.size(); ++i)
|
||||
up_to_date = m_parent->GetPageName(page_count - tab_ids.size() + i) == page_tab_id(tab_ids[i]);
|
||||
for (const auto& [id, page] : m_pages) {
|
||||
for (const auto& [id, entry] : m_pages) {
|
||||
if (!up_to_date)
|
||||
break;
|
||||
const bool wanted = std::find(tab_ids.begin(), tab_ids.end(), id) != tab_ids.end();
|
||||
up_to_date = (m_parent->FindPage(page) != wxNOT_FOUND) == wanted;
|
||||
up_to_date = entry.page->in_book() == wanted;
|
||||
}
|
||||
|
||||
if (!up_to_date) {
|
||||
const wxString id_to_reselect = m_parent->GetSelectedPageName();
|
||||
|
||||
for (const auto& [id, page] : m_pages) {
|
||||
const int idx = m_parent->FindPage(page);
|
||||
// In tab order, as in shutdown().
|
||||
for (const auto& id : m_order) {
|
||||
const int idx = m_parent->FindPage(m_pages.at(id).page);
|
||||
if (idx != wxNOT_FOUND)
|
||||
m_parent->RemovePage(idx);
|
||||
}
|
||||
|
||||
for (const auto& id : tab_ids) {
|
||||
PluginPage* page = m_pages.at(id);
|
||||
m_parent->InsertPage(m_parent->GetPageCount(), page_tab_id(id), page, wxString::FromUTF8(id.name), "",
|
||||
false, page->icon());
|
||||
const Page& entry = m_pages.at(id);
|
||||
m_parent->InsertPage(m_parent->GetPageCount(), page_tab_id(id), entry.page, wxString::FromUTF8(id.name), "",
|
||||
false, entry.icon);
|
||||
}
|
||||
|
||||
if (!id_to_reselect.empty())
|
||||
|
||||
Reference in New Issue
Block a user