Skip to main content

tauri_plugin_single_window/
config.rs

1#[derive(Clone, Default)]
2pub struct Config {
3    pub duplicate_notice: Option<String>,
4    pub target_window_label: Option<String>,
5    pub focus_existing_window: bool,
6    pub(crate) activation_callback: Option<std::sync::Arc<dyn std::any::Any + Send + Sync>>,
7}
8
9impl Config {
10    pub fn new() -> Self {
11        Self {
12            duplicate_notice: None,
13            target_window_label: None,
14            focus_existing_window: true,
15            activation_callback: None,
16        }
17    }
18
19    pub fn with_duplicate_notice<S: Into<String>>(mut self, duplicate_notice: S) -> Self {
20        self.duplicate_notice = Some(duplicate_notice.into());
21        self
22    }
23
24    pub fn with_target_window<S: Into<String>>(mut self, target_window_label: S) -> Self {
25        self.target_window_label = Some(target_window_label.into());
26        self
27    }
28
29    pub fn without_window_focus(mut self) -> Self {
30        self.focus_existing_window = false;
31        self
32    }
33
34    pub fn on_activate<R, F>(mut self, callback: F) -> Self
35    where
36        R: tauri::Runtime,
37        F: Fn(tauri::AppHandle<R>, crate::ActivationPayload) + Send + Sync + 'static,
38    {
39        let callback: crate::ActivationCallback<R> = std::sync::Arc::new(callback);
40        self.activation_callback = Some(std::sync::Arc::new(callback));
41        self
42    }
43}