feat(core): expose Wry's with_incognito to Tauri on the WindowBuilder::incognito function. (#6767)

This commit is contained in:
Hyph 2023-06-06 23:30:37 +08:00 committed by GitHub
parent 3480047ec1
commit f2d68cf7d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 63 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
'tauri': 'patch:feat'
---
Add `incognito` option to the window configuration object.

View File

@ -0,0 +1,5 @@
---
'tauri': 'patch:feat'
---
Add `WindowBuilder::incognito`

View File

@ -184,10 +184,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
.tauri
.security
.dev_csp
.clone()
.or_else(|| config.tauri.security.csp.clone())
.as_ref()
.or(config.tauri.security.csp.as_ref())
} else {
config.tauri.security.csp.clone()
config.tauri.security.csp.as_ref()
};
if csp.is_some() {
options = options.with_csp();

View File

@ -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

View File

@ -34,7 +34,7 @@ fn get_env_var<R: FnOnce(String) -> 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);

View File

@ -3133,6 +3133,10 @@ fn create_webview<T: UserEvent>(
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);

View File

@ -30,11 +30,13 @@ pub struct WebviewAttributes {
pub accept_first_mouse: bool,
pub additional_browser_args: Option<String>,
pub window_effects: Option<WindowEffectsConfig>,
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).

View File

@ -938,6 +938,13 @@ pub struct WindowConfig {
/// - **Linux**: Unsupported
#[serde(default, alias = "window-effects")]
pub window_effects: Option<WindowEffectsConfig>,
/// 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
);
}
}

View File

@ -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();

View File

@ -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.

View File

@ -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