diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ae3a088..ef9992d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -374,6 +374,7 @@ dependencies = [ "serde", "tauri", "tauri-build", + "tauri-plugin-global-shortcut", ] [[package]] @@ -838,6 +839,16 @@ dependencies = [ "typeid", ] +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "fallible-iterator" version = "0.3.0" @@ -1121,6 +1132,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" +dependencies = [ + "rustix", + "windows-link 0.2.1", +] + [[package]] name = "getrandom" version = "0.2.17" @@ -1245,6 +1266,24 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" +[[package]] +name = "global-hotkey" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c386b0a4a70cb2d39fffd74480f985b6f0bfbcb934b6a6b6b7e630e448f242e" +dependencies = [ + "crossbeam-channel", + "keyboard-types", + "objc2", + "objc2-app-kit", + "once_cell", + "serde", + "thiserror 2.0.20", + "windows-sys 0.59.0", + "x11rb", + "xkeysym", +] + [[package]] name = "gobject-sys" version = "0.18.0" @@ -1885,6 +1924,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + [[package]] name = "litemap" version = "0.8.3" @@ -2870,6 +2915,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags 2.13.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + [[package]] name = "rustls" version = "0.23.44" @@ -3584,6 +3642,37 @@ dependencies = [ "tauri-utils", ] +[[package]] +name = "tauri-plugin" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74be5dd4bed9afbd145e5716b5fa2ec28cbc29c34ffa61c258c9273d896c8020" +dependencies = [ + "anyhow", + "glob", + "plist", + "schemars 0.8.22", + "serde", + "serde_json", + "tauri-utils", + "walkdir", +] + +[[package]] +name = "tauri-plugin-global-shortcut" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4dd9f4c5136c09cd962da0c86dc4accd4666db2ea591cf16e6597435843bd2b" +dependencies = [ + "global-hotkey", + "log", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.20", +] + [[package]] name = "tauri-runtime" version = "2.11.3" @@ -4942,6 +5031,29 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414" +dependencies = [ + "gethostname", + "rustix", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd" + +[[package]] +name = "xkeysym" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" + [[package]] name = "yoke" version = "0.8.3" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4d9b7ce..50bab74 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,3 +12,4 @@ tauri-build = { version = "2.5.3", features = [] } clipforge = { path = ".." } serde = { version = "1", features = ["derive"] } tauri = { version = "2.9.5", features = [] } +tauri-plugin-global-shortcut = "2" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6104d3d..5caf33f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use std::process::Command; use std::sync::Mutex; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use tauri::State; +use tauri::{Manager, State}; struct AppRuntime { recorder: Mutex, @@ -105,6 +105,10 @@ fn list_clips(runtime: State<'_, AppRuntime>) -> Result, String> { #[tauri::command] fn save_manual_clip(seconds: u64, runtime: State<'_, AppRuntime>) -> Result { + save_manual_clip_inner(seconds, runtime.inner()) +} + +fn save_manual_clip_inner(seconds: u64, runtime: &AppRuntime) -> Result { let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; let capture = runtime.capture.lock().map_err(|error| error.to_string())?; let Some(active) = capture.as_ref() else { @@ -155,13 +159,17 @@ fn save_manual_clip(seconds: u64, runtime: State<'_, AppRuntime>) -> Result) -> Result { + start_capture_inner(runtime.inner()) +} + +fn start_capture_inner(runtime: &AppRuntime) -> Result { let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; let mut capture = runtime.capture.lock().map_err(|error| error.to_string())?; @@ -217,6 +225,10 @@ fn start_capture(runtime: State<'_, AppRuntime>) -> Result) -> Result { + stop_capture_inner(runtime.inner()) +} + +fn stop_capture_inner(runtime: &AppRuntime) -> Result { let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?; let mut capture = runtime.capture.lock().map_err(|error| error.to_string())?; @@ -241,7 +253,7 @@ fn stop_capture(runtime: State<'_, AppRuntime>) -> Result if let Some(thumbnail_path) = &clip.thumbnail_path { let _ = generate_thumbnail(&ffmpeg, &clip.path, thumbnail_path); } - persist_clip(&runtime, &clip)?; + persist_clip(runtime, &clip)?; } if is_inside_root(&recorder.paths.buffer_root, &active.buffer_dir) { let _ = fs::remove_dir_all(&active.buffer_dir); @@ -273,7 +285,7 @@ fn delete_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result) -> Result(); + if shortcut == &handler_clip_60 { + let _ = save_manual_clip_inner(60, runtime.inner()); + } else if shortcut == &handler_clip_30 { + let _ = save_manual_clip_inner(30, runtime.inner()); + } else if shortcut == &handler_toggle_recording { + let capture_active = runtime + .capture + .lock() + .map(|capture| capture.is_some()) + .unwrap_or(false); + if capture_active { + let _ = stop_capture_inner(runtime.inner()); + } else { + let _ = start_capture_inner(runtime.inner()); + } + } + }) + .build(), + )?; + app.global_shortcut().register(clip_60)?; + app.global_shortcut().register(clip_30)?; + app.global_shortcut().register(toggle_recording)?; + } + Ok(()) + }) .invoke_handler(tauri::generate_handler![ get_status, refresh_detected_game, @@ -558,14 +616,14 @@ fn clip_to_dto(clip: &Clip) -> ClipDto { } } -fn persist_clip(runtime: &State<'_, AppRuntime>, clip: &Clip) -> Result<(), String> { +fn persist_clip(runtime: &AppRuntime, clip: &Clip) -> Result<(), String> { let database = runtime.database.lock().map_err(|error| error.to_string())?; database .upsert_clip(clip) .map_err(|error| format!("Could not save clip database record: {error}")) } -fn delete_clip_record(runtime: &State<'_, AppRuntime>, clip_id: &str) -> Result<(), String> { +fn delete_clip_record(runtime: &AppRuntime, clip_id: &str) -> Result<(), String> { let database = runtime.database.lock().map_err(|error| error.to_string())?; database .delete_clip(clip_id)