chore: icon & global shortcuts

This commit is contained in:
lencx
2022-12-29 01:41:22 +08:00
parent 3424666ec9
commit 9a9fb24de8
6 changed files with 37 additions and 29 deletions

View File

@@ -1,8 +1,9 @@
use crate::{app::window, conf::ChatConfJson, utils};
use log::info;
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, Manager};
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager};
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
info!("stepup");
let chat_conf = ChatConfJson::get_chat_conf();
let url = chat_conf.origin.to_string();
let theme = ChatConfJson::theme();
@@ -12,31 +13,30 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
window::tray_window(&handle);
});
info!("stepup");
{
info!("global_shortcut_start");
let handle = app.app_handle();
let mut shortcut = app.global_shortcut_manager();
let core_shortcut = shortcut.is_registered("CmdOrCtrl+Shift+O");
// fix: Global shortcuts can cause programs to exit under windows
// {
// info!("global_shortcut_start");
// let handle = app.app_handle();
// let mut shortcut = app.global_shortcut_manager();
// let is_mini_key = shortcut.is_registered("CmdOrCtrl+Shift+O");
info!("is_registered: {}", core_shortcut.is_ok());
// if is_mini_key.is_ok() {
// shortcut
// .register("CmdOrCtrl+Shift+O", move || {
// if let Some(w) = handle.get_window("core") {
// if w.is_visible().unwrap() {
// w.hide().unwrap();
// } else {
// w.show().unwrap();
// w.set_focus().unwrap();
// }
// }
// })
// .unwrap();
// };
// info!("global_shortcut_end");
// }
if core_shortcut.is_ok() {
shortcut
.register("CmdOrCtrl+Shift+O", move || {
if let Some(w) = handle.get_window("core") {
if w.is_visible().unwrap() {
w.hide().unwrap();
} else {
w.show().unwrap();
w.set_focus().unwrap();
}
}
})
.unwrap();
};
info!("global_shortcut_end");
}
if chat_conf.hide_dock_icon {
#[cfg(target_os = "macos")]

View File

@@ -1,5 +1,6 @@
use crate::utils::{chat_root, create_file, exists};
use anyhow::Result;
use log::info;
use serde_json::Value;
use std::{collections::BTreeMap, fs, path::PathBuf, sync::Mutex};
use tauri::{Manager, Theme};
@@ -7,8 +8,8 @@ use tauri::{Manager, Theme};
#[cfg(target_os = "macos")]
use tauri::TitleBarStyle;
// pub const USER_AGENT: &str = "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36";
// pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
// pub const USER_AGENT: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15";
// pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1";
pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues";
pub const UPDATE_LOG_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/UPDATE_LOG.md";
@@ -66,6 +67,7 @@ impl ChatConfJson {
/// init chat.conf.json
/// path: ~/.chatgpt/chat.conf.json
pub fn init() -> PathBuf {
info!("chat_conf_init");
let conf_file = ChatConfJson::conf_path();
let content = if cfg!(target_os = "macos") {
DEFAULT_CHAT_CONF_MAC