Unable to register global shortcuts #10017
-
Hey, i want to create a small svelte tauri app wich can be opened and closed via a shortcut. I somewhat followed these steps I ran "permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"image:default",
"resources:default",
"menu:default",
"tray:default",
"shell:allow-open",
"global-shortcut:allow-is-registered",
"global-shortcut:allow-register",
"global-shortcut:allow-unregister"
] And copied the code snipped from the github plugin page in my main.rs // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{Manager, AppHandle};
use tauri_plugin_global_shortcut::{Code, Modifiers, ShortcutState};
const WINDOW: &str = "launcher";
fn toggle_launchbar(app: &AppHandle) {
let window = app.get_webview_window(WINDOW).expect("Did you label your window?");
if let Ok(true) = window.is_visible() {
let _ = window.hide();
} else {
let _ = window.show();
}
}
fn main() {
tauri::Builder::default()
.setup(|app| {
#[cfg(desktop)]
{
println!("Setting up global shortcut"); // is printed out
app.handle().plugin(
tauri_plugin_global_shortcut::Builder::new()
.with_shortcuts(["ctrl+d", "alt+space"])?
.with_handler(|app, shortcut, event| {
println!("im here"); // not here
if event.state == ShortcutState::Pressed {
if shortcut.matches(Modifiers::CONTROL, Code::KeyD) {
println!("Ctrl+D triggered");
let _ = app.emit("shortcut-event", "Ctrl+D triggered");
toggle_launchbar(app);
}
if shortcut.matches(Modifiers::ALT, Code::Space) {
println!("Alt+Space triggered");
let _ = app.emit("shortcut-event", "Alt+Space triggered");
}
}
})
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
} However the second log statement doesnt appear and the shortcuts arent working. Here is my tauri info maybe its helpful. Im using wsl.
Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think that's the issue, especially since wsl uses wayland where global shortcuts aren't supported yet iirc. |
Beta Was this translation helpful? Give feedback.
I think that's the issue, especially since wsl uses wayland where global shortcuts aren't supported yet iirc.