feat(modulo): wire up Add to PATH wizard page
This commit is contained in:
parent
c5ef5337bf
commit
49550f0e60
espanso-modulo/src
|
@ -117,4 +117,5 @@ typedef struct WizardMetadata {
|
||||||
int (*add_to_path)();
|
int (*add_to_path)();
|
||||||
int (*enable_accessibility)();
|
int (*enable_accessibility)();
|
||||||
int (*is_accessibility_enabled)();
|
int (*is_accessibility_enabled)();
|
||||||
|
void (*on_completed)();
|
||||||
} WizardMetadata;
|
} WizardMetadata;
|
|
@ -134,6 +134,7 @@ pub struct WizardMetadata {
|
||||||
pub add_to_path: extern fn() -> c_int,
|
pub add_to_path: extern fn() -> c_int,
|
||||||
pub enable_accessibility: extern fn() -> c_int,
|
pub enable_accessibility: extern fn() -> c_int,
|
||||||
pub is_accessibility_enabled: extern fn() -> c_int,
|
pub is_accessibility_enabled: extern fn() -> c_int,
|
||||||
|
pub on_completed: extern fn(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Native bindings
|
// Native bindings
|
||||||
|
|
|
@ -76,17 +76,15 @@ pub fn show(options: WizardOptions) {
|
||||||
.lock()
|
.lock()
|
||||||
.expect("unable to acquire lock in add_to_path method");
|
.expect("unable to acquire lock in add_to_path method");
|
||||||
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
|
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 let Some(handler_ref) = handlers_ref.add_to_path.as_ref() {
|
if (*handler_ref)() {
|
||||||
// if (*handler_ref)() {
|
1
|
||||||
// 1
|
} else {
|
||||||
// } else {
|
0
|
||||||
// 0
|
}
|
||||||
// }
|
} else {
|
||||||
// } else {
|
-1
|
||||||
// -1
|
}
|
||||||
// }
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn enable_accessibility() -> c_int {
|
extern "C" fn enable_accessibility() -> c_int {
|
||||||
|
@ -125,6 +123,16 @@ pub fn show(options: WizardOptions) {
|
||||||
0
|
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");
|
let mut lock = HANDLERS.lock().expect("unable to acquire handlers lock");
|
||||||
*lock = Some(options.handlers)
|
*lock = Some(options.handlers)
|
||||||
|
@ -174,6 +182,7 @@ pub fn show(options: WizardOptions) {
|
||||||
add_to_path,
|
add_to_path,
|
||||||
enable_accessibility,
|
enable_accessibility,
|
||||||
is_accessibility_enabled,
|
is_accessibility_enabled,
|
||||||
|
on_completed,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -98,6 +98,7 @@ protected:
|
||||||
void welcome_start_clicked(wxCommandEvent &event);
|
void welcome_start_clicked(wxCommandEvent &event);
|
||||||
void migrate_button_clicked(wxCommandEvent &event);
|
void migrate_button_clicked(wxCommandEvent &event);
|
||||||
void migrate_compatibility_mode_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 navigate_to_next_page_or_close();
|
||||||
void change_default_button(int target_page);
|
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)
|
void DerivedFrame::check_timer_tick(wxTimerEvent &event)
|
||||||
{
|
{
|
||||||
if (this->m_simplebook->GetSelection() == LEGACY_VERSION_PAGE_INDEX)
|
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 add_to_path: Option<Box<dyn Fn() -> bool + Send>>,
|
||||||
pub enable_accessibility: Option<Box<dyn Fn() + Send>>,
|
pub enable_accessibility: Option<Box<dyn Fn() + Send>>,
|
||||||
pub is_accessibility_enabled: Option<Box<dyn Fn() -> bool + Send>>,
|
pub is_accessibility_enabled: Option<Box<dyn Fn() -> bool + Send>>,
|
||||||
|
pub on_completed: Option<Box<dyn Fn() + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user