Single Instance
Ensure that a single instance of your tauri app is running at a time using the Single Instance Plugin.
Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | ||
linux | ||
macos | ||
android | | |
ios | |
Setup
Install the Single Instance plugin to get started.
Use your project’s package manager to add the dependency:
-
Run the following command in the
src-tauri
folder to add the plugin to the project’s dependencies inCargo.toml
: -
Modify
lib.rs
to initialize the plugin:
Usage
The plugin is already installed and initialized, and it should be functioning correctly right away. Nevertheless, we can also enhance its functionality with the init()
method.
The plugin init()
method takes a closure that is invoked when a new app instance was started, but closed by the plugin.
The closure has three arguments:
app
: The AppHandle of the application.args
: The list of arguments, that was passed by the user to initiate this new instance.cwd
: The Current Working Directory denotes the directory from which the new application instance was launched.
So, the closure should look like below
Focusing on New Instance
By default, when you initiate a new instance while the application is already running, no action is taken. To focus the window of the running instance when user tries to open a new instance, alter the callback closure as follows:
© 2024 Tauri Contributors. CC-BY / MIT