pub struct SingleInstance;Expand description
Standalone single-instance arbitration.
Implementations§
Source§impl SingleInstance
impl SingleInstance
Sourcepub fn destroy()
pub fn destroy()
Release every single-instance claim this process holds, so a relaunched process (for an update, say) can become the primary before this one exits. Guards stay valid and own nothing afterwards.
What it releases:
- every claim made through this type (the rightkit-daemon endpoint), and
- every release registered with
SingleInstance::on_destroy, each run exactly once.
It is idempotent: a second call finds nothing left and does nothing. It does not touch any
tauri-plugin-single-instance claim unless a hook for it was registered, because
ClaimOptions::legacy_identifier only probes for a legacy holder; this type never creates
a legacy claim, and the plugin’s mutex and window (Windows), unix-socket listener (macOS) and
D-Bus name (Linux) are owned by the plugin’s own state inside the app. A process that still
registers the plugin must release it too (see SingleInstance::on_destroy), or the
relaunched process is refused as a second instance.
Sourcepub fn on_destroy(hook: impl FnOnce() + Send + 'static)
pub fn on_destroy(hook: impl FnOnce() + Send + 'static)
Register a release that SingleInstance::destroy runs once, before it drops this type’s
own claims. This is how an app that still registers tauri-plugin-single-instance makes one
destroy() call release both claims:
let handle = app.handle().clone();
SingleInstance::on_destroy(move || tauri_plugin_single_instance::destroy(&handle));
// relaunch-for-update:
SingleInstance::destroy(); // plugin claim, then rightkit claim
app.exit(0);Without the hook, call tauri_plugin_single_instance::destroy(&app) and
SingleInstance::destroy() both, in either order, before spawning or exiting.
The plugin’s destroy closes its mutex handle (Windows) or removes its socket file (macOS),
which frees the name for the relaunch. On Windows it also calls DestroyWindow for its hidden
window; Win32 allows that only on the thread that created the window, so from another thread
the window lingers until the process exits. The relaunched process is unaffected, because
arbitration there is the mutex, and a new mutex is created.
Sourcepub fn claim(
id: &str,
on_message: impl Fn(InstanceMessage) + Send + Sync + 'static,
) -> ClaimOutcome
pub fn claim( id: &str, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome
Claim the primary for id (lowercase letters, digits and -). on_message receives each
launch that is forwarded to this primary. The outgoing message is this process’s argv and cwd.
Sourcepub fn claim_with(
id: &str,
message: InstanceMessage,
on_message: impl Fn(InstanceMessage) + Send + Sync + 'static,
) -> ClaimOutcome
pub fn claim_with( id: &str, message: InstanceMessage, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome
Like SingleInstance::claim, but the outgoing message (used when this launch is forwarded)
is message, for example one carrying an action and arguments.
Sourcepub fn claim_with_options(
id: &str,
options: ClaimOptions,
message: InstanceMessage,
on_message: impl Fn(InstanceMessage) + Send + Sync + 'static,
) -> ClaimOutcome
pub fn claim_with_options( id: &str, options: ClaimOptions, message: InstanceMessage, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome
SingleInstance::claim_with with options, such as the legacy identifier to probe.
Sourcepub fn claim_in(
suite: &Suite,
id: &str,
message: InstanceMessage,
on_message: impl Fn(InstanceMessage) + Send + Sync + 'static,
) -> ClaimOutcome
pub fn claim_in( suite: &Suite, id: &str, message: InstanceMessage, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome
Claim inside an explicit suite root. Tests use this; apps normally call SingleInstance::claim.
Sourcepub fn claim_in_with(
suite: &Suite,
id: &str,
options: ClaimOptions,
message: InstanceMessage,
on_message: impl Fn(InstanceMessage) + Send + Sync + 'static,
) -> ClaimOutcome
pub fn claim_in_with( suite: &Suite, id: &str, options: ClaimOptions, message: InstanceMessage, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome
SingleInstance::claim_in with options.