mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 03:47:37 +03:00
feat: add webview.clear_all_browsing_data
(#11066)
* feat: add `webview.clear_all_browsing_data` closes #6567 * fix build on iOS and android * fix command name references --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
parent
0ddfc59d67
commit
9014a3f176
6
.changes/clear-all-browsing-data-api.md
Normal file
6
.changes/clear-all-browsing-data-api.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@tauri-apps/api": "patch:feat"
|
||||
---
|
||||
|
||||
Add `WebviewWindow.clearAllBrowsingData` and `Webview.clearAllBrowsingData` to clear the webview browsing data.
|
||||
|
8
.changes/clear-all-browsing-data.md
Normal file
8
.changes/clear-all-browsing-data.md
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
"tauri": "patch:feat"
|
||||
"tauri-runtime": "patch:feat"
|
||||
"tauri-runtime-wry": "patch:feat"
|
||||
---
|
||||
|
||||
Add `WebviewWindow::clear_all_browsing_data` and `Webview::clear_all_browsing_data` to clear the webview browsing data.
|
||||
|
@ -1239,6 +1239,7 @@ pub enum WebviewMessage {
|
||||
Reparent(WindowId, Sender<Result<()>>),
|
||||
SetAutoResize(bool),
|
||||
SetZoom(f64),
|
||||
ClearAllBrowsingData,
|
||||
// Getters
|
||||
Url(Sender<Result<String>>),
|
||||
Bounds(Sender<Result<tauri_runtime::Rect>>),
|
||||
@ -1516,6 +1517,17 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn clear_all_browsing_data(&self) -> Result<()> {
|
||||
send_user_message(
|
||||
&self.context,
|
||||
Message::Webview(
|
||||
*self.window_id.lock().unwrap(),
|
||||
self.webview_id,
|
||||
WebviewMessage::ClearAllBrowsingData,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The Tauri [`WindowDispatch`] for [`Wry`].
|
||||
@ -3157,6 +3169,11 @@ fn handle_user_message<T: UserEvent>(
|
||||
log::error!("failed to set webview zoom: {e}");
|
||||
}
|
||||
}
|
||||
WebviewMessage::ClearAllBrowsingData => {
|
||||
if let Err(e) = webview.clear_all_browsing_data() {
|
||||
log::error!("failed to clear webview browsing data: {e}");
|
||||
}
|
||||
}
|
||||
// Getters
|
||||
WebviewMessage::Url(tx) => {
|
||||
tx.send(
|
||||
|
@ -512,6 +512,9 @@ pub trait WebviewDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + '
|
||||
|
||||
/// Set the webview zoom level
|
||||
fn set_zoom(&self, scale_factor: f64) -> Result<()>;
|
||||
|
||||
/// Clear all browsing data for this webview.
|
||||
fn clear_all_browsing_data(&self) -> Result<()>;
|
||||
}
|
||||
|
||||
/// Window dispatcher. A thread-safe handle to the window APIs.
|
||||
|
@ -127,6 +127,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
|
||||
("set_webview_zoom", false),
|
||||
("print", false),
|
||||
("reparent", false),
|
||||
("clear_all_browsing_data", false),
|
||||
// internal
|
||||
("internal_toggle_devtools", true),
|
||||
],
|
||||
|
@ -16,6 +16,32 @@ Default permissions for the plugin.
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`core:webview:allow-clear-all-browsing-data`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the clear_all_browsing_data command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`core:webview:deny-clear-all-browsing-data`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the clear_all_browsing_data command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -572,6 +572,10 @@ impl<T: UserEvent> WebviewDispatch<T> for MockWebviewDispatcher {
|
||||
fn set_auto_resize(&self, auto_resize: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_all_browsing_data(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
|
||||
|
@ -1472,6 +1472,15 @@ tauri::Builder::default()
|
||||
.set_zoom(scale_factor)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Clear all browsing data for this webview.
|
||||
pub fn clear_all_browsing_data(&self) -> crate::Result<()> {
|
||||
self
|
||||
.webview
|
||||
.dispatcher
|
||||
.clear_all_browsing_data()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> Listener<R> for Webview<R> {
|
||||
|
@ -177,6 +177,7 @@ mod desktop_commands {
|
||||
setter!(set_webview_position, set_position, Position);
|
||||
setter!(set_webview_focus, set_focus);
|
||||
setter!(set_webview_zoom, set_zoom, f64);
|
||||
setter!(clear_all_browsing_data, clear_all_browsing_data);
|
||||
|
||||
#[command(root = "crate")]
|
||||
pub async fn reparent<R: Runtime>(
|
||||
@ -262,6 +263,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
desktop_commands::set_webview_zoom,
|
||||
desktop_commands::print,
|
||||
desktop_commands::reparent,
|
||||
desktop_commands::clear_all_browsing_data,
|
||||
#[cfg(any(debug_assertions, feature = "devtools"))]
|
||||
desktop_commands::internal_toggle_devtools,
|
||||
]);
|
||||
|
@ -1782,6 +1782,11 @@ impl<R: Runtime> WebviewWindow<R> {
|
||||
pub fn set_zoom(&self, scale_factor: f64) -> crate::Result<()> {
|
||||
self.webview.set_zoom(scale_factor)
|
||||
}
|
||||
|
||||
/// Clear all browsing data for this webview window.
|
||||
pub fn clear_all_browsing_data(&self) -> crate::Result<()> {
|
||||
self.webview.clear_all_browsing_data()
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> Listener<R> for WebviewWindow<R> {
|
||||
|
@ -517,6 +517,20 @@ class Webview {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all browsing data for this webview.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { getCurrentWebview } from '@tauri-apps/api/webview';
|
||||
* await getCurrentWebview().clearAllBrowsingData();
|
||||
* ```
|
||||
*
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
*/
|
||||
async clearAllBrowsingData(): Promise<void> {
|
||||
return invoke('plugin:webview|clear_all_browsing_data')
|
||||
}
|
||||
|
||||
// Listeners
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user