JFLib

plat/autostart.rs#

Source: lib/plat/autostart.rs

autostart -- start the app when the user logs in

  autostart_set(on, args) -> Result<(), AutostartError>   on: start this program with args
                                    at login (an existing entry is replaced); off: remove it
  autostart_get() -> bool           an entry of this app is there and switched on
  autostart_entry() -> Option<String>   the command the entry starts (Windows: the Run
                                    value, Linux: the Exec value, Flatpak: what was asked
                                    last), None without one

Changing it needs `autostart` in the app's manifest (policy.rs; else Denied and "PERMDENY
autostart"); reading needs nothing.  The entry is named after the app (vfs::app_id; Linux:
the .desktop id, linux_desk.rs) and starts the running executable -- call autostart_set
again after the program moved (autostart_entry tells where the entry points).

Windows (win_autostart.rs): the value <app id> = "exe" args of
HKCU\Software\Microsoft\Windows\CurrentVersion\Run (arguments quoted with the Microsoft
rules).  The Task Manager's switch (Explorer\StartupApproved\Run, an odd first byte = off)
counts for autostart_get; autostart_set(true) clears it (the user asked in the app), false
removes both; in an MSIX package (HKCU virtualized) the package's StartupTask instead,
switched through WinRT (TaskId "Autostart"; it takes no arguments, a task the user switched
off in Settings stays off: Dismissed).  Linux (linux_autostart.rs): $XDG_CONFIG_HOME/autostart/<desktop id>.desktop
(XDG autostart; Hidden=true or X-GNOME-Autostart-enabled=false count as off), Exec quoted
as the Desktop Entry spec wants, $APPIMAGE instead of the executable when set.  In Flatpak
the Background portal (RequestBackground with autostart and the command line): the desktop
may ask the user, and the call waits for the answer (at most AUTOSTART_WAIT_MS); the sandbox
cannot see the host's autostart folder, so the answer is remembered in
config://autostart.  jfgui_AUTOSTART=portal / file picks the way (tests).  macOS
(apple_autostart.rs): a LaunchAgent ~/Library/LaunchAgents/<app id>.plist (RunAtLoad, the
executable and the arguments).  Web, Android and iOS: Unavailable.
/// how long autostart_set waits for the Background portal's answer (the user may be asked)
AUTOSTART_WAIT_MS: i32 = 120_000
  • enum AutostartError why autostart_set failed

    • Unavailable -- not possible here (web, Android, no session bus for the portal, an MSIX package without a StartupTask)
    • Denied -- the app's permissions lack autostart
    • Dismissed -- the user (or the desktop) refused it, or did not answer in time (the portal)
    • Invalid -- an argument with NUL, or a command line beyond the system's limit
    • Failed(String) -- the system refused or failed: what it said
  • fn autostart_set(on: bool, args: &[&str]) -> Result<(), AutostartError> start this program with args when the user logs in (on), or not any more (off)

  • fn autostart_get() -> bool whether the app starts at login (an entry of it is there and switched on)

  • fn autostart_entry() -> Option<String> the command the app's entry starts, None without one

Source: docs/API.md in the JFLib repository.