Force opening hyperlink on App updater.

Refactored open_browser_with_warning_dialog due to poor readability - no changes to funcionality.
This commit is contained in:
David Kocik 2024-08-27 14:19:48 +02:00 committed by Lukas Matena
parent 447dd15681
commit abea96fd8a

View File

@ -3544,19 +3544,13 @@ bool GUI_App::check_updates(const bool invoked_by_user)
// Applicaiton will continue. // Applicaiton will continue.
return true; return true;
} }
namespace {
bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* parent/* = nullptr*/, bool force_remember_choice /*= true*/, int flags/* = 0*/) bool open_dialog_hyperlink_checkbox(wxWindow* parent, AppConfig* app_config)
{ {
bool launch = true;
// warning dialog containes a "Remember my choice" checkbox
std::string option_key = "suppress_hyperlinks";
if (force_remember_choice || app_config->get(option_key).empty()) {
if (app_config->get(option_key).empty()) {
RichMessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO); RichMessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
dialog.ShowCheckBox(_L("Remember my choice")); dialog.ShowCheckBox(_L("Remember my choice"));
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
launch = answer == wxID_YES; bool launch = answer == wxID_YES;
if (dialog.IsCheckBoxChecked()) { if (dialog.IsCheckBoxChecked()) {
wxString preferences_item = _L("Suppress to open hyperlink in browser"); wxString preferences_item = _L("Suppress to open hyperlink in browser");
wxString msg = wxString msg =
@ -3567,19 +3561,47 @@ bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* pa
MessageDialog msg_dlg(parent, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION); MessageDialog msg_dlg(parent, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION);
if (msg_dlg.ShowModal() == wxID_CANCEL) if (msg_dlg.ShowModal() == wxID_CANCEL)
return false; return false;
app_config->set(option_key, answer == wxID_NO ? "1" : "0"); app_config->set("suppress_hyperlinks", answer == wxID_NO ? "1" : "0");
} }
return launch;
} }
if (launch) bool open_dialog_hyperlink(wxWindow* parent)
launch = !app_config->get_bool(option_key); {
}
// warning dialog doesn't containe a "Remember my choice" checkbox
// and will be shown only when "Suppress to open hyperlink in browser" is ON.
else if (app_config->get_bool(option_key)) {
MessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO); MessageDialog dialog(parent, _L("Open hyperlink in default browser?"), _L("PrusaSlicer: Open hyperlink"), wxICON_QUESTION | wxYES_NO);
launch = dialog.ShowModal() == wxID_YES; return dialog.ShowModal() == wxID_YES;
}
}
bool GUI_App::open_browser_with_warning_dialog(const wxString& url, wxWindow* parent/* = nullptr*/, bool force_remember_choice /*= true*/, int flags/* = 0*/)
{
enum class SupressHyperLinksOption{
SHLO_UNCHECKED,
SHLO_ALWAYS_SUPRESS,
SHLO_ALWAYS_ALLOW
};
bool empty = app_config->get("suppress_hyperlinks").empty();
bool checked = app_config->get_bool("suppress_hyperlinks");
SupressHyperLinksOption opt_val =
(empty
? SupressHyperLinksOption::SHLO_UNCHECKED
: (checked
? SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS
: SupressHyperLinksOption::SHLO_ALWAYS_ALLOW));
bool launch = true;
if (opt_val == SupressHyperLinksOption::SHLO_UNCHECKED) {
// no previous action from user
// open dialog with remember checkbox
launch = open_dialog_hyperlink_checkbox(parent, app_config);
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_ALLOW) {
// user already set checkbox to always open
launch = true;
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && force_remember_choice) {
// user already set checkbox or preferences to always supress
launch = false;
} else if (opt_val == SupressHyperLinksOption::SHLO_ALWAYS_SUPRESS && !force_remember_choice) {
// user already set checkbox or preferences to always supress but it is overriden
// no checkbox in dialog
launch = open_dialog_hyperlink(parent);
} }
return launch && wxLaunchDefaultBrowser(url, flags); return launch && wxLaunchDefaultBrowser(url, flags);
} }
@ -3712,7 +3734,7 @@ void GUI_App::app_updater(bool from_user)
return; return;
} }
if (app_data.action == AppUpdaterURLAction::AUUA_OPEN_IN_BROWSER) { if (app_data.action == AppUpdaterURLAction::AUUA_OPEN_IN_BROWSER) {
open_browser_with_warning_dialog(from_u8(app_data.url)); open_browser_with_warning_dialog(from_u8(app_data.url), nullptr, false);
return; return;
} }
// dialog with new version download (installer or app dependent on system) including path selection // dialog with new version download (installer or app dependent on system) including path selection