✨ Support setting activationShortcut
This commit is contained in:
@@ -11,6 +11,7 @@ pub struct WindowConfig {
|
||||
pub url_type: String,
|
||||
pub always_on_top: bool,
|
||||
pub disabled_web_shortcuts: bool,
|
||||
pub activation_shortcut: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
||||
@@ -9,6 +9,7 @@ mod util;
|
||||
use app::{invoke, menu, window};
|
||||
use invoke::{download_file, download_file_by_binary};
|
||||
use menu::{get_system_tray, system_tray_handle};
|
||||
use tauri::{GlobalShortcutManager, Manager};
|
||||
use tauri_plugin_window_state::Builder as windowStatePlugin;
|
||||
use util::{get_data_dir, get_pake_config};
|
||||
use window::get_window;
|
||||
@@ -28,6 +29,9 @@ pub fn run_app() {
|
||||
.on_system_tray_event(system_tray_handle);
|
||||
}
|
||||
|
||||
// Save the value of toggle_app_shortcut before pake_config is moved
|
||||
let activation_shortcut = pake_config.windows[0].activation_shortcut.clone();
|
||||
|
||||
tauri_app
|
||||
.plugin(windowStatePlugin::default().build())
|
||||
.plugin(tauri_plugin_oauth::init())
|
||||
@@ -35,10 +39,28 @@ pub fn run_app() {
|
||||
download_file,
|
||||
download_file_by_binary
|
||||
])
|
||||
.setup(|app| {
|
||||
.setup(move |app| {
|
||||
let _window = get_window(app, pake_config, data_dir);
|
||||
// Prevent initial shaking
|
||||
_window.show().unwrap();
|
||||
|
||||
if !activation_shortcut.is_empty() {
|
||||
let app_handle = app.app_handle().clone();
|
||||
app_handle
|
||||
.global_shortcut_manager()
|
||||
.register(activation_shortcut.as_str(), move || {
|
||||
let window = app_handle.get_window("pake").unwrap();
|
||||
match window.is_visible().unwrap() {
|
||||
true => window.hide().unwrap(),
|
||||
false => {
|
||||
window.show().unwrap();
|
||||
window.set_focus().unwrap();
|
||||
}
|
||||
}
|
||||
})
|
||||
.expect("Error registering global evoke shortcuts!");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|event| {
|
||||
|
||||
Reference in New Issue
Block a user