Skip to content

Instantly share code, notes, and snippets.

@bedwards
Created December 30, 2023 21:21
Show Gist options
  • Save bedwards/c77688b51874a352ecf20f7c434f229c to your computer and use it in GitHub Desktop.
Save bedwards/c77688b51874a352ecf20f7c434f229c to your computer and use it in GitHub Desktop.
dioxus-desktop Cmd-Q quit
[dependencies]
active-win-pos-rs = "0.8.3"
dioxus = "0.4.3"
dioxus-desktop = "0.4.3"
dioxus-html = { version = "0.4.3", features = ["serialize", "native-bind"] }
wry = { version = "0.28.0", default-features = false, features = ["protocol", "file-drop"] }
use active_win_pos_rs::get_active_window;
use dioxus::prelude::*;
use dioxus_desktop;
use wry::application::keyboard::ModifiersState;
fn main() {
dioxus_desktop::launch(App);
}
#[allow(non_snake_case)]
fn App(cx: Scope) -> Element {
dioxus_desktop::use_global_shortcut(cx, (ModifiersState::SUPER, KeyCode::Q), || {
match get_active_window() {
Ok(active_window) => {
if active_window.process_id == std::process::id() as u64 {
std::process::exit(0);
}
}
Err(e) => panic!("{:#?}", e),
}
});
render!(div{"hello"})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment