diff --git a/.changes/config-incognito.md b/.changes/config-incognito.md new file mode 100644 index 000000000..1ac657deb --- /dev/null +++ b/.changes/config-incognito.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch:feat' +--- + +Add `incognito` option to the window configuration object. diff --git a/.changes/core-incognito.md b/.changes/core-incognito.md new file mode 100644 index 000000000..ebfdeb531 --- /dev/null +++ b/.changes/core-incognito.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch:feat' +--- + +Add `WindowBuilder::incognito` diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index bce0e3a3d..cf556e512 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -184,10 +184,10 @@ pub fn context_codegen(data: ContextData) -> Result String>( pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream { let function = parse_macro_input!(item as ItemFn); - let function_name = function.sig.ident.clone(); + let function_name = &function.sig.ident; let mut error = None; let domain = get_env_var("TAURI_ANDROID_PACKAGE_PREFIX", |r| r, &mut error, &function); diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index a1c3b4bca..694d7ebe4 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -3133,6 +3133,10 @@ fn create_webview( webview_builder.webview.clipboard = true; } + if webview_attributes.incognito { + webview_builder.webview.incognito = true; + } + #[cfg(any(debug_assertions, feature = "devtools"))] { webview_builder = webview_builder.with_devtools(true); diff --git a/core/tauri-runtime/src/webview.rs b/core/tauri-runtime/src/webview.rs index 5103b28e9..888c127f5 100644 --- a/core/tauri-runtime/src/webview.rs +++ b/core/tauri-runtime/src/webview.rs @@ -30,11 +30,13 @@ pub struct WebviewAttributes { pub accept_first_mouse: bool, pub additional_browser_args: Option, pub window_effects: Option, + pub incognito: bool, } impl From<&WindowConfig> for WebviewAttributes { fn from(config: &WindowConfig) -> Self { let mut builder = Self::new(config.url.clone()); + builder = builder.incognito(config.incognito); builder = builder.accept_first_mouse(config.accept_first_mouse); if !config.file_drop_enabled { builder = builder.disable_file_drop_handler(); @@ -65,6 +67,7 @@ impl WebviewAttributes { accept_first_mouse: false, additional_browser_args: None, window_effects: None, + incognito: false, } } @@ -126,6 +129,13 @@ impl WebviewAttributes { self.window_effects = Some(effects); self } + + /// Enable or disable incognito mode for the WebView. + #[must_use] + pub fn incognito(mut self, incognito: bool) -> Self { + self.incognito = incognito; + self + } } /// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime). diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 03cdd4207..5d58abdc1 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -938,6 +938,13 @@ pub struct WindowConfig { /// - **Linux**: Unsupported #[serde(default, alias = "window-effects")] pub window_effects: Option, + /// Whether or not the webview should be launched in incognito mode. + /// + /// ## Platform-specific: + /// + /// - **Android**: Unsupported. + #[serde(default)] + pub incognito: bool, } impl Default for WindowConfig { @@ -978,6 +985,7 @@ impl Default for WindowConfig { additional_browser_args: None, shadow: true, window_effects: None, + incognito: false, } } } @@ -2161,6 +2169,7 @@ mod build { let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref()); let shadow = self.shadow; let window_effects = opt_lit(self.window_effects.as_ref()); + let incognito = self.incognito; literal_struct!( tokens, @@ -2199,7 +2208,8 @@ mod build { tabbing_identifier, additional_browser_args, shadow, - window_effects + window_effects, + incognito ); } } diff --git a/core/tauri/src/event/listener.rs b/core/tauri/src/event/listener.rs index 6a3d556fb..dc4475e67 100644 --- a/core/tauri/src/event/listener.rs +++ b/core/tauri/src/event/listener.rs @@ -235,14 +235,12 @@ mod test { // check to see if on_event properly grabs the stored function from listen. #[test] - fn check_on_event(e in "[a-z]+", d in "[a-z]+") { + fn check_on_event(key in "[a-z]+", d in "[a-z]+") { let listeners: Listeners = Default::default(); - // clone e as the key - let key = e.clone(); // call listen with e and the event_fn dummy func - listeners.listen(e.clone(), None, event_fn); + listeners.listen(key.clone(), None, event_fn); // call on event with e and d. - listeners.trigger(&e, None, Some(d)); + listeners.trigger(&key, None, Some(d)); // lock the mutex let l = listeners.inner.handlers.lock().unwrap(); diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 6e21abf07..383d6f329 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -741,6 +741,17 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { self.webview_attributes.clipboard = true; self } + + /// Enable or disable incognito mode for the WebView.. + /// + /// ## Platform-specific: + /// + /// **Android**: Unsupported. + #[must_use] + pub fn incognito(mut self, incognito: bool) -> Self { + self.webview_attributes.incognito = incognito; + self + } } /// Key for a JS event listener. diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index 2e87ffe2e..46c025741 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -514,6 +514,11 @@ "type": "null" } ] + }, + "incognito": { + "description": "Whether or not the webview should be launched in incognito mode.\n\n## Platform-specific:\n\n- **Android**: Unsupported.", + "default": false, + "type": "boolean" } }, "additionalProperties": false