Auto Launch

Crates.io API reference License

Auto launch any application or executable at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux.

How does it work? See Teamwork/node-auto-launch for details.

If you find any bugs, welcome to PR or issue.

Usage

The parameters of AutoLaunch::new are different on each platform. See the function definition or the demo below for details.

Or you can construct the AutoLaunch by using AutoLaunchBuilder.

Linux

On Linux, it supports hidden parameter which means that hidden the app on launch.

```rust use auto_launch::AutoLaunch;

fn main() { let appname = "the-app"; let apppath = "/path/to/the-app"; let auto = AutoLaunch::new(appname, apppath, false);

// enable the auto launch
auto.enable().is_ok();
auto.is_enabled().unwrap();

// disable the auto launch
auto.disable().is_ok();
auto.is_enabled().unwrap();

} ```

Macos

Macos supports two ways 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:

```rust use auto_launch::AutoLaunch;

fn main() { let appname = "the-app"; let apppath = "/path/to/the-app.app"; let auto = AutoLaunch::new(appname, apppath, false, false);

// enable the auto launch
auto.enable().is_ok();
auto.is_enabled().unwrap();

// disable the auto launch
auto.disable().is_ok();
auto.is_enabled().unwrap();

} ```

Windows

On Windows, it will add a registry entry under \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

```rust use auto_launch::AutoLaunch;

fn main() { let appname = "the-app"; let apppath = "C:\path\to\the-app.exe"; let auto = AutoLaunch::new(appname, apppath);

// enable the auto launch
auto.enable().is_ok();
auto.is_enabled().unwrap();

// disable the auto launch
auto.disable().is_ok();
auto.is_enabled().unwrap();

} ```

Builder

AutoLaunch Builder helps to eliminate the constructor difference on various platforms.

```rust use auto_launch::*;

fn main() -> std::io::Result<()> { let auto = AutoLaunchBuilder::new() .setappname("the-app") .setapppath("/path/to/the-app") .setuselaunchagent(true) .sethidden(true) .build();

auto.enable()?;
auto.is_enabled()?;

auto.disable()?;
auto.is_enabled()?;

Ok(())

} ```

License

MIT License. See the License file for details.

Acknowledgement

The project is based on node-auto-launch.