Skip to main content

Module single_instance

Module single_instance 

Source
Expand description

One tray UI per config directory.

ui holds <config dir>/ui.lock exclusively for its whole life; the OS releases it when the process exits, however it exits. A second ui for the same config finds the lock taken, leaves a raise request (ui.raise) for the running one and exits, so a config never gets two tray icons. The running UI watches for the request and shows its window.

Structs§

UiLock
The held UI lock; dropping it releases the lock.

Enums§

Instance
The outcome of acquire.

Constants§

LOCK_FILE_NAME
The UI lock’s file name, next to config.toml.
RAISE_FILE_NAME
A second launch’s request to show the running UI’s window.
RAISE_POLL
How often the running UI looks for a raise request.
RESTART_ATTEMPTS
How long a UI restarting itself for the display waits for the lock its predecessor still holds: attempts × pause = 5 s.
RESTART_PAUSE

Functions§

acquire
Take the UI lock for the config at config_path, trying attempts times pause apart. A stale raise request is dropped once the lock is ours, so it cannot pop the window open later.
hand_over
Ask the running tray UI to show its window, and say so.
lock_path_for
The UI lock for the config at config_path.
raise_path_for
The raise request for the config at config_path.
take_raise_request
Consume a pending raise request; answers whether there was one.
watch
Until stop, consume raise requests and call raise for each, when it can (raise answers whether the window could be reached).