feat(core): wire up Add to PATH wizard page
This commit is contained in:
parent
49550f0e60
commit
1edb533c32
|
@ -71,16 +71,25 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let is_add_path_page_enabled =
|
||||||
|
if cfg!(not(target_os = "linux")) && !preferences.has_completed_wizard() {
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
!crate::path::is_espanso_in_path()
|
||||||
|
} else {
|
||||||
// TODO: enable "Add to PATH" page only when NOT in portable mode
|
// TODO: enable "Add to PATH" page only when NOT in portable mode
|
||||||
// TODO: if the user clicks on "Continue" after unchecking the "ADD to PATH"
|
!crate::path::is_espanso_in_path()
|
||||||
// checkbox, we should remember (with the kvs) the choice and avoid asking again.
|
}
|
||||||
let is_add_path_page_enabled = if cfg!(target_os = "macos") {
|
|
||||||
// TODO: add actual check
|
|
||||||
// TODO: consider also Windows case
|
|
||||||
true
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
// TODO: consider also Windows case?
|
||||||
|
let add_to_path_handler = Box::new(move || match util::add_espanso_to_path() {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("Add to path returned error: {}", error);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let is_accessibility_page_enabled = if cfg!(target_os = "macos") {
|
let is_accessibility_page_enabled = if cfg!(target_os = "macos") {
|
||||||
// TODO: add actual check
|
// TODO: add actual check
|
||||||
|
@ -89,6 +98,11 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let preferences_clone = preferences.clone();
|
||||||
|
let on_completed_handler = Box::new(move || {
|
||||||
|
preferences_clone.set_completed_wizard(true);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: show a "espanso is now running page at the end" (it should be triggered everytime
|
// TODO: show a "espanso is now running page at the end" (it should be triggered everytime
|
||||||
// espanso is started, unless the user unchecks "show this message at startup")
|
// espanso is started, unless the user unchecks "show this message at startup")
|
||||||
// This page could also be used when the user starts espanso, but an instance is already running.
|
// This page could also be used when the user starts espanso, but an instance is already running.
|
||||||
|
@ -120,14 +134,13 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
|
||||||
handlers: WizardHandlers {
|
handlers: WizardHandlers {
|
||||||
is_legacy_version_running: Some(is_legacy_version_running_handler),
|
is_legacy_version_running: Some(is_legacy_version_running_handler),
|
||||||
backup_and_migrate: Some(backup_and_migrate_handler),
|
backup_and_migrate: Some(backup_and_migrate_handler),
|
||||||
add_to_path: None, // TODO
|
add_to_path: Some(add_to_path_handler),
|
||||||
enable_accessibility: None, // TODO
|
enable_accessibility: None, // TODO
|
||||||
is_accessibility_enabled: None, // TODO
|
is_accessibility_enabled: None, // TODO
|
||||||
|
on_completed: Some(on_completed_handler),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: check the wizard return status?
|
|
||||||
preferences.set_completed_wizard(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: initialize config directory if not present
|
// TODO: initialize config directory if not present
|
||||||
|
|
|
@ -76,3 +76,24 @@ pub enum MigrationError {
|
||||||
#[error("unexpected error")]
|
#[error("unexpected error")]
|
||||||
UnexpectedError,
|
UnexpectedError,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_espanso_to_path() -> Result<()> {
|
||||||
|
let espanso_exe_path = std::env::current_exe()?;
|
||||||
|
let mut command = Command::new(&espanso_exe_path.to_string_lossy().to_string());
|
||||||
|
command.args(&["env-path", "--prompt", "register"]);
|
||||||
|
|
||||||
|
let mut child = command.spawn()?;
|
||||||
|
let result = child.wait()?;
|
||||||
|
|
||||||
|
if result.success() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(AddToPathError::NonZeroExitCode.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum AddToPathError {
|
||||||
|
#[error("unexpected error, 'espanso env-path register' returned a non-zero exit code.")]
|
||||||
|
NonZeroExitCode,
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ use anyhow::Result;
|
||||||
|
|
||||||
mod default;
|
mod default;
|
||||||
|
|
||||||
pub trait Preferences: Send + Sync {
|
pub trait Preferences: Send + Sync + Clone {
|
||||||
fn has_completed_wizard(&self) -> bool;
|
fn has_completed_wizard(&self) -> bool;
|
||||||
fn set_completed_wizard(&self, value: bool);
|
fn set_completed_wizard(&self, value: bool);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user