Crate auto_launch
source[−]Expand description
Auto launch any application or executable at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux.
Usage
The parameters of AutoLaunch::new are different on each os.
See the function definition of the demo below for details.
Linux
On Linux, it supports hidden parameter which means that hidden the app on launch.
use auto_launch::AutoLaunch;
fn main() {
let app_name = "the-app";
let app_path = "/path/to/the-app";
let auto = AutoLaunch::new(app_name, app_path, false);
// enable the auto launch
assets!(auto.enable().is_ok());
assets!(auto.is_enabled().unwrap());
// disable the auto launch
assets!(auto.disable().is_ok());
assets!(!auto.is_enabled().unwrap());
}Macos
Macos supports two way to achieve auto launch (via AppleScript or Launch Agent).
When the use_launch_agent is true, it will achieve by Launch Agent, otherwise by AppleScript.
On Macos, it supports hidden parameter which means that hidden the app on launch.
Note:
- The
app_pathshould be a absolute path and exists. Otherwise, it will cause an error whenenable. - When in the AppleScript way, the
app_nameshould be same as the basename ofapp_path, or it will be corrected automately.
use auto_launch::AutoLaunch;
#[cfg(target_os = "macos")]
fn main() {
let app_name = "the-app";
let app_path = "/path/to/the-app.app";
let auto = AutoLaunch::new(app_name, app_path, false, false);
// enable the auto launch
assets!(auto.enable().is_ok());
assets!(auto.is_enabled().unwrap());
// disable the auto launch
assets!(auto.disable().is_ok());
assets!(!auto.is_enabled().unwrap());
}Windows
On Windows, it will add a registry entry under \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.
use auto_launch::AutoLaunch;
#[cfg(target_os = "macos")]
fn main() {
let app_name = "the-app";
let app_path = "C:\\path\\to\\the-app.exe";
let auto = AutoLaunch::new(app_name, app_path);
// enable the auto launch
assets!(auto.enable().is_ok());
assets!(auto.is_enabled().unwrap());
// disable the auto launch
assets!(auto.disable().is_ok());
assets!(!auto.is_enabled().unwrap());
}