feat: add screenshot capture with F9 hotkey and library panel

This commit is contained in:
Alvin-Zilverstand committed 2026-09-14 10:54:58 +02:00
1 parent 50ab1cd54a
commit a2800c3664
7 files changed
+677 -108

No files matched your search

Generated
+150 -16
View File
@@ -87,6 +87,7 @@ dependencies = [
name = "clipforge"
version = "0.1.0"
dependencies = [
"dirs",
"reqwest",
"rusqlite",
"serde",
@@ -136,6 +137,27 @@ version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
[[package]]
name = "dirs"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys",
]
[[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",
"windows-sys 0.48.0",
]
[[package]]
name = "displaydoc"
version = "0.2.7"
@@ -505,6 +527,15 @@ version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "libredox"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6480ccc157a1389bb2e4891b24751b0f798ba640d22386f23143fbcc89da195a"
dependencies = [
"libc",
]
[[package]]
name = "libsqlite3-sys"
version = "0.30.1"
@@ -609,6 +640,12 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "parking_lot"
version = "0.12.5"
@@ -682,7 +719,7 @@ dependencies = [
"rustc-hash",
"rustls",
"socket2",
"thiserror",
"thiserror 2.0.20",
"tokio",
"tracing",
"web-time",
@@ -704,7 +741,7 @@ dependencies = [
"rustls",
"rustls-pki-types",
"slab",
"thiserror",
"thiserror 2.0.20",
"tinyvec",
"tracing",
"web-time",
@@ -794,6 +831,17 @@ dependencies = [
"bitflags",
]
[[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 = "reqwest"
version = "0.12.28"
@@ -1073,13 +1121,33 @@ dependencies = [
"windows 0.57.0",
]
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
dependencies = [
"thiserror-impl",
"thiserror-impl 2.0.20",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
@@ -1277,7 +1345,7 @@ checksum = "ee144c215d8d31e94c1a599fbaf540ca82a7017e4f1786816b179f334fac751d"
dependencies = [
"log",
"num-integer",
"thiserror",
"thiserror 2.0.20",
"windows 0.62.2",
"windows-core 0.62.2",
]
@@ -1401,7 +1469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
dependencies = [
"windows-core 0.57.0",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@@ -1424,7 +1492,7 @@ checksum = "09046acbe9b6d039cde50e8c8178d95bb0f9b33ed7feccc4465dadc5404b31b4"
dependencies = [
"parking_lot",
"rayon",
"thiserror",
"thiserror 2.0.20",
"windows 0.62.2",
"windows-future",
]
@@ -1447,7 +1515,7 @@ dependencies = [
"windows-implement 0.57.0",
"windows-interface 0.57.0",
"windows-result 0.1.2",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@@ -1540,7 +1608,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
dependencies = [
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@@ -1561,13 +1629,22 @@ dependencies = [
"windows-link",
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@@ -1579,20 +1656,35 @@ dependencies = [
"windows-link",
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
@@ -1604,18 +1696,36 @@ dependencies = [
"windows-link",
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[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"
@@ -1628,24 +1738,48 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[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"
+1
View File
@@ -18,6 +18,7 @@ reqwest = { version = "0.12", default-features = false, features = ["blocking",
rusqlite = { version = "0.32", features = ["bundled"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
dirs = "5"
sysinfo = "0.31"
wasapi = "0.24.0"
windows-capture = "2.0.1"
+105 -6
View File
@@ -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
View File
@@ -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("."))
+1
View File
@@ -1,3 +1,4 @@
pub mod screenshot;
pub mod audio;
pub mod capture;
pub mod database;
+187
View File
@@ -0,0 +1,187 @@
use crate::capture::{CaptureConfig, CaptureError, CaptureMethod, CaptureSource, EncoderPreference};
use dirs;
use std::path::PathBuf;
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};
impl Default for ScreenshotCapture {
fn default() -> Self {
let output_dir = default_screenshot_dir();
Self {
executable: default_ffmpeg_executable(),
output_dir,
}
}
}
fn default_ffmpeg_executable() -> PathBuf {
let bundled = std::env::current_exe()
.ok()
.and_then(|path| path.parent().map(|parent| parent.to_path_buf()))
.map(|parent| parent.join("ffmpeg-x86_64-pc-windows-msvc.exe"));
if let Some(path) = bundled {
if path.exists() {
return path;
}
}
PathBuf::from("ffmpeg")
}
fn default_screenshot_dir() -> PathBuf {
let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
home.join("Pictures").join("ClipForge")
}
pub fn screenshot_dir() -> PathBuf {
default_screenshot_dir()
}
pub fn list_screenshots() -> Vec<PathBuf> {
let dir = default_screenshot_dir();
let Ok(entries) = std::fs::read_dir(&dir) else {
return Vec::new();
};
let mut screenshots = entries
.flatten()
.map(|entry| entry.path())
.filter(|path| {
path.is_file()
&& path
.extension()
.map(|ext| {
ext.eq_ignore_ascii_case("png")
|| ext.eq_ignore_ascii_case("jpg")
|| ext.eq_ignore_ascii_case("jpeg")
})
.unwrap_or(false)
})
.collect::<Vec<_>>();
screenshots.sort_by_key(|path| {
std::fs::metadata(path)
.and_then(|meta| meta.created())
.ok()
});
screenshots
}
pub fn take_screenshot() -> Result<PathBuf, CaptureError> {
let capture = ScreenshotCapture::default();
let config = CaptureConfig {
source: CaptureSource::Desktop,
method: CaptureMethod::DesktopDuplication,
width: 1920,
height: 1080,
fps: 30,
bitrate_kbps: 6000,
encoder: EncoderPreference::HardwareH264,
system_audio_enabled: false,
mic_enabled: false,
system_audio_device: None,
mic_device: None,
separate_audio_tracks: false,
};
capture.capture(&config)
}
#[derive(Debug, Clone)]
pub struct ScreenshotCapture {
executable: PathBuf,
output_dir: PathBuf,
}
impl ScreenshotCapture {
pub fn new(executable: impl Into<PathBuf>, output_dir: impl Into<PathBuf>) -> Self {
Self {
executable: executable.into(),
output_dir: output_dir.into(),
}
}
pub fn capture(&self, config: &CaptureConfig) -> Result<PathBuf, CaptureError> {
let now = SystemTime::now();
let timestamp = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_millis();
let output_path = self.output_dir.join(format!("screenshot-{}.png", timestamp));
std::fs::create_dir_all(&self.output_dir).map_err(|e| CaptureError::DeviceUnavailable(e.to_string()))?;
let size = format!("{}x{}", config.width, config.height);
let fps = config.fps.to_string();
let mut args = vec![
"-y".to_string(),
"-hide_banner".to_string(),
"-loglevel".to_string(),
"error".to_string(),
];
match config.method {
CaptureMethod::DesktopDuplication => {
args.extend([
"-f".to_string(),
"lavfi".to_string(),
"-i".to_string(),
format!("ddagrab=framerate={fps}:video_size={size},hwdownload,format=bgra"),
]);
}
CaptureMethod::GdiGrab => {
args.extend([
"-f".to_string(),
"gdigrab".to_string(),
"-framerate".to_string(),
fps,
"-video_size".to_string(),
size,
"-i".to_string(),
"desktop".to_string(),
]);
}
}
args.extend([
"-vframes".to_string(),
"1".to_string(),
"-update".to_string(),
"1".to_string(),
output_path.display().to_string(),
]);
let status = Command::new(&self.executable)
.args(&args)
.status()
.map_err(|e| CaptureError::DeviceUnavailable(e.to_string()))?;
if !status.success() {
return Err(CaptureError::DeviceUnavailable("FFmpeg screenshot failed".to_string()));
}
Ok(output_path)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::capture::{CaptureMethod, CaptureSource, EncoderPreference};
#[test]
fn test_screenshot_args() {
let _config = CaptureConfig {
source: CaptureSource::Desktop,
method: CaptureMethod::GdiGrab,
width: 1920,
height: 1080,
fps: 30,
bitrate_kbps: 6000,
encoder: EncoderPreference::HardwareH264,
system_audio_enabled: false,
mic_enabled: false,
system_audio_device: None,
mic_device: None,
separate_audio_tracks: false,
};
let capture = ScreenshotCapture::new("ffmpeg", "screenshots");
assert_eq!(capture.output_dir, PathBuf::from("screenshots"));
assert_eq!(capture.executable, PathBuf::from("ffmpeg"));
}
}
+169 -70
View File
@@ -8,7 +8,7 @@ type RecordingState =
| "Processing"
| "StorageLow";
type ClipSource = "Auto Event" | "Manual Hotkey" | "Bookmark" | "Imported";
type ClipSource = "Auto Event" | "Manual Hotkey" | "Bookmark" | "Imported" | "Screenshot";
type UploadState = "Local only" | "Uploaded" | "Failed" | "Queued";
type UploadProvider = "catbox" | "litterbox" | "custom_http" | "lustful";
@@ -133,6 +133,7 @@ type AppState = {
notice: string;
selectedClipId: string;
clips: Clip[];
screenshots: string[];
autoEvents: AutoEvent[];
hotkeyClipLast60s: string;
hotkeyClipLast30s: string;
@@ -156,38 +157,39 @@ declare global {
let tauriInvoke: (<T>(command: string, args?: Record<string, unknown>) => Promise<T>) | null = null;
const state: AppState = {
activeView: "Library",
recordingState: "WaitingForGame",
detectedGame: "Waiting for game",
replayBufferSeconds: 60,
systemAudioEnabled: true,
sessionRecording: false,
captureActive: false,
captureBackend: null,
capturePath: null,
ffmpegAvailable: false,
ffmpegPath: null,
systemAudioAvailable: false,
desktopDuplicationAvailable: false,
micEnabled: false,
micDevice: "",
audioDevices: [],
autoRecordEnabled: false,
autoUpload: false,
uploadProvider: "catbox",
catboxUserhash: "",
litterboxExpiryHours: 24,
customUploadEndpoint: "",
customUploadResponsePath: "url",
customUploadHeaders: "",
gsiConfigStatus: "",
libraryFilter: "all",
libraryQuery: "",
libraryViewMode: "grid",
notice: "",
selectedClipId: "",
clips: [],
autoEvents: [
activeView: "Library",
recordingState: "WaitingForGame",
detectedGame: "Waiting for game",
replayBufferSeconds: 60,
systemAudioEnabled: true,
sessionRecording: false,
captureActive: false,
captureBackend: null,
capturePath: null,
ffmpegAvailable: false,
ffmpegPath: null,
systemAudioAvailable: false,
desktopDuplicationAvailable: false,
micEnabled: false,
micDevice: "",
audioDevices: [],
autoRecordEnabled: false,
autoUpload: false,
uploadProvider: "catbox",
catboxUserhash: "",
litterboxExpiryHours: 24,
customUploadEndpoint: "",
customUploadResponsePath: "url",
customUploadHeaders: "",
gsiConfigStatus: "",
libraryFilter: "all",
libraryQuery: "",
libraryViewMode: "grid",
notice: "",
selectedClipId: "",
clips: [],
screenshots: [],
autoEvents: [
{ id: "cs2-kill", gameId: "counter-strike-2", eventType: "kill", game: "Counter-Strike 2", event: "Kill", enabled: true },
{ id: "cs2-death", gameId: "counter-strike-2", eventType: "death", game: "Counter-Strike 2", event: "Death", enabled: true },
{ id: "cs2-round", gameId: "counter-strike-2", eventType: "round_win", game: "Counter-Strike 2", event: "Round win", enabled: true },
@@ -269,6 +271,7 @@ function renderRecordingBar() {
</div>
<div class="status-pill">${statusText}</div>
<button class="icon-button" data-action="clip">Clip</button>
<button class="icon-button" data-action="screenshot">Screenshot</button>
<button class="record-button" data-action="toggle-record">${state.captureActive || state.sessionRecording ? "Stop" : "Record"}</button>
</header>
`;
@@ -291,41 +294,76 @@ function renderActiveView(selectedClip: Clip | undefined) {
}
function renderLibraryView(selectedClip: Clip | undefined) {
const clips = filteredClips();
const clips = filteredClips();
return `
<section class="content-grid">
<section class="library-panel">
<div class="section-heading">
<div>
<p class="eyebrow">Local library</p>
<h2>Recent Clips</h2>
</div>
<div class="segmented">
<button class="${state.libraryViewMode === "grid" ? "selected" : ""}" data-view-mode="grid">Grid</button>
<button class="${state.libraryViewMode === "list" ? "selected" : ""}" data-view-mode="list">List</button>
</div>
</div>
<input class="search-input" placeholder="Search clips, games, events, tags" value="${escapeHtml(state.libraryQuery)}" data-action="library-search" />
<div class="filters">
${[
["all", "All"],
["kills", "Kills"],
["wins", "Wins"],
["uploaded", "Uploaded"],
["failed", "Failed"],
]
.map(
([filter, label]) =>
`<button class="${state.libraryFilter === filter ? "selected" : ""}" data-library-filter="${filter}">${label}</button>`,
)
.join("")}
</div>
<div class="${state.libraryViewMode === "list" ? "clip-list" : "clip-grid"}">
${clips.length > 0 ? clips.map(renderClipCard).join("") : `<div class="empty-state">No matching clips</div>`}
</div>
</section>
<section class="screenshots-panel">
<div class="section-heading">
<div>
<p class="eyebrow">Screenshots</p>
<h2>Recent Screenshots</h2>
</div>
<div class="segmented">
<button class="${state.libraryViewMode === "grid" ? "selected" : ""}" data-view-mode="grid">Grid</button>
<button class="${state.libraryViewMode === "list" ? "selected" : ""}" data-view-mode="list">List</button>
</div>
</div>
<input class="search-input" placeholder="Search screenshots" value="${escapeHtml(state.libraryQuery)}" data-action="library-search" />
<div class="${state.libraryViewMode === "list" ? "screenshot-list" : "screenshot-grid"}">
${state.screenshots.length > 0 ? state.screenshots.map(renderScreenshotCard).join("") : `<div class="empty-state">No screenshots</div>`}
</div>
</section>
${renderClipDetails(selectedClip)}
</section>
`;
}
function renderScreenshotCard(path: string) {
const filename = path.split(/[/\\]/).pop() ?? path;
const url = convertFileSrc(path);
return `
<section class="content-grid">
<section class="library-panel">
<div class="section-heading">
<div>
<p class="eyebrow">Local library</p>
<h2>Recent Clips</h2>
</div>
<div class="segmented">
<button class="${state.libraryViewMode === "grid" ? "selected" : ""}" data-view-mode="grid">Grid</button>
<button class="${state.libraryViewMode === "list" ? "selected" : ""}" data-view-mode="list">List</button>
</div>
</div>
<input class="search-input" placeholder="Search clips, games, events, tags" value="${escapeHtml(state.libraryQuery)}" data-action="library-search" />
<div class="filters">
${[
["all", "All"],
["kills", "Kills"],
["wins", "Wins"],
["uploaded", "Uploaded"],
["failed", "Failed"],
]
.map(
([filter, label]) =>
`<button class="${state.libraryFilter === filter ? "selected" : ""}" data-library-filter="${filter}">${label}</button>`,
)
.join("")}
</div>
<div class="${state.libraryViewMode === "list" ? "clip-list" : "clip-grid"}">
${clips.length > 0 ? clips.map(renderClipCard).join("") : `<div class="empty-state">No matching clips</div>`}
</div>
</section>
${renderClipDetails(selectedClip)}
</section>
<article class="clip-card screenshot-card" data-screenshot-path="${escapeHtml(path)}">
<div class="thumb screenshot-thumb">
<img src="${url}" alt="${escapeHtml(filename)}" />
</div>
<h3>${escapeHtml(filename)}</h3>
<p class="muted">${escapeHtml(path)}</p>
<div class="actions">
<button data-action="reveal-screenshot" data-screenshot-path="${escapeHtml(path)}">Open</button>
</div>
</article>
`;
}
@@ -605,6 +643,10 @@ function bindEvents() {
void saveClip();
});
appRoot.querySelector<HTMLButtonElement>("[data-action='screenshot']")?.addEventListener("click", () => {
void takeScreenshot();
});
appRoot.querySelector<HTMLButtonElement>("[data-action='toggle-record']")?.addEventListener("click", () => {
void toggleRecording();
});
@@ -739,6 +781,15 @@ function bindEvents() {
void saveHotkeys();
});
appRoot.querySelectorAll<HTMLButtonElement>("[data-action='reveal-screenshot']").forEach((button) => {
button.addEventListener("click", () => {
const path = button.dataset.screenshotPath;
if (path) {
void revealScreenshot(path);
}
});
});
// Timeline drag handlers
const timelineTrack = appRoot.querySelector<HTMLElement>("[data-action='timeline-track']");
const handleStart = appRoot.querySelector<HTMLElement>("#timeline-handle-start");
@@ -773,7 +824,7 @@ function bindEvents() {
}
};
const startDrag = (handle: "start" | "end", clientX: number) => {
const startDrag = (handle: "start" | "end") => {
draggingHandle = handle;
document.body.style.cursor = "ew-resize";
document.body.style.userSelect = "none";
@@ -810,12 +861,12 @@ function bindEvents() {
handleStart.addEventListener("mousedown", (e) => {
e.stopPropagation();
startDrag("start", e.clientX);
startDrag("start");
});
handleEnd.addEventListener("mousedown", (e) => {
e.stopPropagation();
startDrag("end", e.clientX);
startDrag("end");
});
timelineTrack.addEventListener("mousedown", (e) => {
@@ -1066,6 +1117,15 @@ async function revealSelectedClip() {
}
}
async function revealScreenshot(path: string) {
try {
await window.__TAURI__?.core?.invoke?.("reveal_screenshot", { path });
} catch (error) {
console.error("Could not reveal screenshot", error);
showNotice(`Could not reveal screenshot: ${String(error)}`);
}
}
async function uploadSelectedClip() {
if (!tauriInvoke || !state.selectedClipId) {
return;
@@ -1333,6 +1393,44 @@ async function saveHotkeys() {
}
}
async function takeScreenshot() {
if (!tauriInvoke) {
return;
}
state.recordingState = "Processing";
render();
try {
await tauriInvoke("take_screenshot");
await refreshScreenshots();
showNotice("Screenshot saved");
render();
} catch (error) {
console.error("Could not take screenshot", error);
showNotice(`Could not take screenshot: ${String(error)}`);
render();
}
}
async function listScreenshots() {
if (!tauriInvoke) {
return [];
}
try {
return await tauriInvoke<string[]>("list_screenshots");
} catch (error) {
console.warn("Could not list screenshots", error);
return [];
}
}
async function refreshScreenshots() {
const screenshots = await listScreenshots();
state.screenshots = screenshots;
}
function filteredClips() {
const query = state.libraryQuery.trim().toLowerCase();
return state.clips.filter((clip) => {
@@ -1418,6 +1516,7 @@ async function loadDesktopBridge() {
const clips = await invoke<ClipDto[]>("list_clips");
state.clips = clips.map(clipFromDto);
state.selectedClipId = state.clips[0]?.id ?? "";
await refreshScreenshots();
render();
await refreshAudioDevices();
window.setInterval(() => {