feat(modulo): wire up Add to PATH wizard page
This commit is contained in:
parent
c5ef5337bf
commit
49550f0e60
|
@ -117,4 +117,5 @@ typedef struct WizardMetadata {
|
|||
int (*add_to_path)();
|
||||
int (*enable_accessibility)();
|
||||
int (*is_accessibility_enabled)();
|
||||
void (*on_completed)();
|
||||
} WizardMetadata;
|
|
@ -134,6 +134,7 @@ pub struct WizardMetadata {
|
|||
pub add_to_path: extern fn() -> c_int,
|
||||
pub enable_accessibility: extern fn() -> c_int,
|
||||
pub is_accessibility_enabled: extern fn() -> c_int,
|
||||
pub on_completed: extern fn(),
|
||||
}
|
||||
|
||||
// Native bindings
|
||||
|
|
|
@ -76,17 +76,15 @@ pub fn show(options: WizardOptions) {
|
|||
.lock()
|
||||
.expect("unable to acquire lock in add_to_path 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.add_to_path.as_ref() {
|
||||
if (*handler_ref)() {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn enable_accessibility() -> c_int {
|
||||
|
@ -125,6 +123,16 @@ pub fn show(options: WizardOptions) {
|
|||
0
|
||||
}
|
||||
|
||||
extern "C" fn on_completed() {
|
||||
let lock = HANDLERS
|
||||
.lock()
|
||||
.expect("unable to acquire lock in on_completed method");
|
||||
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
|
||||
if let Some(handler_ref) = handlers_ref.on_completed.as_ref() {
|
||||
(*handler_ref)()
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let mut lock = HANDLERS.lock().expect("unable to acquire handlers lock");
|
||||
*lock = Some(options.handlers)
|
||||
|
@ -174,6 +182,7 @@ pub fn show(options: WizardOptions) {
|
|||
add_to_path,
|
||||
enable_accessibility,
|
||||
is_accessibility_enabled,
|
||||
on_completed,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -98,6 +98,7 @@ protected:
|
|||
void welcome_start_clicked(wxCommandEvent &event);
|
||||
void migrate_button_clicked(wxCommandEvent &event);
|
||||
void migrate_compatibility_mode_clicked(wxCommandEvent &event);
|
||||
void add_path_continue_clicked( wxCommandEvent& event );
|
||||
|
||||
void navigate_to_next_page_or_close();
|
||||
void change_default_button(int target_page);
|
||||
|
@ -180,6 +181,41 @@ void DerivedFrame::migrate_button_clicked(wxCommandEvent &event)
|
|||
}
|
||||
}
|
||||
|
||||
void DerivedFrame::add_path_continue_clicked( wxCommandEvent& event ) {
|
||||
if (!add_path_checkbox->IsChecked()) {
|
||||
this->navigate_to_next_page_or_close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (metadata->add_to_path)
|
||||
{
|
||||
while (true) {
|
||||
int result = metadata->add_to_path();
|
||||
if (result == 1)
|
||||
{
|
||||
this->navigate_to_next_page_or_close();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageDialog* dialog = new wxMessageDialog(this,
|
||||
"An error occurred while registering the 'espanso' command to the PATH, please check the logs for more information.\nDo you want to retry? You can always add espanso to the PATH 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::check_timer_tick(wxTimerEvent &event)
|
||||
{
|
||||
if (this->m_simplebook->GetSelection() == LEGACY_VERSION_PAGE_INDEX)
|
||||
|
|
|
@ -43,6 +43,7 @@ pub struct WizardHandlers {
|
|||
pub add_to_path: Option<Box<dyn Fn() -> bool + Send>>,
|
||||
pub enable_accessibility: Option<Box<dyn Fn() + Send>>,
|
||||
pub is_accessibility_enabled: Option<Box<dyn Fn() -> bool + Send>>,
|
||||
pub on_completed: Option<Box<dyn Fn() + Send>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in New Issue
Block a user