Skip to main content

SingleInstance

Struct SingleInstance 

Source
pub struct SingleInstance;
Expand description

Standalone single-instance arbitration.

Implementations§

Source§

impl SingleInstance

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn claim_in_with( suite: &Suite, id: &str, options: ClaimOptions, message: InstanceMessage, on_message: impl Fn(InstanceMessage) + Send + Sync + 'static, ) -> ClaimOutcome

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.