feat: use the keyboard to select the slash command

This commit is contained in:
lencx
2022-12-27 14:41:50 +08:00
parent 06ee907199
commit 39febe759e
6 changed files with 124 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
use crate::{app::window, conf::ChatConfJson, utils};
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>> {
let chat_conf = ChatConfJson::get_chat_conf();
@@ -11,6 +11,27 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
window::tray_window(&handle);
});
{
let handle = app.app_handle();
let mut shortcut = app.global_shortcut_manager();
let is_mini_key = shortcut.is_registered("CmdOrCtrl+Shift+O");
if !is_mini_key.unwrap() {
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();
};
}
if chat_conf.hide_dock_icon {
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory);