-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
119 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use core::time::Duration; | ||
|
||
use global_hotkey::hotkey::HotKey; | ||
use global_hotkey::GlobalHotKeyEvent; | ||
|
||
use crate::utils::setup::HOTKEY_MANAGER; | ||
|
||
pub fn init_hotkey_listener() -> () { | ||
println!("init_hotkey_listener"); | ||
|
||
let hotkey_manager = HOTKEY_MANAGER.get().unwrap(); | ||
|
||
let hotkey_str = parse_shortcut(true, false, false, "y"); | ||
let hotkey: HotKey = hotkey_str.parse().unwrap(); | ||
|
||
let _ = hotkey_manager.register(hotkey).unwrap(); | ||
|
||
let receiver = GlobalHotKeyEvent::receiver(); | ||
std::thread::spawn(|| loop { | ||
if let Ok(event) = receiver.try_recv() { | ||
println!("tray event: {event:?}"); | ||
} | ||
std::thread::sleep(Duration::from_millis(100)); | ||
}); | ||
} | ||
|
||
pub fn parse_shortcut(ctrl: bool, alt: bool, shift: bool, key: &str) -> String { | ||
let mut modifiers = Vec::new(); | ||
if ctrl { | ||
modifiers.push("Control"); | ||
} | ||
if alt { | ||
modifiers.push("Alt"); | ||
} | ||
if shift { | ||
modifiers.push("Shift"); | ||
} | ||
|
||
format!( | ||
"{}{}Key{}", | ||
modifiers.join("+"), | ||
if !modifiers.is_empty() { "+" } else { "" }, | ||
key.to_uppercase() | ||
) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod hotkey_listener; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod clipboard; | ||
pub mod setup; | ||
pub mod tray; | ||
pub mod hotkey; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,7 @@ export type HotkeyEvent = | |
| "exit" | ||
| "toggle_dev_tools" | ||
| "scroll_to_top"; | ||
|
||
interface ImportMeta { | ||
env: any; | ||
} |
This file contains 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
This file contains 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