Skip to content

Commit f2d68cf

Browse files
authored
feat(core): expose Wry's with_incognito to Tauri on the WindowBuilder::incognito function. (#6767)
1 parent 3480047 commit f2d68cf

File tree

11 files changed

+63
-10
lines changed

11 files changed

+63
-10
lines changed

.changes/config-incognito.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:feat'
3+
---
4+
5+
Add `incognito` option to the window configuration object.

.changes/core-incognito.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:feat'
3+
---
4+
5+
Add `WindowBuilder::incognito`

core/tauri-codegen/src/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
184184
.tauri
185185
.security
186186
.dev_csp
187-
.clone()
188-
.or_else(|| config.tauri.security.csp.clone())
187+
.as_ref()
188+
.or(config.tauri.security.csp.as_ref())
189189
} else {
190-
config.tauri.security.csp.clone()
190+
config.tauri.security.csp.as_ref()
191191
};
192192
if csp.is_some() {
193193
options = options.with_csp();

core/tauri-config-schema/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@
514514
"type": "null"
515515
}
516516
]
517+
},
518+
"incognito": {
519+
"description": "Whether or not the webview should be launched in incognito mode.\n\n## Platform-specific:\n\n- **Android**: Unsupported.",
520+
"default": false,
521+
"type": "boolean"
517522
}
518523
},
519524
"additionalProperties": false

core/tauri-macros/src/mobile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn get_env_var<R: FnOnce(String) -> String>(
3434

3535
pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
3636
let function = parse_macro_input!(item as ItemFn);
37-
let function_name = function.sig.ident.clone();
37+
let function_name = &function.sig.ident;
3838

3939
let mut error = None;
4040
let domain = get_env_var("TAURI_ANDROID_PACKAGE_PREFIX", |r| r, &mut error, &function);

core/tauri-runtime-wry/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,10 @@ fn create_webview<T: UserEvent>(
31333133
webview_builder.webview.clipboard = true;
31343134
}
31353135

3136+
if webview_attributes.incognito {
3137+
webview_builder.webview.incognito = true;
3138+
}
3139+
31363140
#[cfg(any(debug_assertions, feature = "devtools"))]
31373141
{
31383142
webview_builder = webview_builder.with_devtools(true);

core/tauri-runtime/src/webview.rs

+10
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ pub struct WebviewAttributes {
3030
pub accept_first_mouse: bool,
3131
pub additional_browser_args: Option<String>,
3232
pub window_effects: Option<WindowEffectsConfig>,
33+
pub incognito: bool,
3334
}
3435

3536
impl From<&WindowConfig> for WebviewAttributes {
3637
fn from(config: &WindowConfig) -> Self {
3738
let mut builder = Self::new(config.url.clone());
39+
builder = builder.incognito(config.incognito);
3840
builder = builder.accept_first_mouse(config.accept_first_mouse);
3941
if !config.file_drop_enabled {
4042
builder = builder.disable_file_drop_handler();
@@ -65,6 +67,7 @@ impl WebviewAttributes {
6567
accept_first_mouse: false,
6668
additional_browser_args: None,
6769
window_effects: None,
70+
incognito: false,
6871
}
6972
}
7073

@@ -126,6 +129,13 @@ impl WebviewAttributes {
126129
self.window_effects = Some(effects);
127130
self
128131
}
132+
133+
/// Enable or disable incognito mode for the WebView.
134+
#[must_use]
135+
pub fn incognito(mut self, incognito: bool) -> Self {
136+
self.incognito = incognito;
137+
self
138+
}
129139
}
130140

131141
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

core/tauri-utils/src/config.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,13 @@ pub struct WindowConfig {
938938
/// - **Linux**: Unsupported
939939
#[serde(default, alias = "window-effects")]
940940
pub window_effects: Option<WindowEffectsConfig>,
941+
/// Whether or not the webview should be launched in incognito mode.
942+
///
943+
/// ## Platform-specific:
944+
///
945+
/// - **Android**: Unsupported.
946+
#[serde(default)]
947+
pub incognito: bool,
941948
}
942949

943950
impl Default for WindowConfig {
@@ -978,6 +985,7 @@ impl Default for WindowConfig {
978985
additional_browser_args: None,
979986
shadow: true,
980987
window_effects: None,
988+
incognito: false,
981989
}
982990
}
983991
}
@@ -2161,6 +2169,7 @@ mod build {
21612169
let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref());
21622170
let shadow = self.shadow;
21632171
let window_effects = opt_lit(self.window_effects.as_ref());
2172+
let incognito = self.incognito;
21642173

21652174
literal_struct!(
21662175
tokens,
@@ -2199,7 +2208,8 @@ mod build {
21992208
tabbing_identifier,
22002209
additional_browser_args,
22012210
shadow,
2202-
window_effects
2211+
window_effects,
2212+
incognito
22032213
);
22042214
}
22052215
}

core/tauri/src/event/listener.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,12 @@ mod test {
235235

236236
// check to see if on_event properly grabs the stored function from listen.
237237
#[test]
238-
fn check_on_event(e in "[a-z]+", d in "[a-z]+") {
238+
fn check_on_event(key in "[a-z]+", d in "[a-z]+") {
239239
let listeners: Listeners = Default::default();
240-
// clone e as the key
241-
let key = e.clone();
242240
// call listen with e and the event_fn dummy func
243-
listeners.listen(e.clone(), None, event_fn);
241+
listeners.listen(key.clone(), None, event_fn);
244242
// call on event with e and d.
245-
listeners.trigger(&e, None, Some(d));
243+
listeners.trigger(&key, None, Some(d));
246244

247245
// lock the mutex
248246
let l = listeners.inner.handlers.lock().unwrap();

core/tauri/src/window.rs

+11
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,17 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
741741
self.webview_attributes.clipboard = true;
742742
self
743743
}
744+
745+
/// Enable or disable incognito mode for the WebView..
746+
///
747+
/// ## Platform-specific:
748+
///
749+
/// **Android**: Unsupported.
750+
#[must_use]
751+
pub fn incognito(mut self, incognito: bool) -> Self {
752+
self.webview_attributes.incognito = incognito;
753+
self
754+
}
744755
}
745756

746757
/// Key for a JS event listener.

tooling/cli/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@
514514
"type": "null"
515515
}
516516
]
517+
},
518+
"incognito": {
519+
"description": "Whether or not the webview should be launched in incognito mode.\n\n## Platform-specific:\n\n- **Android**: Unsupported.",
520+
"default": false,
521+
"type": "boolean"
517522
}
518523
},
519524
"additionalProperties": false

0 commit comments

Comments
 (0)