mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-09-26 17:03:13 +08:00
SPE-2564: Add javascript listeners only once/
+ keyboard shortcut fix
This commit is contained in:
parent
cfcb284520
commit
189d728b3f
@ -1008,10 +1008,10 @@ void MainFrame::on_tab_change_rename_reload_item(int new_tab)
|
|||||||
|| (m_connect_webview_added && new_tab == m_tabpanel->FindPage(m_connect_webview))
|
|| (m_connect_webview_added && new_tab == m_tabpanel->FindPage(m_connect_webview))
|
||||||
|| (m_printer_webview_added && new_tab == m_tabpanel->FindPage(m_printer_webview)))
|
|| (m_printer_webview_added && new_tab == m_tabpanel->FindPage(m_printer_webview)))
|
||||||
{
|
{
|
||||||
m_menu_item_reload->SetItemLabel(_L("Re&load Web Content") + "\t\xA0" + "F5");
|
m_menu_item_reload->SetItemLabel(_L("Re&load Web Content") + "\tF5");
|
||||||
m_menu_item_reload->SetHelp(_L("Reload Web Content"));
|
m_menu_item_reload->SetHelp(_L("Reload Web Content"));
|
||||||
} else {
|
} else {
|
||||||
m_menu_item_reload->SetItemLabel(_L("Re&load from Disk") + "\t\xA0" + "F5");
|
m_menu_item_reload->SetItemLabel(_L("Re&load from Disk") + "\tF5");
|
||||||
m_menu_item_reload->SetHelp(_L("Reload the plater from disk"));
|
m_menu_item_reload->SetHelp(_L("Reload the plater from disk"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1642,7 +1642,7 @@ void MainFrame::init_menubar_as_editor()
|
|||||||
_L("Reload Web Content"), [this](wxCommandEvent&) { reload_selected_webview(); },
|
_L("Reload Web Content"), [this](wxCommandEvent&) { reload_selected_webview(); },
|
||||||
"", nullptr, [this]() {return is_any_webview_selected(); }, this);
|
"", nullptr, [this]() {return is_any_webview_selected(); }, this);
|
||||||
#else
|
#else
|
||||||
m_menu_item_reload = append_menu_item(editMenu, wxID_ANY, _L("Re&load from Disk") + sep + "F5",
|
m_menu_item_reload = append_menu_item(editMenu, wxID_ANY, _L("Re&load from Disk") + "\tF5",
|
||||||
_L("Reload the plater from disk"), [this](wxCommandEvent&) { reload_item_function_cb(); },
|
_L("Reload the plater from disk"), [this](wxCommandEvent&) { reload_item_function_cb(); },
|
||||||
"", nullptr, [this]() {return reload_item_condition_cb(); }, this);
|
"", nullptr, [this]() {return reload_item_condition_cb(); }, this);
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
@ -636,17 +636,24 @@ void WebViewPanel::define_css()
|
|||||||
|
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
)";
|
)";
|
||||||
#ifdef __APPLE__
|
//#ifdef __APPLE__
|
||||||
|
#if defined(__APPLE__)
|
||||||
// WebView on Windows does read keyboard shortcuts
|
// WebView on Windows does read keyboard shortcuts
|
||||||
// Thus doing f.e. Reload twice would make the oparation to fail
|
// Thus doing f.e. Reload twice would make the oparation to fail
|
||||||
script += R"(
|
script += R"(
|
||||||
|
(function() {
|
||||||
|
const listenerKey = 'custom-click-listener';
|
||||||
|
if (!document[listenerKey]) {
|
||||||
document.addEventListener('keydown', function (event) {
|
document.addEventListener('keydown', function (event) {
|
||||||
if (event.key === 'F5' || (event.ctrlKey && event.key === 'r') || (event.metaKey && event.key === 'r')) {
|
if (event.key === 'F5' || (event.ctrlKey && event.key === 'r') || (event.metaKey && event.key === 'r')) {
|
||||||
window.ExternalApp.postMessage(JSON.stringify({ event: 'reloadHomePage', fromKeyboard: 1}));
|
window.ExternalApp.postMessage(JSON.stringify({ event: 'reloadHomePage', fromKeyboard: 1}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
document[listenerKey] = true;
|
||||||
|
}
|
||||||
|
})();
|
||||||
)";
|
)";
|
||||||
#endif // !_WIN32
|
#endif // __APPLE__
|
||||||
run_script(script);
|
run_script(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1579,6 +1586,8 @@ void PrintablesWebViewPanel::define_css()
|
|||||||
// Capture click on hypertext
|
// Capture click on hypertext
|
||||||
// Rewritten from mobileApp code
|
// Rewritten from mobileApp code
|
||||||
(function() {
|
(function() {
|
||||||
|
const listenerKey = 'custom-click-listener';
|
||||||
|
if (!document[listenerKey]) {
|
||||||
document.addEventListener( 'click', function(event) {
|
document.addEventListener( 'click', function(event) {
|
||||||
const target = event.target.closest('a[href]');
|
const target = event.target.closest('a[href]');
|
||||||
if (!target) return; // Ignore clicks that are not on links
|
if (!target) return; // Ignore clicks that are not on links
|
||||||
@ -1596,19 +1605,27 @@ void PrintablesWebViewPanel::define_css()
|
|||||||
}
|
}
|
||||||
// Default: Allow navigation to proceed
|
// Default: Allow navigation to proceed
|
||||||
},true); // Capture the event during the capture phase
|
},true); // Capture the event during the capture phase
|
||||||
|
document[listenerKey] = true;
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
)";
|
)";
|
||||||
#ifdef __APPLE__
|
#if defined(__APPLE__)
|
||||||
// WebView on Windows does read keyboard shortcuts
|
// WebView on Windows does read keyboard shortcuts
|
||||||
// Thus doing f.e. Reload twice would make the oparation to fail
|
// Thus doing f.e. Reload twice would make the oparation to fail
|
||||||
script += R"(
|
script += R"(
|
||||||
|
(function() {
|
||||||
|
const listenerKey = 'custom-click-listener';
|
||||||
|
if (!document[listenerKey]) {
|
||||||
document.addEventListener('keydown', function (event) {
|
document.addEventListener('keydown', function (event) {
|
||||||
if (event.key === 'F5' || (event.ctrlKey && event.key === 'r') || (event.metaKey && event.key === 'r')) {
|
if (event.key === 'F5' || (event.ctrlKey && event.key === 'r') || (event.metaKey && event.key === 'r')) {
|
||||||
window.ExternalApp.postMessage(JSON.stringify({ event: 'reloadHomePage', fromKeyboard: 1}));
|
window.ExternalApp.postMessage(JSON.stringify({ event: 'reloadHomePage', fromKeyboard: 1}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
document[listenerKey] = true;
|
||||||
|
}
|
||||||
|
})();
|
||||||
)";
|
)";
|
||||||
#endif // !_WIN32
|
#endif // defined(__APPLE__)
|
||||||
run_script(script);
|
run_script(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user