Skip to content

autostart ​

go
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.

常量 ​

go
const LoginArg = "--tango-login"

LoginArg is added to the command line of an app started at login.

变量 ​

go
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.

函数 ​

func Disable ​

go
func Disable(o Options) error

Disable removes the login item. Removing one that does not exist is not an error.

func Enable ​

go
func Enable(o Options) error

Enable registers the login item, replacing an existing one with the same ID.

func IsEnabled ​

go
func IsEnabled(o Options) (bool, error)

IsEnabled reports whether the login item exists and is not turned off.

func OpenedAtLogin ​

go
func OpenedAtLogin() bool

OpenedAtLogin reports whether this process was started by the login item (its command line has LoginArg).

类型 ​

Options ​

go
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.

以 MIT 许可发布