fix: package crash problem (#50)

This commit is contained in:
BiggerRain
2024-12-13 14:49:47 +08:00
committed by GitHub
parent 72b60db618
commit e432f5a3d6
4 changed files with 15 additions and 12 deletions

View File

@@ -13,7 +13,7 @@
"@headlessui/react": "^2.1.10", "@headlessui/react": "^2.1.10",
"@tauri-apps/api": ">=2.0.0", "@tauri-apps/api": ">=2.0.0",
"@tauri-apps/plugin-autostart": "~2", "@tauri-apps/plugin-autostart": "~2",
"@tauri-apps/plugin-global-shortcut": "~2", "@tauri-apps/plugin-global-shortcut": "~2.0.0",
"@tauri-apps/plugin-http": "~2.0.1", "@tauri-apps/plugin-http": "~2.0.1",
"@tauri-apps/plugin-os": "^2.0.0", "@tauri-apps/plugin-os": "^2.0.0",
"@tauri-apps/plugin-shell": ">=2.0.0", "@tauri-apps/plugin-shell": ">=2.0.0",

2
pnpm-lock.yaml generated
View File

@@ -18,7 +18,7 @@ importers:
specifier: ~2 specifier: ~2
version: 2.0.0 version: 2.0.0
'@tauri-apps/plugin-global-shortcut': '@tauri-apps/plugin-global-shortcut':
specifier: ~2 specifier: ~2.0.0
version: 2.0.0 version: 2.0.0
'@tauri-apps/plugin-http': '@tauri-apps/plugin-http':
specifier: ~2.0.1 specifier: ~2.0.1

View File

@@ -42,6 +42,7 @@
"global-shortcut:allow-is-registered", "global-shortcut:allow-is-registered",
"global-shortcut:allow-register", "global-shortcut:allow-register",
"global-shortcut:allow-unregister", "global-shortcut:allow-unregister",
"global-shortcut:allow-unregister-all",
{ {
"identifier": "http:default", "identifier": "http:default",
"allow": [ "allow": [

View File

@@ -167,14 +167,18 @@ fn enable_shortcut(app: &mut tauri::App) {
#[tauri::command] #[tauri::command]
fn change_shortcut<R: Runtime>( fn change_shortcut<R: Runtime>(
app: tauri::AppHandle<R>, app: tauri::AppHandle<R>,
window: tauri::Window<R>, _window: tauri::Window<R>,
key: String, key: String,
) -> Result<(), String> { ) -> Result<(), String> {
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use tauri_plugin_global_shortcut::ShortcutState; use tauri_plugin_global_shortcut::ShortcutState;
remove_shortcut(&app)?; if let Err(e) = remove_shortcut(&app) {
eprintln!("Failed to remove old shortcut: {}", e);
}
let main_window = app.get_webview_window("main").unwrap();
let shortcut: Shortcut = key let shortcut: Shortcut = key
.parse() .parse()
@@ -184,11 +188,11 @@ fn change_shortcut<R: Runtime>(
if scut == &shortcut { if scut == &shortcut {
if let ShortcutState::Pressed = event.state() { if let ShortcutState::Pressed = event.state() {
println!("Command+B Pressed!"); println!("Command+B Pressed!");
if window.is_focused().unwrap() { if main_window.is_focused().unwrap() {
window.hide().unwrap(); main_window.hide().unwrap();
} else { } else {
window.show().unwrap(); main_window.show().unwrap();
window.set_focus().unwrap(); main_window.set_focus().unwrap();
} }
} }
} }
@@ -240,14 +244,12 @@ fn remove_shortcut<R: Runtime>(app: &tauri::AppHandle<R>) -> Result<(), String>
fn enable_tray(app: &mut tauri::App) { fn enable_tray(app: &mut tauri::App) {
use tauri::{ use tauri::{
image::Image, // image::Image,
menu::{MenuBuilder, MenuItem}, menu::{MenuBuilder, MenuItem},
tray::TrayIconBuilder, tray::TrayIconBuilder,
webview::WebviewBuilder, webview::WebviewBuilder,
}; };
let image = Image::from_path("icons/32x32.png").unwrap();
let quit_i = MenuItem::with_id(app, "quit", "Quit Coco", true, None::<&str>).unwrap(); let quit_i = MenuItem::with_id(app, "quit", "Quit Coco", true, None::<&str>).unwrap();
let settings_i = MenuItem::with_id(app, "settings", "Settings", true, None::<&str>).unwrap(); let settings_i = MenuItem::with_id(app, "settings", "Settings", true, None::<&str>).unwrap();
let open_i = MenuItem::with_id(app, "open", "Open Coco", true, None::<&str>).unwrap(); let open_i = MenuItem::with_id(app, "open", "Open Coco", true, None::<&str>).unwrap();
@@ -261,7 +263,7 @@ fn enable_tray(app: &mut tauri::App) {
.unwrap(); .unwrap();
let _tray = TrayIconBuilder::new() let _tray = TrayIconBuilder::new()
.icon(image) .icon(app.default_window_icon().unwrap().clone())
.menu(&menu) .menu(&menu)
.on_menu_event(|app, event| match event.id.as_ref() { .on_menu_event(|app, event| match event.id.as_ref() {
"show" => { "show" => {