mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 19:47:43 +01:00
fix: package crash problem (#50)
This commit is contained in:
@@ -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
2
pnpm-lock.yaml
generated
@@ -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
|
||||||
|
|||||||
@@ -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": [
|
||||||
|
|||||||
@@ -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" => {
|
||||||
|
|||||||
Reference in New Issue
Block a user