All tests run on an 8-year-old MacBook Air.
All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.
Global shortcuts in Tauri v2 changed significantly from v1. The plugin API is cleaner now, but there are still ways to get it wrong.
Here's what I learned building a menubar app with a system-wide shortcut.
The basics
Add the plugin:
toml# Cargo.toml
tauri-plugin-global-shortcut = "2"
json// package.json
"@tauri-apps/plugin-global-shortcut": "^2.0.0"
Register in main.rs:
rustuse tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut};
tauri::Builder::default()
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.setup(|app| {
let shortcut = Shortcut::new(
Some(Modifiers::SUPER | Modifiers::SHIFT),
Code::KeyH
);
app.global_shortcut().register(shortcut)?;
Ok(())
})
The wrong way: hardcoded shortcuts
Hardcoding Cmd+Shift+H is fine for your machine.…