feat: add screenshot capture with F9 hotkey and library panel
This commit is contained in:
1 parent
50ab1cd54a
commit
a2800c3664
7 files changed
+677
-108
No files matched your search
Generated
+105
-6
@@ -360,6 +360,7 @@ dependencies = [
|
||||
name = "clipforge"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dirs 5.0.1",
|
||||
"reqwest 0.12.28",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
@@ -666,13 +667,34 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
"dirs-sys 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users 0.4.6",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -683,7 +705,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"redox_users 0.5.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
@@ -2749,6 +2771,17 @@ dependencies = [
|
||||
"bitflags 2.13.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
"libredox",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.2"
|
||||
@@ -3550,7 +3583,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"cookie",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
"embed_plist",
|
||||
"getrandom 0.3.4",
|
||||
@@ -3600,7 +3633,7 @@ checksum = "bc9ce40b16101cb6ea63d3e221567affd1c3a9205f95d7bc574941a10636b632"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"glob",
|
||||
"heck 0.5.0",
|
||||
"json-patch",
|
||||
@@ -4117,7 +4150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "045979e3f037cd18ad1cb2a419dfda133c5c29c9f3453370079f2255d46c257e"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"libappindicator",
|
||||
"muda",
|
||||
"objc2",
|
||||
@@ -4834,6 +4867,15 @@ dependencies = [
|
||||
"windows-targets 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
@@ -4876,6 +4918,21 @@ dependencies = [
|
||||
"windows_x86_64_msvc 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
@@ -4925,6 +4982,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -4937,6 +5000,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -4949,6 +5018,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -4967,6 +5042,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -4979,6 +5060,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -4991,6 +5078,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -5003,6 +5096,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -5065,7 +5164,7 @@ dependencies = [
|
||||
"block2",
|
||||
"cookie",
|
||||
"crossbeam-channel",
|
||||
"dirs",
|
||||
"dirs 6.0.0",
|
||||
"dom_query",
|
||||
"dpi",
|
||||
"dunce",
|
||||
|
||||
+64
-16
@@ -58,6 +58,7 @@ struct HotkeyShortcuts {
|
||||
clip_60: tauri_plugin_global_shortcut::Shortcut,
|
||||
clip_30: tauri_plugin_global_shortcut::Shortcut,
|
||||
toggle_recording: tauri_plugin_global_shortcut::Shortcut,
|
||||
screenshot: tauri_plugin_global_shortcut::Shortcut,
|
||||
}
|
||||
|
||||
struct ActiveCapture {
|
||||
@@ -960,6 +961,35 @@ fn export_clip_copy(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<S
|
||||
Ok(output.display().to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn take_screenshot(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
||||
handle_screenshot()?;
|
||||
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn reveal_screenshot(path: String) -> Result<(), String> {
|
||||
let path = PathBuf::from(&path);
|
||||
if !path.exists() {
|
||||
return Err(format!("Screenshot file does not exist: {}", path.display()));
|
||||
}
|
||||
Command::new("explorer")
|
||||
.arg(format!("/select,{}", path.display()))
|
||||
.spawn()
|
||||
.map_err(|error| error.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn list_screenshots() -> Result<Vec<String>, String> {
|
||||
Ok(clipforge::screenshot::list_screenshots()
|
||||
.into_iter()
|
||||
.filter_map(|path| path.to_str().map(|s| s.to_string()))
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn upload_clip_with_settings(
|
||||
clip: &Clip,
|
||||
settings: &AppSettings,
|
||||
@@ -1185,6 +1215,7 @@ fn register_hotkeys(
|
||||
let _ = app.global_shortcut().unregister(existing.clip_60);
|
||||
let _ = app.global_shortcut().unregister(existing.clip_30);
|
||||
let _ = app.global_shortcut().unregister(existing.toggle_recording);
|
||||
let _ = app.global_shortcut().unregister(existing.screenshot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1197,9 +1228,14 @@ fn register_hotkeys(
|
||||
let clip_30 = Shortcut::new(clip_30_mods, clip_30_code);
|
||||
let toggle_recording = Shortcut::new(toggle_mods, toggle_code);
|
||||
|
||||
let (screenshot_mods, screenshot_code) = parse_accelerator(&settings.screenshot)?;
|
||||
|
||||
let screenshot = Shortcut::new(screenshot_mods, screenshot_code);
|
||||
|
||||
let handler_clip_60 = clip_60.clone();
|
||||
let handler_clip_30 = clip_30.clone();
|
||||
let handler_toggle_recording = toggle_recording.clone();
|
||||
let handler_screenshot = screenshot.clone();
|
||||
|
||||
app.plugin(
|
||||
tauri_plugin_global_shortcut::Builder::new()
|
||||
@@ -1223,6 +1259,8 @@ fn register_hotkeys(
|
||||
} else {
|
||||
let _ = start_capture_inner(runtime.inner());
|
||||
}
|
||||
} else if shortcut == &handler_screenshot {
|
||||
let _ = handle_screenshot();
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
@@ -1231,12 +1269,14 @@ fn register_hotkeys(
|
||||
app.global_shortcut().register(clip_60.clone()).map_err(|e| e.to_string())?;
|
||||
app.global_shortcut().register(clip_30.clone()).map_err(|e| e.to_string())?;
|
||||
app.global_shortcut().register(toggle_recording.clone()).map_err(|e| e.to_string())?;
|
||||
app.global_shortcut().register(screenshot.clone()).map_err(|e| e.to_string())?;
|
||||
|
||||
if let Ok(mut shortcuts_guard) = runtime.hotkey_shortcuts.lock() {
|
||||
*shortcuts_guard = Some(HotkeyShortcuts {
|
||||
clip_60,
|
||||
clip_30,
|
||||
toggle_recording,
|
||||
screenshot,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1330,27 +1370,35 @@ fn main() {
|
||||
set_mic_enabled,
|
||||
set_system_audio_enabled,
|
||||
list_audio_devices,
|
||||
set_mic_device,
|
||||
set_auto_record_enabled,
|
||||
set_upload_settings,
|
||||
set_auto_clip_event_enabled,
|
||||
write_gsi_configs,
|
||||
poll_auto_clip_events,
|
||||
save_manual_clip,
|
||||
start_capture,
|
||||
stop_capture,
|
||||
delete_clip,
|
||||
reveal_clip,
|
||||
trim_clip,
|
||||
upload_clip,
|
||||
update_clip_metadata,
|
||||
export_clip_copy,
|
||||
set_hotkeys
|
||||
set_mic_device,
|
||||
set_auto_record_enabled,
|
||||
set_upload_settings,
|
||||
set_auto_clip_event_enabled,
|
||||
write_gsi_configs,
|
||||
poll_auto_clip_events,
|
||||
save_manual_clip,
|
||||
start_capture,
|
||||
stop_capture,
|
||||
delete_clip,
|
||||
reveal_clip,
|
||||
trim_clip,
|
||||
upload_clip,
|
||||
update_clip_metadata,
|
||||
export_clip_copy,
|
||||
take_screenshot,
|
||||
list_screenshots,
|
||||
reveal_screenshot,
|
||||
set_hotkeys
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running ClipForge desktop shell");
|
||||
}
|
||||
|
||||
fn handle_screenshot() -> Result<(), String> {
|
||||
clipforge::screenshot::take_screenshot().map_err(|error| error.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_runtime() -> Result<(PathBuf, RecorderService, ClipDatabase), String> {
|
||||
let root = env::current_dir()
|
||||
.unwrap_or_else(|_| PathBuf::from("."))
|
||||
|
||||
Reference in new issue
Block a user