autostart
import "github.com/tangoui/tango/sys/autostart"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package autostart starts the app when the user logs in.
o := autostart.Options{ID: "com.example.notes", Name: "Notes"}
err := autostart.Enable(o)
Per platform:
- macOS: a launch agent, ~/Library/LaunchAgents/<ID>.plist. It takes effect at the next login; System Settings lists it under Login Items ("Allow in the Background").
- Windows: a value named <ID> under HKCU\Software\Microsoft\Windows\CurrentVersion\Run. Task Manager's Startup tab can disable it without removing it; IsEnabled then reports false.
- Linux: an XDG autostart entry, ~/.config/autostart/<ID>.desktop ($XDG_CONFIG_HOME is honoured). A desktop that turned it off (Hidden=true, X-GNOME-Autostart-enabled=false) reads as disabled.
The login command runs the executable with Args and LoginArg, which OpenedAtLogin detects, so the app can start hidden in the tray.
The package needs no running app and does no work on the main thread. Other platforms return ErrUnsupported.
常量
const LoginArg = "--tango-login"LoginArg is added to the command line of an app started at login.
变量
var ErrUnsupported = platform.ErrUnsupportedErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.
函数
func Disable
func Disable(o Options) errorDisable removes the login item. Removing one that does not exist is not an error.
func Enable
func Enable(o Options) errorEnable registers the login item, replacing an existing one with the same ID.
func IsEnabled
func IsEnabled(o Options) (bool, error)IsEnabled reports whether the login item exists and is not turned off.
func OpenedAtLogin
func OpenedAtLogin() boolOpenedAtLogin reports whether this process was started by the login item (its command line has LoginArg).
类型
Options
type Options struct {
// ID names the entry: a reverse-DNS identifier such as
// "com.example.notes". Required; it must not contain path separators.
ID string
// Name is shown by the desktop (Linux entry Name). Defaults to ID.
Name string
// Exec is the program to start; defaults to os.Executable().
Exec string
// Args are extra arguments, before LoginArg.
Args []string
// Dir overrides where the entry lives, for tests and portable
// installs: the LaunchAgents directory (macOS), the autostart
// directory (Linux) or the registry key under HKEY_CURRENT_USER
// (Windows).
Dir string
}Options identifies the login item.