feat: move default clip library to ~/Documents/ClipForge with legacy migration, enable release notes
Build Windows Release / Windows installer (push) Canceled after 0s

This commit is contained in:
Alvin-Zilverstand committed 2026-09-14 13:14:17 +02:00
1 parent 7a4ba815fe
commit 355a798c34
5 files changed
+182 -5

No files matched your search

+1
View File
@@ -124,6 +124,7 @@ jobs:
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
generate_release_notes: true
files: |
src-tauri/target/release/bundle/msi/*.msi
src-tauri/target/release/bundle/nsis/*.exe
+1
View File
@@ -51,6 +51,7 @@
- A GitHub Actions release workflow publishes MSI/NSIS assets on tag push; auto-update will pick up newer releases automatically once the repo ships a tag newer than the running app version.
- The Settings screen shows the current version, checks for updates, and offers a Download & install button when a newer release exists.
- First-run onboarding wizard walks new installs through privacy/audio, capture-source, storage, and hotkey setup before showing the main app; it uses the defaults already saved in `settings.json` so existing users are unaffected.
- The default clip library root is `~/Documents/ClipForge` (rather than the process working directory), and a first-run migration moves any legacy `clipforge-library` folder found in the CWD into the new location while rewriting stored clip paths in the SQLite database.
- Vite TypeScript UI builds and has interactive Library, Recording, Auto Clip, Uploads, and Settings views.
- Library search, event/upload filters, and grid/list switching are functional in the UI.
- User-visible notices are shown for major actions and failures instead of relying only on console output.
+11 -5
View File
@@ -27,13 +27,12 @@ use clipforge::native_audio::{
use clipforge::native_wgc::NativeWgcReplayCaptureBackend;
use clipforge::recorder::{RecorderAction, RecorderService};
use clipforge::settings::{load_or_create_settings, save_settings, AppSettings};
use clipforge::storage::{clip_path, is_inside_root, LibraryPaths};
use clipforge::storage::{clip_path, is_inside_root, resolve_library_root, LibraryPaths};
use clipforge::updater::{self, UpdateCheck};
use clipforge::upload::{
CatboxUploader, CustomHttpUploader, LitterboxUploader, UploadMetadata, UploadResult, Uploader,
};
use serde::Serialize;
use std::env;
use std::fs;
use std::io::{Read, Write};
use std::net::TcpListener;
@@ -1645,15 +1644,22 @@ fn handle_screenshot() -> Result<(), String> {
}
fn create_runtime() -> Result<(PathBuf, RecorderService, ClipDatabase), String> {
let root = env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join("clipforge-library");
let resolution = resolve_library_root()
.map_err(|error| format!("Could not resolve library root: {error}"))?;
let root = resolution.root;
let settings = load_or_create_settings(&root)
.map_err(|error| format!("Could not load settings: {error}"))?;
let paths = LibraryPaths::new(&root);
paths.ensure().map_err(|error| error.to_string())?;
let database = ClipDatabase::open(root.join("library.sqlite"))
.map_err(|error| format!("Could not open clip database: {error}"))?;
if let Some(legacy) = resolution.migrated_from {
let old_prefix = legacy.display().to_string();
let new_prefix = root.display().to_string();
database
.rewrite_path_prefix(&old_prefix, &new_prefix)
.map_err(|error| format!("Could not remap migrated clip paths: {error}"))?;
}
let mut recorder = RecorderService::new(settings, paths);
for clip in database
.load_clips()
+51
View File
@@ -172,6 +172,16 @@ impl ClipDatabase {
Ok(())
}
pub fn rewrite_path_prefix(&self, old_prefix: &str, new_prefix: &str) -> rusqlite::Result<usize> {
self.connection.execute(
"UPDATE clips SET
path = REPLACE(path, ?1, ?2),
thumbnail_path = REPLACE(thumbnail_path, ?1, ?2)
WHERE path LIKE ?1 || '%' OR thumbnail_path LIKE ?1 || '%'",
params![old_prefix, new_prefix],
)
}
pub fn insert_upload_history(
&self,
clip_id: &str,
@@ -430,4 +440,45 @@ mod tests {
assert!(database.load_clips().expect("load empty").is_empty());
let _ = std::fs::remove_file(db_path);
}
#[test]
fn rewrites_stored_paths_to_new_library_root() {
let db_path = temp_database_path("rewrite");
let database = ClipDatabase::open(&db_path).expect("database");
let clip = Clip {
id: "clip-1".to_string(),
title: None,
session_id: "session-1".to_string(),
game_id: "counter-strike-2".to_string(),
path: PathBuf::from("C:/Old/ClipForge/clips/counter-strike-2/2026-09/clip-1.mp4"),
thumbnail_path: Some(PathBuf::from(
"C:/Old/ClipForge/thumbs/clip-1.jpg",
)),
created_at: UNIX_EPOCH + Duration::from_secs(10),
duration: Duration::from_secs(60),
source: ClipSource::ManualHotkey,
event_type: None,
tags: Vec::new(),
upload_url: None,
upload_provider: None,
};
database.upsert_clip(&clip).expect("upsert");
let updated = database
.rewrite_path_prefix("C:/Old/ClipForge", "C:/Users/alvin/Documents/ClipForge")
.expect("rewrite");
assert_eq!(updated, 1);
let loaded = database.load_clips().expect("load");
assert_eq!(loaded.len(), 1);
assert_eq!(
loaded[0].path,
PathBuf::from("C:/Users/alvin/Documents/ClipForge/clips/counter-strike-2/2026-09/clip-1.mp4")
);
assert_eq!(
loaded[0].thumbnail_path.as_deref(),
Some(Path::new("C:/Users/alvin/Documents/ClipForge/thumbs/clip-1.jpg"))
);
let _ = std::fs::remove_file(db_path);
}
}
+118
View File
@@ -236,6 +236,82 @@ fn collect_files(root: &Path) -> io::Result<Vec<FileFact>> {
Ok(files)
}
pub fn default_library_root() -> PathBuf {
dirs::document_dir()
.map(|docs| docs.join("ClipForge"))
.or_else(|| dirs::home_dir().map(|home| home.join("ClipForge")))
.unwrap_or_else(|| {
std::env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join("clipforge-library")
})
}
#[derive(Debug, Clone)]
pub struct LibraryResolution {
pub root: PathBuf,
pub migrated_from: Option<PathBuf>,
}
pub fn resolve_library_root() -> io::Result<LibraryResolution> {
let target = default_library_root();
let legacy = legacy_library_in_working_dir();
if let Some(legacy) = legacy {
if legacy != target && !library_has_content(&target) {
migrate_library(&legacy, &target)?;
return Ok(LibraryResolution {
root: target,
migrated_from: Some(legacy),
});
}
}
Ok(LibraryResolution {
root: target,
migrated_from: None,
})
}
fn legacy_library_in_working_dir() -> Option<PathBuf> {
let cwd = std::env::current_dir().ok()?;
let candidate = cwd.join("clipforge-library");
candidate.is_dir().then_some(candidate)
}
fn library_has_content(path: &Path) -> bool {
if path.join("settings.json").exists() || path.join("library.sqlite").exists() {
return true;
}
if let Ok(mut entries) = fs::read_dir(path) {
return entries.next().is_some();
}
false
}
fn migrate_library(from: &Path, to: &Path) -> io::Result<()> {
if let Some(parent) = to.parent() {
fs::create_dir_all(parent)?;
}
if fs::rename(from, to).is_ok() {
return Ok(());
}
copy_dir_all(from, to)?;
fs::remove_dir_all(from)
}
fn copy_dir_all(from: &Path, to: &Path) -> io::Result<()> {
fs::create_dir_all(to)?;
for entry in fs::read_dir(from)? {
let entry = entry?;
let target = to.join(entry.file_name());
if entry.file_type()?.is_dir() {
copy_dir_all(&entry.path(), &target)?;
} else {
fs::copy(entry.path(), &target)?;
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -292,4 +368,46 @@ mod tests {
};
assert!(path_is_on_mount(root, mount));
}
#[test]
fn default_library_root_prefers_documents_dir() {
let root = default_library_root();
let docs = dirs::document_dir().expect("documents dir");
let expected = docs.join("ClipForge");
assert_eq!(root, expected);
}
#[test]
fn migrates_legacy_library_to_target() {
let temp_ns = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos();
let from = std::env::temp_dir().join(format!("clipforge-from-{temp_ns}"));
let to = std::env::temp_dir().join(format!("clipforge-to-{temp_ns}"));
fs::create_dir_all(&from).expect("from");
fs::write(from.join("settings.json"), "{}").expect("settings");
fs::create_dir_all(to.parent().unwrap()).expect("parent");
assert!(from.exists());
assert!(!to.exists());
migrate_library(&from, &to).expect("migrate");
assert!(!from.exists());
assert!(to.join("settings.json").exists());
assert!(library_has_content(&to));
let _ = fs::remove_dir_all(to);
}
#[test]
fn library_has_content_reports_empty_directory() {
let temp_ns = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos();
let dir = std::env::temp_dir().join(format!("clipforge-hascontent-{temp_ns}"));
fs::create_dir_all(&dir).expect("dir");
assert!(!library_has_content(&dir));
let _ = fs::remove_dir_all(dir);
}
}