From 7f7b3cb358ef100003cc3a92458701242c0890d8 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 26 Jun 2021 21:31:50 +0200 Subject: [PATCH] feat(modulo): wire up Wizard accessibility page --- espanso-modulo/src/sys/wizard/mod.rs | 37 ++++++++++-------------- espanso-modulo/src/sys/wizard/wizard.cpp | 36 ++++++++++++++++++++++- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/espanso-modulo/src/sys/wizard/mod.rs b/espanso-modulo/src/sys/wizard/mod.rs index 46f48ab..542512e 100644 --- a/espanso-modulo/src/sys/wizard/mod.rs +++ b/espanso-modulo/src/sys/wizard/mod.rs @@ -92,17 +92,12 @@ pub fn show(options: WizardOptions) { .lock() .expect("unable to acquire lock in enable_accessibility method"); let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers"); - // TODO: - // if let Some(handler_ref) = handlers_ref.add_to_path.as_ref() { - // if (*handler_ref)() { - // 1 - // } else { - // 0 - // } - // } else { - // -1 - // } - 0 + if let Some(handler_ref) = handlers_ref.enable_accessibility.as_ref() { + (*handler_ref)(); + 1 + } else { + -1 + } } extern "C" fn is_accessibility_enabled() -> c_int { @@ -110,17 +105,15 @@ pub fn show(options: WizardOptions) { .lock() .expect("unable to acquire lock in is_accessibility_enabled method"); let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers"); - // TODO: - // if let Some(handler_ref) = handlers_ref.add_to_path.as_ref() { - // if (*handler_ref)() { - // 1 - // } else { - // 0 - // } - // } else { - // -1 - // } - 0 + if let Some(handler_ref) = handlers_ref.is_accessibility_enabled.as_ref() { + if (*handler_ref)() { + 1 + } else { + 0 + } + } else { + -1 + } } extern "C" fn on_completed() { diff --git a/espanso-modulo/src/sys/wizard/wizard.cpp b/espanso-modulo/src/sys/wizard/wizard.cpp index 8b69d34..7a869ee 100644 --- a/espanso-modulo/src/sys/wizard/wizard.cpp +++ b/espanso-modulo/src/sys/wizard/wizard.cpp @@ -99,6 +99,7 @@ protected: void migrate_button_clicked(wxCommandEvent &event); void migrate_compatibility_mode_clicked(wxCommandEvent &event); void add_path_continue_clicked( wxCommandEvent& event ); + void accessibility_enable_clicked( wxCommandEvent& event ); void navigate_to_next_page_or_close(); void change_default_button(int target_page); @@ -110,7 +111,7 @@ public: DerivedFrame::DerivedFrame(wxWindow *parent) : WizardFrame(parent) { - // TODO: load images for accessibility page if on macOS + // Welcome images if (metadata->welcome_image_path) { @@ -120,6 +121,19 @@ DerivedFrame::DerivedFrame(wxWindow *parent) this->welcome_version_text->SetLabel(wxString::Format("( version %s )", metadata->version)); + // Accessiblity images + + if (metadata->accessibility_image_1_path) + { + wxBitmap accessiblityImage1 = wxBitmap(metadata->accessibility_image_1_path, wxBITMAP_TYPE_PNG); + this->accessibility_image1->SetBitmap(accessiblityImage1); + } + if (metadata->accessibility_image_2_path) + { + wxBitmap accessiblityImage2 = wxBitmap(metadata->accessibility_image_2_path, wxBITMAP_TYPE_PNG); + this->accessibility_image2->SetBitmap(accessiblityImage2); + } + // Load the first page int page = find_next_page(-1); if (page >= 0) @@ -143,6 +157,10 @@ void DerivedFrame::navigate_to_next_page_or_close() } else { + if (metadata->on_completed) { + metadata->on_completed(); + } + Close(true); } } @@ -216,6 +234,14 @@ void DerivedFrame::add_path_continue_clicked( wxCommandEvent& event ) { } } +void DerivedFrame::accessibility_enable_clicked( wxCommandEvent& event ) +{ + if (metadata->enable_accessibility) + { + metadata->enable_accessibility(); + } +} + void DerivedFrame::check_timer_tick(wxTimerEvent &event) { if (this->m_simplebook->GetSelection() == LEGACY_VERSION_PAGE_INDEX) @@ -227,6 +253,14 @@ void DerivedFrame::check_timer_tick(wxTimerEvent &event) this->navigate_to_next_page_or_close(); } } + } else if (this->m_simplebook->GetSelection() == ACCESSIBILITY_PAGE_INDEX) { + if (metadata->is_accessibility_enabled) + { + if (metadata->is_accessibility_enabled() == 1) + { + this->navigate_to_next_page_or_close(); + } + } } }