mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
Co-authored-by: FabianLars <github@fabianlars.de> Co-authored-by: Amr Bashir <github@amrbashir.me>
This commit is contained in:
@@ -29,17 +29,70 @@ pub(crate) type SingleInstanceCallback<R> =
|
||||
dyn FnMut(&AppHandle<R>, Vec<String>, String) + Send + Sync + 'static;
|
||||
|
||||
pub fn init<R: Runtime, F: FnMut(&AppHandle<R>, Vec<String>, String) + Send + Sync + 'static>(
|
||||
mut f: F,
|
||||
f: F,
|
||||
) -> TauriPlugin<R> {
|
||||
platform_impl::init(Box::new(move |app, args, cwd| {
|
||||
#[cfg(feature = "deep-link")]
|
||||
if let Some(deep_link) = app.try_state::<tauri_plugin_deep_link::DeepLink<R>>() {
|
||||
deep_link.handle_cli_arguments(args.iter());
|
||||
}
|
||||
f(app, args, cwd)
|
||||
}))
|
||||
Builder::new().callback(f).build()
|
||||
}
|
||||
|
||||
pub fn destroy<R: Runtime, M: Manager<R>>(manager: &M) {
|
||||
platform_impl::destroy(manager)
|
||||
}
|
||||
|
||||
pub struct Builder<R: Runtime> {
|
||||
callback: Box<SingleInstanceCallback<R>>,
|
||||
dbus_id: Option<String>,
|
||||
}
|
||||
|
||||
impl<R: Runtime> Default for Builder<R> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
callback: Box::new(move |_app, _args, _| {
|
||||
#[cfg(feature = "deep-link")]
|
||||
if let Some(deep_link) = _app.try_state::<tauri_plugin_deep_link::DeepLink<R>>() {
|
||||
deep_link.handle_cli_arguments(_args.iter());
|
||||
}
|
||||
}),
|
||||
dbus_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> Builder<R> {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Function to call when a secondary instance was opened by the user and killed by the plugin.
|
||||
/// If the `deep-link` feature is enabled, the plugin triggers the deep-link plugin before executing the callback.
|
||||
pub fn callback<F: FnMut(&AppHandle<R>, Vec<String>, String) + Send + Sync + 'static>(
|
||||
mut self,
|
||||
mut f: F,
|
||||
) -> Self {
|
||||
self.callback = Box::new(move |app, args, cwd| {
|
||||
#[cfg(feature = "deep-link")]
|
||||
if let Some(deep_link) = app.try_state::<tauri_plugin_deep_link::DeepLink<R>>() {
|
||||
deep_link.handle_cli_arguments(args.iter());
|
||||
}
|
||||
f(app, args, cwd)
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a custom D-Bus ID, used on Linux. The plugin will append a `.SingleInstance` subname.
|
||||
/// For example `com.mycompany.myapp` will result in the plugin registering its D-Bus service on `com.mycompany.myapp.SingleInstance`.
|
||||
/// Usually you want the same base ID across all components in your app.
|
||||
///
|
||||
/// Defaults to the app's bundle identifier set in tauri.conf.json.
|
||||
pub fn dbus_id(mut self, dbus_id: impl Into<String>) -> Self {
|
||||
self.dbus_id = Some(dbus_id.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> TauriPlugin<R> {
|
||||
platform_impl::init(
|
||||
self.callback,
|
||||
#[cfg(target_os = "linux")]
|
||||
self.dbus_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user