Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ctrl+q and prepare ctrl+w keybinds #205

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0.91"
serde = { version = "1.0.152", features = ["derive"] }
tauri = { version = "1.2.3", features = ["api-all", "devtools", "updater"] }
tauri = { version = "1.2.3", features = ["api-all", "devtools", "global-shortcut", "updater"] }

[features]
# by default Tauri runs in production mode
Expand Down
19 changes: 15 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@

#[cfg(target_os = "macos")]
mod menu;
mod shortcuts;

fn main() {
let builder = tauri::Builder::default();

#[cfg(target_os = "macos")]
let builder = builder.menu(menu::menu());

builder
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
builder
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(run_event_handler)
}

fn run_event_handler<R: tauri::Runtime>(app: &tauri::AppHandle<R>, event: tauri::RunEvent) {
match event {
tauri::RunEvent::Ready => {
shortcuts::ready_event_handler(app);
}
_ => {}
}
}
27 changes: 27 additions & 0 deletions src-tauri/src/shortcuts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use tauri::{ GlobalShortcutManager, Manager };

//use crate::tray;

pub fn ready_event_handler<R: tauri::Runtime>(
app: &tauri::AppHandle<R>
) {
let manager = app.global_shortcut_manager();
//manager.clone().register("CmdOrCtrl+w", hide_closure(app)).unwrap();
manager.clone().register("CmdOrCtrl+q", close_closure(app)).unwrap();
}

/*
fn hide_closure<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> impl Fn() {
let window = app.get_window("main").unwrap();
let app = app.clone();
return move || {
window.hide().unwrap();
tray::toggle_window_state(window.clone(), app.tray_handle_by_id(tray::TRAY_LABEL).unwrap())
}
}
*/

fn close_closure<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> impl Fn() {
let window = app.get_window("main").unwrap();
return move || window.close().unwrap();
}