Created
December 30, 2023 21:21
-
-
Save bedwards/c77688b51874a352ecf20f7c434f229c to your computer and use it in GitHub Desktop.
dioxus-desktop Cmd-Q quit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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