From 0804ef5e279087baa8ccd16eb2cad043192c8b7c Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 9 Oct 2021 17:33:39 +0200 Subject: [PATCH] feat(modulo): add auto startup wizard page --- espanso-modulo/src/sys/interop/interop.h | 2 + espanso-modulo/src/sys/interop/mod.rs | 2 + espanso-modulo/src/sys/wizard/mod.rs | 22 + espanso-modulo/src/sys/wizard/wizard.cpp | 49 ++- espanso-modulo/src/sys/wizard/wizard.fbp | 402 +++++++++++++++++++ espanso-modulo/src/sys/wizard/wizard_gui.cpp | 42 ++ espanso-modulo/src/sys/wizard/wizard_gui.h | 7 + espanso-modulo/src/wizard/mod.rs | 2 + 8 files changed, 527 insertions(+), 1 deletion(-) diff --git a/espanso-modulo/src/sys/interop/interop.h b/espanso-modulo/src/sys/interop/interop.h index fdd3dcd..2d97c1e 100644 --- a/espanso-modulo/src/sys/interop/interop.h +++ b/espanso-modulo/src/sys/interop/interop.h @@ -109,6 +109,7 @@ typedef struct WizardMetadata { const int is_legacy_version_page_enabled; const int is_wrong_edition_page_enabled; const int is_migrate_page_enabled; + const int is_auto_start_page_enabled; const int is_add_path_page_enabled; const int is_accessibility_page_enabled; @@ -121,6 +122,7 @@ typedef struct WizardMetadata { // METHODS int (*is_legacy_version_running)(); int (*backup_and_migrate)(); + int (*auto_start)(int); int (*add_to_path)(); int (*enable_accessibility)(); int (*is_accessibility_enabled)(); diff --git a/espanso-modulo/src/sys/interop/mod.rs b/espanso-modulo/src/sys/interop/mod.rs index d4fde29..debd2b9 100644 --- a/espanso-modulo/src/sys/interop/mod.rs +++ b/espanso-modulo/src/sys/interop/mod.rs @@ -127,6 +127,7 @@ pub struct WizardMetadata { pub is_legacy_version_page_enabled: c_int, pub is_wrong_edition_page_enabled: c_int, pub is_migrate_page_enabled: c_int, + pub is_auto_start_page_enabled: c_int, pub is_add_path_page_enabled: c_int, pub is_accessibility_page_enabled: c_int, @@ -138,6 +139,7 @@ pub struct WizardMetadata { pub is_legacy_version_running: extern "C" fn() -> c_int, pub backup_and_migrate: extern "C" fn() -> c_int, + pub auto_start: extern "C" fn(auto_start: c_int) -> c_int, pub add_to_path: extern "C" fn() -> c_int, pub enable_accessibility: extern "C" fn() -> c_int, pub is_accessibility_enabled: extern "C" fn() -> c_int, diff --git a/espanso-modulo/src/sys/wizard/mod.rs b/espanso-modulo/src/sys/wizard/mod.rs index 4c02f09..d128992 100644 --- a/espanso-modulo/src/sys/wizard/mod.rs +++ b/espanso-modulo/src/sys/wizard/mod.rs @@ -81,6 +81,22 @@ pub fn show(options: WizardOptions) -> bool { } } + extern "C" fn auto_start(auto_start: c_int) -> c_int { + let lock = HANDLERS + .lock() + .expect("unable to acquire lock in auto_start method"); + let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers"); + if let Some(handler_ref) = handlers_ref.auto_start.as_ref() { + if (*handler_ref)(auto_start != 0) { + 1 + } else { + 0 + } + } else { + -1 + } + } + extern "C" fn add_to_path() -> c_int { let lock = HANDLERS .lock() @@ -169,6 +185,11 @@ pub fn show(options: WizardOptions) -> bool { } else { 0 }, + is_auto_start_page_enabled: if options.is_auto_start_page_enabled { + 1 + } else { + 0 + }, is_add_path_page_enabled: if options.is_add_path_page_enabled { 1 } else { @@ -192,6 +213,7 @@ pub fn show(options: WizardOptions) -> bool { is_legacy_version_running, backup_and_migrate, + auto_start, add_to_path, enable_accessibility, is_accessibility_enabled, diff --git a/espanso-modulo/src/sys/wizard/wizard.cpp b/espanso-modulo/src/sys/wizard/wizard.cpp index 2764768..5b9de10 100644 --- a/espanso-modulo/src/sys/wizard/wizard.cpp +++ b/espanso-modulo/src/sys/wizard/wizard.cpp @@ -32,7 +32,8 @@ const int MOVE_BUNDLE_PAGE_INDEX = WELCOME_PAGE_INDEX + 1; const int LEGACY_VERSION_PAGE_INDEX = MOVE_BUNDLE_PAGE_INDEX + 1; const int WRONG_EDITION_PAGE_INDEX = LEGACY_VERSION_PAGE_INDEX + 1; const int MIGRATE_PAGE_INDEX = WRONG_EDITION_PAGE_INDEX + 1; -const int ADD_PATH_PAGE_INDEX = MIGRATE_PAGE_INDEX + 1; +const int AUTO_START_PAGE_INDEX = MIGRATE_PAGE_INDEX + 1; +const int ADD_PATH_PAGE_INDEX = AUTO_START_PAGE_INDEX + 1; const int ACCESSIBILITY_PAGE_INDEX = ADD_PATH_PAGE_INDEX + 1; const int MAX_PAGE_INDEX = ACCESSIBILITY_PAGE_INDEX + 1; // Update if a new page is added at the end @@ -82,6 +83,11 @@ int find_next_page(int current_index) { return MIGRATE_PAGE_INDEX; } + case AUTO_START_PAGE_INDEX: + if (wizard_metadata->is_auto_start_page_enabled) + { + return AUTO_START_PAGE_INDEX; + } case ADD_PATH_PAGE_INDEX: if (wizard_metadata->is_add_path_page_enabled) { @@ -105,6 +111,7 @@ protected: void welcome_start_clicked(wxCommandEvent &event); void migrate_button_clicked(wxCommandEvent &event); void migrate_compatibility_mode_clicked(wxCommandEvent &event); + void auto_start_continue_clicked( wxCommandEvent& event ); void add_path_continue_clicked( wxCommandEvent& event ); void accessibility_enable_clicked( wxCommandEvent& event ); void quit_espanso_clicked( wxCommandEvent& event ); @@ -218,6 +225,45 @@ void DerivedFrame::migrate_button_clicked(wxCommandEvent &event) } } +void DerivedFrame::auto_start_continue_clicked( wxCommandEvent& event ) { + if (!auto_start_checkbox->IsChecked()) { + if (wizard_metadata->auto_start) + { + wizard_metadata->auto_start(0); + } + this->navigate_to_next_page_or_close(); + return; + } + + if (wizard_metadata->auto_start) + { + while (true) { + int result = wizard_metadata->auto_start(1); + if (result == 1) + { + this->navigate_to_next_page_or_close(); + return; + } + else + { + wxMessageDialog* dialog = new wxMessageDialog(this, + "An error occurred while registering Espanso as a service, please check the logs for more information.\nDo you want to retry? You can always configure this option later", + "Operation failed", + wxCENTER | wxOK_DEFAULT | wxOK | wxCANCEL | + wxICON_EXCLAMATION); + + dialog->SetOKLabel("Retry"); + + int prompt_result = dialog->ShowModal(); + if (prompt_result == wxID_CANCEL) { + this->navigate_to_next_page_or_close(); + break; + } + } + } + } +} + void DerivedFrame::add_path_continue_clicked( wxCommandEvent& event ) { if (!add_path_checkbox->IsChecked()) { this->navigate_to_next_page_or_close(); @@ -253,6 +299,7 @@ void DerivedFrame::add_path_continue_clicked( wxCommandEvent& event ) { } } + void DerivedFrame::accessibility_enable_clicked( wxCommandEvent& event ) { if (wizard_metadata->enable_accessibility) diff --git a/espanso-modulo/src/sys/wizard/wizard.fbp b/espanso-modulo/src/sys/wizard/wizard.fbp index 7529b3d..913ec19 100644 --- a/espanso-modulo/src/sys/wizard/wizard.fbp +++ b/espanso-modulo/src/sys/wizard/wizard.fbp @@ -1971,6 +1971,408 @@ + + a page + 0 + + 1 + 1 + 1 + 1 + + + + + + wxSYS_COLOUR_WINDOW + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + auto_start_panel + 1 + + + protected + 1 + + Resizable + 1 + + ; ; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + bSizer2122 + wxVERTICAL + none + + 20 + wxALIGN_CENTER_HORIZONTAL|wxALIGN_LEFT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + ,90,92,18,70,0 + 0 + 0 + wxID_ANY + Launch on System startup + 0 + + 0 + + + 0 + + 1 + auto_start_title + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + + 0 + + 20 + protected + 0 + + + + 10 + wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Espanso can be launched automatically when you start your PC. Do you want to proceed? + 0 + + 0 + + + 0 + + 1 + auto_start_description + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + 500 + + + + 20 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Yes, launch Espanso on system startup (recommended) + + 0 + + + 0 + + 1 + auto_start_checkbox + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 10 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Note: you can always disable this option later. + 0 + + 0 + + + 0 + + 1 + auto_start_note + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + 500 + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 10 + wxALIGN_RIGHT|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 1 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Continue + + 0 + + 0 + + + 0 + + 1 + auto_start_continue + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + auto_start_continue_clicked + + + + + a page 0 diff --git a/espanso-modulo/src/sys/wizard/wizard_gui.cpp b/espanso-modulo/src/sys/wizard/wizard_gui.cpp index bcda087..bb53755 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.cpp +++ b/espanso-modulo/src/sys/wizard/wizard_gui.cpp @@ -219,6 +219,46 @@ WizardFrame::WizardFrame( wxWindow* parent, wxWindowID id, const wxString& title migrate_panel->Layout(); bSizer211->Fit( migrate_panel ); m_simplebook->AddPage( migrate_panel, wxT("a page"), false ); + auto_start_panel = new wxPanel( m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + auto_start_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + + wxBoxSizer* bSizer2122; + bSizer2122 = new wxBoxSizer( wxVERTICAL ); + + auto_start_title = new wxStaticText( auto_start_panel, wxID_ANY, wxT("Launch on System startup"), wxDefaultPosition, wxDefaultSize, 0 ); + auto_start_title->Wrap( -1 ); + auto_start_title->SetFont( wxFont( 18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) ); + + bSizer2122->Add( auto_start_title, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_LEFT|wxTOP, 20 ); + + + bSizer2122->Add( 0, 20, 0, 0, 5 ); + + auto_start_description = new wxStaticText( auto_start_panel, wxID_ANY, wxT("Espanso can be launched automatically when you start your PC. \n\nDo you want to proceed?"), wxDefaultPosition, wxDefaultSize, 0 ); + auto_start_description->Wrap( 500 ); + bSizer2122->Add( auto_start_description, 0, wxLEFT|wxRIGHT|wxTOP, 10 ); + + auto_start_checkbox = new wxCheckBox( auto_start_panel, wxID_ANY, wxT("Yes, launch Espanso on system startup (recommended)"), wxDefaultPosition, wxDefaultSize, 0 ); + auto_start_checkbox->SetValue(true); + bSizer2122->Add( auto_start_checkbox, 0, wxALL, 20 ); + + auto_start_note = new wxStaticText( auto_start_panel, wxID_ANY, wxT("Note: you can always disable this option later."), wxDefaultPosition, wxDefaultSize, 0 ); + auto_start_note->Wrap( 500 ); + bSizer2122->Add( auto_start_note, 0, wxALL, 10 ); + + + bSizer2122->Add( 0, 0, 1, wxEXPAND, 5 ); + + auto_start_continue = new wxButton( auto_start_panel, wxID_ANY, wxT("Continue"), wxDefaultPosition, wxDefaultSize, 0 ); + + auto_start_continue->SetDefault(); + bSizer2122->Add( auto_start_continue, 0, wxALIGN_RIGHT|wxALL, 10 ); + + + auto_start_panel->SetSizer( bSizer2122 ); + auto_start_panel->Layout(); + bSizer2122->Fit( auto_start_panel ); + m_simplebook->AddPage( auto_start_panel, wxT("a page"), false ); add_path_panel = new wxPanel( m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); add_path_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); @@ -326,6 +366,7 @@ WizardFrame::WizardFrame( wxWindow* parent, wxWindowID id, const wxString& title wrong_edition_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::quit_espanso_clicked ), NULL, this ); migrate_compatibility_mode_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_compatibility_mode_clicked ), NULL, this ); migrate_backup_and_migrate_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_button_clicked ), NULL, this ); + auto_start_continue->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::auto_start_continue_clicked ), NULL, this ); add_path_continue_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::add_path_continue_clicked ), NULL, this ); accessibility_enable_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::accessibility_enable_clicked ), NULL, this ); } @@ -340,6 +381,7 @@ WizardFrame::~WizardFrame() wrong_edition_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::quit_espanso_clicked ), NULL, this ); migrate_compatibility_mode_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_compatibility_mode_clicked ), NULL, this ); migrate_backup_and_migrate_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_button_clicked ), NULL, this ); + auto_start_continue->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::auto_start_continue_clicked ), NULL, this ); add_path_continue_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::add_path_continue_clicked ), NULL, this ); accessibility_enable_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::accessibility_enable_clicked ), NULL, this ); diff --git a/espanso-modulo/src/sys/wizard/wizard_gui.h b/espanso-modulo/src/sys/wizard/wizard_gui.h index 5e59cf5..1a9e24a 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.h +++ b/espanso-modulo/src/sys/wizard/wizard_gui.h @@ -69,6 +69,12 @@ class WizardFrame : public wxFrame wxHyperlinkCtrl* migrate_link; wxButton* migrate_compatibility_mode_button; wxButton* migrate_backup_and_migrate_button; + wxPanel* auto_start_panel; + wxStaticText* auto_start_title; + wxStaticText* auto_start_description; + wxCheckBox* auto_start_checkbox; + wxStaticText* auto_start_note; + wxButton* auto_start_continue; wxPanel* add_path_panel; wxStaticText* add_path_title; wxStaticText* add_path_description; @@ -92,6 +98,7 @@ class WizardFrame : public wxFrame virtual void quit_espanso_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void migrate_compatibility_mode_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void migrate_button_clicked( wxCommandEvent& event ) { event.Skip(); } + virtual void auto_start_continue_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void add_path_continue_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void accessibility_enable_clicked( wxCommandEvent& event ) { event.Skip(); } diff --git a/espanso-modulo/src/wizard/mod.rs b/espanso-modulo/src/wizard/mod.rs index 3547cd9..afe90db 100644 --- a/espanso-modulo/src/wizard/mod.rs +++ b/espanso-modulo/src/wizard/mod.rs @@ -27,6 +27,7 @@ pub struct WizardOptions { pub is_legacy_version_page_enabled: bool, pub is_wrong_edition_page_enabled: bool, pub is_migrate_page_enabled: bool, + pub is_auto_start_page_enabled: bool, pub is_add_path_page_enabled: bool, pub is_accessibility_page_enabled: bool, @@ -42,6 +43,7 @@ pub struct WizardOptions { pub struct WizardHandlers { pub is_legacy_version_running: Option bool + Send>>, pub backup_and_migrate: Option MigrationResult + Send>>, + pub auto_start: Option bool + Send>>, pub add_to_path: Option bool + Send>>, pub enable_accessibility: Option>, pub is_accessibility_enabled: Option bool + Send>>,