From ad029b626e65dbf0a2982223dcafea95310778e9 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 24 Aug 2021 23:04:25 +0200 Subject: [PATCH] feat(modulo): add wrong edition page in Wizard GUI --- espanso-modulo/src/sys/interop/interop.h | 6 + espanso-modulo/src/sys/interop/mod.rs | 6 + espanso-modulo/src/sys/wizard/mod.rs | 35 +- espanso-modulo/src/sys/wizard/wizard.cpp | 24 +- espanso-modulo/src/sys/wizard/wizard.fbp | 401 +++++++++++++++++++ espanso-modulo/src/sys/wizard/wizard_gui.cpp | 41 ++ espanso-modulo/src/sys/wizard/wizard_gui.h | 7 + espanso-modulo/src/wizard/mod.rs | 9 + 8 files changed, 521 insertions(+), 8 deletions(-) diff --git a/espanso-modulo/src/sys/interop/interop.h b/espanso-modulo/src/sys/interop/interop.h index ccbeb65..fdd3dcd 100644 --- a/espanso-modulo/src/sys/interop/interop.h +++ b/espanso-modulo/src/sys/interop/interop.h @@ -97,12 +97,17 @@ const int MIGRATE_RESULT_CLEAN_FAILURE = 1; const int MIGRATE_RESULT_DIRTY_FAILURE = 2; const int MIGRATE_RESULT_UNKNOWN_FAILURE = 3; +const int DETECTED_OS_UNKNOWN = 0; +const int DETECTED_OS_X11 = 1; +const int DETECTED_OS_WAYLAND = 2; + typedef struct WizardMetadata { const char *version; const int is_welcome_page_enabled; const int is_move_bundle_page_enabled; const int is_legacy_version_page_enabled; + const int is_wrong_edition_page_enabled; const int is_migrate_page_enabled; const int is_add_path_page_enabled; const int is_accessibility_page_enabled; @@ -111,6 +116,7 @@ typedef struct WizardMetadata { const char *welcome_image_path; const char *accessibility_image_1_path; const char *accessibility_image_2_path; + const int detected_os; // METHODS int (*is_legacy_version_running)(); diff --git a/espanso-modulo/src/sys/interop/mod.rs b/espanso-modulo/src/sys/interop/mod.rs index e299c68..2a4a393 100644 --- a/espanso-modulo/src/sys/interop/mod.rs +++ b/espanso-modulo/src/sys/interop/mod.rs @@ -113,6 +113,10 @@ pub const WIZARD_MIGRATE_RESULT_CLEAN_FAILURE: i32 = 1; pub const WIZARD_MIGRATE_RESULT_DIRTY_FAILURE: i32 = 2; pub const WIZARD_MIGRATE_RESULT_UNKNOWN_FAILURE: i32 = 3; +pub const WIZARD_DETECTED_OS_UNKNOWN: i32 = 0; +pub const WIZARD_DETECTED_OS_X11: i32 = 1; +pub const WIZARD_DETECTED_OS_WAYLAND: i32 = 2; + #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct WizardMetadata { @@ -121,6 +125,7 @@ pub struct WizardMetadata { pub is_welcome_page_enabled: c_int, pub is_move_bundle_page_enabled: c_int, 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_add_path_page_enabled: c_int, pub is_accessibility_page_enabled: c_int, @@ -129,6 +134,7 @@ pub struct WizardMetadata { pub welcome_image_path: *const c_char, pub accessibility_image_1_path: *const c_char, pub accessibility_image_2_path: *const c_char, + pub detected_os: c_int, pub is_legacy_version_running: extern fn() -> c_int, pub backup_and_migrate: extern fn() -> c_int, diff --git a/espanso-modulo/src/sys/wizard/mod.rs b/espanso-modulo/src/sys/wizard/mod.rs index ca7d47f..3686694 100644 --- a/espanso-modulo/src/sys/wizard/mod.rs +++ b/espanso-modulo/src/sys/wizard/mod.rs @@ -20,8 +20,17 @@ use std::os::raw::{c_char, c_int}; use std::{ffi::CString, sync::Mutex}; +use crate::sys::interop::{ + WIZARD_DETECTED_OS_UNKNOWN, WIZARD_DETECTED_OS_WAYLAND, WIZARD_DETECTED_OS_X11, +}; use crate::sys::util::convert_to_cstring_or_null; -use crate::{sys::interop::{WIZARD_MIGRATE_RESULT_CLEAN_FAILURE, WIZARD_MIGRATE_RESULT_DIRTY_FAILURE, WIZARD_MIGRATE_RESULT_SUCCESS, WIZARD_MIGRATE_RESULT_UNKNOWN_FAILURE, WizardMetadata}, wizard::{WizardHandlers, WizardOptions}}; +use crate::{ + sys::interop::{ + WizardMetadata, WIZARD_MIGRATE_RESULT_CLEAN_FAILURE, WIZARD_MIGRATE_RESULT_DIRTY_FAILURE, + WIZARD_MIGRATE_RESULT_SUCCESS, WIZARD_MIGRATE_RESULT_UNKNOWN_FAILURE, + }, + wizard::{WizardHandlers, WizardOptions}, +}; lazy_static! { static ref HANDLERS: Mutex> = Mutex::new(None); @@ -126,7 +135,7 @@ pub fn show(options: WizardOptions) -> bool { (*handler_ref)() } } - + { let mut lock = HANDLERS.lock().expect("unable to acquire handlers lock"); *lock = Some(options.handlers) @@ -150,6 +159,11 @@ pub fn show(options: WizardOptions) -> bool { } else { 0 }, + is_wrong_edition_page_enabled: if options.is_wrong_edition_page_enabled { + 1 + } else { + 0 + }, is_migrate_page_enabled: if options.is_migrate_page_enabled { 1 } else { @@ -170,6 +184,11 @@ pub fn show(options: WizardOptions) -> bool { welcome_image_path: c_welcome_image_path_ptr, accessibility_image_1_path: c_accessibility_image_1_path_ptr, accessibility_image_2_path: c_accessibility_image_2_path_ptr, + detected_os: match options.detected_os { + crate::wizard::DetectedOS::Unknown => WIZARD_DETECTED_OS_UNKNOWN, + crate::wizard::DetectedOS::X11 => WIZARD_DETECTED_OS_X11, + crate::wizard::DetectedOS::Wayland => WIZARD_DETECTED_OS_WAYLAND, + }, is_legacy_version_running, backup_and_migrate, @@ -179,9 +198,11 @@ pub fn show(options: WizardOptions) -> bool { on_completed, }; - let successful = unsafe { - super::interop::interop_show_wizard(&wizard_metadata) - }; + let successful = unsafe { super::interop::interop_show_wizard(&wizard_metadata) }; - if successful == 1 { true } else { false } -} \ No newline at end of file + if successful == 1 { + true + } else { + false + } +} diff --git a/espanso-modulo/src/sys/wizard/wizard.cpp b/espanso-modulo/src/sys/wizard/wizard.cpp index bc6463d..2764768 100644 --- a/espanso-modulo/src/sys/wizard/wizard.cpp +++ b/espanso-modulo/src/sys/wizard/wizard.cpp @@ -30,7 +30,8 @@ const int WELCOME_PAGE_INDEX = 0; const int MOVE_BUNDLE_PAGE_INDEX = WELCOME_PAGE_INDEX + 1; const int LEGACY_VERSION_PAGE_INDEX = MOVE_BUNDLE_PAGE_INDEX + 1; -const int MIGRATE_PAGE_INDEX = LEGACY_VERSION_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 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 @@ -71,6 +72,11 @@ int find_next_page(int current_index) { return LEGACY_VERSION_PAGE_INDEX; } + case WRONG_EDITION_PAGE_INDEX: + if (wizard_metadata->is_wrong_edition_page_enabled) + { + return WRONG_EDITION_PAGE_INDEX; + } case MIGRATE_PAGE_INDEX: if (wizard_metadata->is_migrate_page_enabled) { @@ -101,6 +107,7 @@ protected: void migrate_compatibility_mode_clicked(wxCommandEvent &event); void add_path_continue_clicked( wxCommandEvent& event ); void accessibility_enable_clicked( wxCommandEvent& event ); + void quit_espanso_clicked( wxCommandEvent& event ); void navigate_to_next_page_or_close(); void change_default_button(int target_page); @@ -135,6 +142,16 @@ DerivedFrame::DerivedFrame(wxWindow *parent) this->accessibility_image2->SetBitmap(accessiblityImage2); } + // Wrong edition + if (wizard_metadata->is_wrong_edition_page_enabled) { + if (wizard_metadata->detected_os == DETECTED_OS_X11) { + this->wrong_edition_description_x11->Hide(); + } + if (wizard_metadata->detected_os == DETECTED_OS_WAYLAND) { + this->wrong_edition_description_wayland->Hide(); + } + } + // Load the first page int page = find_next_page(-1); if (page >= 0) @@ -244,6 +261,11 @@ void DerivedFrame::accessibility_enable_clicked( wxCommandEvent& event ) } } +void DerivedFrame::quit_espanso_clicked( wxCommandEvent& event ) +{ + Close(true); +} + void DerivedFrame::check_timer_tick(wxTimerEvent &event) { if (this->m_simplebook->GetSelection() == LEGACY_VERSION_PAGE_INDEX) diff --git a/espanso-modulo/src/sys/wizard/wizard.fbp b/espanso-modulo/src/sys/wizard/wizard.fbp index 889b4ac..08eb71e 100644 --- a/espanso-modulo/src/sys/wizard/wizard.fbp +++ b/espanso-modulo/src/sys/wizard/wizard.fbp @@ -1136,6 +1136,407 @@ + + 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 + wrong_edition_panel + 1 + + + protected + 1 + + Resizable + 1 + + ; ; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + bSizer213 + 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 + Incompatibility detected + 0 + + 0 + + + 0 + + 1 + wrong_edition_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 + This version of espanso was compiled to support X11-based systems, but it seems you are on a Wayland-based desktop environment. Unfortunately, the two versions are incompatible. To use espanso, please download the Wayland version from the website. For more information: + 0 + + 0 + + + 0 + + 1 + wrong_edition_description_x11 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + 500 + + + + 10 + wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + This version of espanso was compiled to support Wayland-based systems, but it seems you are on a X11-based desktop environment. Unfortunately, the two versions are incompatible. To use espanso, please download the X11 version from the website. For more information: + 0 + + 0 + + + 0 + + 1 + wrong_edition_description_wayland + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + 500 + + + + 10 + wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + + wxID_ANY + https://espanso.org/install + + 0 + + + 0 + + 1 + wrong_edition_link + + 1 + + + protected + 1 + + Resizable + 1 + + wxHL_DEFAULT_STYLE + ; ; forward_declare + 0 + + https://espanso.org/install + + + + + + + + 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 + Quit Espanso + + 0 + + 0 + + + 0 + + 1 + wrong_edition_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + quit_espanso_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 21a39b9..bfe5050 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.cpp +++ b/espanso-modulo/src/sys/wizard/wizard_gui.cpp @@ -133,6 +133,45 @@ WizardFrame::WizardFrame( wxWindow* parent, wxWindowID id, const wxString& title legacy_version_panel->Layout(); bSizer21->Fit( legacy_version_panel ); m_simplebook->AddPage( legacy_version_panel, wxT("a page"), false ); + wrong_edition_panel = new wxPanel( m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + wrong_edition_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + + wxBoxSizer* bSizer213; + bSizer213 = new wxBoxSizer( wxVERTICAL ); + + wrong_edition_title = new wxStaticText( wrong_edition_panel, wxID_ANY, wxT("Incompatibility detected"), wxDefaultPosition, wxDefaultSize, 0 ); + wrong_edition_title->Wrap( -1 ); + wrong_edition_title->SetFont( wxFont( 18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) ); + + bSizer213->Add( wrong_edition_title, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_LEFT|wxTOP, 20 ); + + + bSizer213->Add( 0, 20, 0, 0, 5 ); + + wrong_edition_description_x11 = new wxStaticText( wrong_edition_panel, wxID_ANY, wxT("This version of espanso was compiled to support X11-based systems, but it seems you are on a Wayland-based desktop environment.\n\nUnfortunately, the two versions are incompatible. To use espanso, please download the Wayland version from the website.\n\nFor more information:"), wxDefaultPosition, wxDefaultSize, 0 ); + wrong_edition_description_x11->Wrap( 500 ); + bSizer213->Add( wrong_edition_description_x11, 0, wxLEFT|wxRIGHT|wxTOP, 10 ); + + wrong_edition_description_wayland = new wxStaticText( wrong_edition_panel, wxID_ANY, wxT("This version of espanso was compiled to support Wayland-based systems, but it seems you are on a X11-based desktop environment.\n\nUnfortunately, the two versions are incompatible. To use espanso, please download the X11 version from the website.\n\nFor more information:"), wxDefaultPosition, wxDefaultSize, 0 ); + wrong_edition_description_wayland->Wrap( 500 ); + bSizer213->Add( wrong_edition_description_wayland, 0, wxLEFT|wxRIGHT|wxTOP, 10 ); + + wrong_edition_link = new wxHyperlinkCtrl( wrong_edition_panel, wxID_ANY, wxT("https://espanso.org/install"), wxT("https://espanso.org/install"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE ); + bSizer213->Add( wrong_edition_link, 0, wxLEFT|wxRIGHT, 10 ); + + + bSizer213->Add( 0, 0, 1, wxEXPAND, 5 ); + + wrong_edition_button = new wxButton( wrong_edition_panel, wxID_ANY, wxT("Quit Espanso"), wxDefaultPosition, wxDefaultSize, 0 ); + + wrong_edition_button->SetDefault(); + bSizer213->Add( wrong_edition_button, 0, wxALIGN_RIGHT|wxALL, 10 ); + + + wrong_edition_panel->SetSizer( bSizer213 ); + wrong_edition_panel->Layout(); + bSizer213->Fit( wrong_edition_panel ); + m_simplebook->AddPage( wrong_edition_panel, wxT("a page"), false ); migrate_panel = new wxPanel( m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); migrate_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); @@ -284,6 +323,7 @@ WizardFrame::WizardFrame( wxWindow* parent, wxWindowID id, const wxString& title m_simplebook->Connect( wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED, wxBookCtrlEventHandler( WizardFrame::on_page_changed ), NULL, this ); welcome_start_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::welcome_start_clicked ), NULL, this ); move_bundle_quit_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::move_bundle_quit_clicked ), NULL, this ); + 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 ); add_path_continue_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::add_path_continue_clicked ), NULL, this ); @@ -297,6 +337,7 @@ WizardFrame::~WizardFrame() m_simplebook->Disconnect( wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED, wxBookCtrlEventHandler( WizardFrame::on_page_changed ), NULL, this ); welcome_start_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::welcome_start_clicked ), NULL, this ); move_bundle_quit_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::move_bundle_quit_clicked ), NULL, this ); + 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 ); add_path_continue_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::add_path_continue_clicked ), NULL, this ); diff --git a/espanso-modulo/src/sys/wizard/wizard_gui.h b/espanso-modulo/src/sys/wizard/wizard_gui.h index 930b818..5e59cf5 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.h +++ b/espanso-modulo/src/sys/wizard/wizard_gui.h @@ -57,6 +57,12 @@ class WizardFrame : public wxFrame wxStaticText* legacy_version_description; wxHyperlinkCtrl* legacy_version_docs_link; wxButton* legacy_version_continue_button; + wxPanel* wrong_edition_panel; + wxStaticText* wrong_edition_title; + wxStaticText* wrong_edition_description_x11; + wxStaticText* wrong_edition_description_wayland; + wxHyperlinkCtrl* wrong_edition_link; + wxButton* wrong_edition_button; wxPanel* migrate_panel; wxStaticText* migrate_title; wxStaticText* migrate_description; @@ -83,6 +89,7 @@ class WizardFrame : public wxFrame virtual void on_page_changed( wxBookCtrlEvent& event ) { event.Skip(); } virtual void welcome_start_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void move_bundle_quit_clicked( wxCommandEvent& event ) { event.Skip(); } + 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 add_path_continue_clicked( wxCommandEvent& event ) { event.Skip(); } diff --git a/espanso-modulo/src/wizard/mod.rs b/espanso-modulo/src/wizard/mod.rs index 1208831..3547cd9 100644 --- a/espanso-modulo/src/wizard/mod.rs +++ b/espanso-modulo/src/wizard/mod.rs @@ -25,6 +25,7 @@ pub struct WizardOptions { pub is_welcome_page_enabled: bool, pub is_move_bundle_page_enabled: bool, pub is_legacy_version_page_enabled: bool, + pub is_wrong_edition_page_enabled: bool, pub is_migrate_page_enabled: bool, pub is_add_path_page_enabled: bool, pub is_accessibility_page_enabled: bool, @@ -33,6 +34,7 @@ pub struct WizardOptions { pub welcome_image_path: Option, pub accessibility_image_1_path: Option, pub accessibility_image_2_path: Option, + pub detected_os: DetectedOS, pub handlers: WizardHandlers, } @@ -53,3 +55,10 @@ pub enum MigrationResult { DirtyFailure, UnknownFailure, } + +#[derive(Debug)] +pub enum DetectedOS { + Unknown, + X11, + Wayland, +}