Support clearing cache and shortcut keys

This commit is contained in:
Tw93
2025-12-08 14:34:26 +08:00
parent 2767fc1b94
commit ca6a56d689
8 changed files with 48 additions and 5 deletions

2
src-tauri/Cargo.lock generated
View File

@@ -2588,7 +2588,7 @@ dependencies = [
[[package]]
name = "pake"
version = "3.5.4"
version = "3.6.0"
dependencies = [
"serde",
"serde_json",

View File

@@ -1,6 +1,6 @@
[package]
name = "pake"
version = "3.5.4"
version = "3.6.0"
description = "🤱🏻 Turn any webpage into a desktop app with Rust."
authors = ["Tw93"]
license = "MIT"

View File

@@ -116,7 +116,7 @@ pub fn send_notification(app: AppHandle, params: NotificationParams) -> Result<(
}
#[command]
pub fn update_theme_mode(app: AppHandle, mode: String) {
pub async fn update_theme_mode(app: AppHandle, mode: String) {
let window = app.get_webview_window("pake").unwrap();
#[cfg(target_os = "macos")]
{
@@ -128,3 +128,23 @@ pub fn update_theme_mode(app: AppHandle, mode: String) {
let _ = window.set_theme(Some(theme));
}
}
#[command]
#[allow(unreachable_code)]
pub fn clear_cache_and_restart(app: AppHandle) -> Result<(), String> {
if let Some(window) = app.get_webview_window("pake") {
match window.clear_all_browsing_data() {
Ok(_) => {
// Clear all browsing data successfully
app.restart();
Ok(())
}
Err(e) => {
eprintln!("Failed to clear browsing data: {}", e);
Err(format!("Failed to clear browsing data: {}", e))
}
}
} else {
Err("Main window not found".to_string())
}
}

View File

@@ -13,7 +13,10 @@ use tauri::menu::{AboutMetadata, Menu, MenuItem, PredefinedMenuItem, Submenu};
use tauri_plugin_opener::OpenerExt; // Add this
use app::{
invoke::{download_file, download_file_by_binary, send_notification, update_theme_mode},
invoke::{
clear_cache_and_restart, download_file, download_file_by_binary, send_notification,
update_theme_mode,
},
setup::{set_global_shortcut, set_system_tray},
window::set_window,
};
@@ -65,6 +68,7 @@ pub fn run_app() {
download_file_by_binary,
send_notification,
update_theme_mode,
clear_cache_and_restart,
])
.setup(move |app| {
// --- Menu Construction Start ---
@@ -91,6 +95,15 @@ pub fn run_app() {
// File Menu
let file_menu = Submenu::new(app, "File", true)?;
file_menu.append(&PredefinedMenuItem::close_window(app, None)?)?;
file_menu.append(&PredefinedMenuItem::separator(app)?)?;
file_menu.append(&MenuItem::with_id(
app,
"clear_cache_restart",
"Clear Cache & Restart",
true,
Some("CmdOrCtrl+Shift+Backspace"),
)?)?;
// Edit Menu
let edit_menu = Submenu::new(app, "Edit", true)?;
@@ -277,6 +290,13 @@ pub fn run_app() {
window.eval("navigator.clipboard.writeText(window.location.href)");
}
}
"clear_cache_restart" => {
if let Some(window) = app_handle.get_webview_window("pake") {
if let Ok(_) = window.clear_all_browsing_data() {
app_handle.restart();
}
}
}
"always_on_top" => {
if let Some(window) = app_handle.get_webview_window("pake") {
let is_on_top = window.is_always_on_top().unwrap_or(false);