loginitem

package
v0.9.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package loginitem starts the Blitz service (blitzd) at login and controls it: a launchd agent on macOS, a systemd user unit on Linux. On Windows only the tray starts at login (InstallTray), and it starts the service. The CLI (`blitz service …`) and the desktop app both use it, so the app needs no CLI to install, restart or stop the service.

Index

Constants

View Source
const (
	// Label is the launchd agent's label (macOS).
	Label = "dev.blitz.service"
	// Unit is the systemd user unit (Linux).
	Unit = "blitz.service"
)
View Source
const TrayLabel = "dev.blitz.tray"

TrayLabel is the tray's launchd agent (macOS); on Linux the tray starts from an XDG autostart entry, as graphical programs do, and on Windows from a value in the registry's Run key.

Variables

View Source
var ErrNotInstalled = errors.New("the Blitz service isn't installed to start at login")

ErrNotInstalled means the login item isn't installed, and starting or restarting needs it.

View Source
var ErrUnsupported = fmt.Errorf("starting the service at login isn't supported on %s: run blitzd yourself", goruntime.GOOS)

ErrUnsupported means login items aren't available: they exist only on macOS and Linux.

View Source
var RunSystem = func(name string, args ...string) error {
	out, err := exec.Command(name, args...).CombinedOutput()
	if err != nil {
		return fmt.Errorf("%s %s: %w: %s", name, strings.Join(args, " "), err, strings.TrimSpace(string(out)))
	}
	return nil
}

RunSystem runs a system command (launchctl, systemctl); tests replace it.

Functions

func Beside

func Beside() string

Beside is the directory of the running program (symlinks resolved), for FindService.

func FindService

func FindService(dirs ...string) (string, error)

FindService finds blitzd: in dirs (beside the program asking, as released and bundled), else on PATH. The result has symlinks resolved, so a login item keeps working when the link moves.

func Install

func Install(blitzd string) error

Install writes the login item for blitzd (an absolute path) and starts it now, replacing a previous item and stopping the service it ran; the same item again only starts the service if it isn't running.

func InstallTray

func InstallTray(bin string) error

InstallTray makes bin (blitz-tray, an absolute path) start at login. On macOS launchd starts it now too; on Linux and Windows the caller starts it.

func Installed

func Installed() bool

Installed reports whether the login item exists.

func LogFile

func LogFile() string

LogFile is where the service's output goes on macOS (systemd keeps it in the journal on Linux).

func Path

func Path() (string, error)

Path is where the login item is written.

func RepairService added in v0.7.1

func RepairService(blitzd string) (bool, error)

RepairService rewrites the service's login item when the program it names is gone, to run blitzd instead (and starts it), and reports whether it did.

func RepairTray added in v0.7.1

func RepairTray(bin string) (bool, error)

RepairTray rewrites the tray's start-at-login entry when the program it names is gone, to run bin instead, and reports whether it did. The caller starts the tray (on macOS launchd has).

func Restart

func Restart() error

Restart stops the service the login item runs, if it runs, and starts it again.

func RunfilesRoots added in v0.3.1

func RunfilesRoots() []string

RunfilesRoots are where Bazel puts the running program's runfiles, when Bazel runs it (bazel run, bazel test).

func ServiceDirs added in v0.3.1

func ServiceDirs() []string

ServiceDirs are where a program finds the blitzd that goes with it: beside it (as released and bundled), then in its Bazel runfiles.

func ServiceProgram added in v0.7.1

func ServiceProgram() string

ServiceProgram is the program the service's login item runs ("" when there's none).

func SnapCurrent added in v0.9.8

func SnapCurrent(path string) string

SnapCurrent is path with a snap's revision (/snap/<name>/<revision>/…) made current, the link snapd moves to each new revision, so a login item or a link naming it lasts through the snap's updates. Any other path, or one not there under current, is returned as it is.

func Start

func Start() error

Start starts the service the login item runs (after Stop, say).

func Stop

func Stop() error

Stop stops the service the login item runs, until the next login (or Start, or Install).

func TrayInstalled

func TrayInstalled() bool

TrayInstalled reports whether the tray starts at login.

func TrayPath

func TrayPath() (string, error)

TrayPath is where the tray's start-at-login entry is written.

func TrayProgram added in v0.7.1

func TrayProgram() string

TrayProgram is the program the tray's start-at-login entry runs ("" when there's no entry, or it can't be read).

func Uninstall

func Uninstall() error

Uninstall stops the service the login item runs and removes the item.

func UninstallTray

func UninstallTray() error

UninstallTray stops the tray starting at login (and on macOS, stops it).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL