From 7e09fe769b9ee7f6513bec6756e71e3361d34556 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 27 Jun 2021 20:18:49 +0200 Subject: [PATCH] feat(modulo): return result from Wizard --- espanso-modulo/src/sys/interop/mod.rs | 2 +- espanso-modulo/src/sys/wizard/mod.rs | 10 ++++++---- espanso-modulo/src/sys/wizard/wizard.cpp | 6 +++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/espanso-modulo/src/sys/interop/mod.rs b/espanso-modulo/src/sys/interop/mod.rs index d583e6e..07f4e08 100644 --- a/espanso-modulo/src/sys/interop/mod.rs +++ b/espanso-modulo/src/sys/interop/mod.rs @@ -170,7 +170,7 @@ extern "C" { pub(crate) fn update_items(app: *const c_void, items: *const SearchItem, itemCount: c_int); // WIZARD - pub(crate) fn interop_show_wizard(metadata: *const WizardMetadata); + pub(crate) fn interop_show_wizard(metadata: *const WizardMetadata) -> c_int; // WELCOME pub(crate) fn interop_show_welcome(metadata: *const WelcomeMetadata); diff --git a/espanso-modulo/src/sys/wizard/mod.rs b/espanso-modulo/src/sys/wizard/mod.rs index 9178106..ca7d47f 100644 --- a/espanso-modulo/src/sys/wizard/mod.rs +++ b/espanso-modulo/src/sys/wizard/mod.rs @@ -27,7 +27,7 @@ lazy_static! { static ref HANDLERS: Mutex> = Mutex::new(None); } -pub fn show(options: WizardOptions) { +pub fn show(options: WizardOptions) -> bool { let c_version = CString::new(options.version).expect("unable to convert version to CString"); let (_c_window_icon_path, c_window_icon_path_ptr) = @@ -179,7 +179,9 @@ pub fn show(options: WizardOptions) { on_completed, }; - 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 diff --git a/espanso-modulo/src/sys/wizard/wizard.cpp b/espanso-modulo/src/sys/wizard/wizard.cpp index 7a869ee..1174624 100644 --- a/espanso-modulo/src/sys/wizard/wizard.cpp +++ b/espanso-modulo/src/sys/wizard/wizard.cpp @@ -36,6 +36,7 @@ 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 WizardMetadata *metadata = nullptr; +int completed_successfully = 0; // App Code @@ -159,6 +160,7 @@ void DerivedFrame::navigate_to_next_page_or_close() { if (metadata->on_completed) { metadata->on_completed(); + completed_successfully = 1; } Close(true); @@ -319,7 +321,7 @@ bool WizardApp::OnInit() return true; } -extern "C" void interop_show_wizard(WizardMetadata *_metadata) +extern "C" int interop_show_wizard(WizardMetadata *_metadata) { // Setup high DPI support on Windows #ifdef __WXMSW__ @@ -331,4 +333,6 @@ extern "C" void interop_show_wizard(WizardMetadata *_metadata) wxApp::SetInstance(new WizardApp()); int argc = 0; wxEntry(argc, (char **)nullptr); + + return completed_successfully; } \ No newline at end of file