Starting at login
Os::autostart has the system start the application when the person logs in, and reads whether it does.
Turning it on and off
impl Autostart<'_> {
pub async fn enable(&self) -> Result<(), Error>;
pub async fn disable(&self) -> Result<(), Error>;
pub async fn is_enabled(&self) -> Result<bool, Error>;
}Os::autostart returns the system's entry that starts the application when the person logs in. enable writes it, disable removes it, and is_enabled reads whether it is there, so a settings page shows a switch in the state the system holds. A chat application with a tray starts this way and waits in the tray:
use hypersig_desktop::Os;
/// Turns the start at login on or off from a switch on the settings page.
async fn set_start_at_login(os: &Os, on: bool) -> Result<(), hypersig_desktop::Error> {
if on {
os.autostart().enable().await
} else {
os.autostart().disable().await
}
}Each fails with ErrorKind::Autostart when the entry cannot be read or written. In a test, the FakeOs keeps whether it is on.
On each system
- The entry is named by the identifier
App::newtakes, and starts the program running now: on Linux the AppImage the person installed, whichAPPIMAGEnames, and elsewhere the running binary. A run fromcargo runwrites an entry for the binary undertarget. - macOS keeps a launch agent in
~/Library/LaunchAgents, Windows a value under theRunkey of the registry, and Linux a desktop entry in~/.config/autostart, which theauto-launchcrate writes. On macOS, a run sawenablewrite the launch agent,is_enabledread it back, anddisableremove it.