Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(studio): a file that goes missing while a project is open is noticed when the window comes back - the relink dialog opens on it, a dismissal keeps it quiet until the file returns and is lost again, and a dialog about a project that closed does not linger (#409)

PanSHIgg87fd67813ef2
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 03c7bb95..97936af7 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -252,6 +252,17 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
// See the handler in platform.rs for why this is a raw event and
// not a TouchArea.
|| Shell::with(|_, app| app.invoke_blur()),
+ // Back at the front, after Explorer or Finder: a file moved out
+ // from under an open project is noticed here, and the relink
+ // dialog opens on it. See `Studio::check_missing_media`.
+ || {
+ Shell::with(|shell, app| {
+ let changed = shell.studio.borrow_mut().check_missing_media();
+ if changed {
+ shell.studio.borrow().publish(&app, &shell.models);
+ }
+ });
+ },
)?;
let host = match Host::start(gpu) {
diff --git a/src/crates/concat/src/panes/mod.rs b/src/crates/concat/src/panes/mod.rs
index dfc41e13..8c0a1e6b 100644
--- a/src/crates/concat/src/panes/mod.rs
+++ b/src/crates/concat/src/panes/mod.rs
@@ -190,7 +190,10 @@ pub fn activity(msg: &Msg) -> Option<Activity> {
let level = match inner.as_str() {
"Select" | "Band" | "Zoomed" | "ZoomIn" | "ZoomOut" | "ZoomToFit" | "PageChanged"
| "Restore" | "Reset" | "Opened" | "Closed" | "SnapToggled" | "MagneticToggled"
- | "UpdatesFetched" => Debug,
+ | "UpdatesFetched"
+ // Every return to the front asks what is missing; only what it
+ // finds - the dialog opening - is worth a line of its own.
+ | "Recheck" => Debug,
_ => Info,
};
Some(Activity {
diff --git a/src/crates/concat/src/panes/relink.rs b/src/crates/concat/src/panes/relink.rs
index c9c843dd..76d9cb3b 100644
--- a/src/crates/concat/src/panes/relink.rs
+++ b/src/crates/concat/src/panes/relink.rs
@@ -4,7 +4,7 @@
//! The missing media dialog: what a project cannot find, and one folder
//! to look for it in.
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use concat_project::Command;
@@ -21,6 +21,9 @@ use crate::ui::{MissingMediaItem, RelinkData};
pub enum RelinkMsg {
/// A project opened with files it cannot find.
Show(Vec<MissingMedia>),
+ /// The window came back to the front: what the project cannot find
+ /// now, which may have changed while it was away.
+ Recheck(Vec<MissingMedia>),
/// Pick a folder and look for every missing file inside it.
RelinkAll,
/// The folder the picker answered with: look inside it.
@@ -33,6 +36,9 @@ pub enum RelinkMsg {
pub struct RelinkPane {
pub open: bool,
pub items: Vec<MissingMedia>,
+ /// The media whose dialog the user closed: no dialog mentions them
+ /// again until they come back and go missing anew.
+ dismissed: HashSet<String>,
}
impl RelinkPane {
@@ -40,10 +46,11 @@ impl RelinkPane {
/// this runs the studio's copy of the pane is a blank it must not read.
pub fn update(&mut self, msg: RelinkMsg, studio: &mut Studio) {
match msg {
- RelinkMsg::Show(items) => {
- self.open = true;
- self.items = items;
- }
+ RelinkMsg::Show(items) => self.show(items),
+ // A return to the front: forget media that is back (losing it
+ // again will be news), keep the silence the user asked for on
+ // the rest, and open on whatever missing is new to them.
+ RelinkMsg::Recheck(missing) => self.recheck(missing),
// The picker runs with the studio unborrowed and answers as a
// message of its own; see `host::after_dialog`.
RelinkMsg::RelinkAll => {
@@ -56,10 +63,40 @@ impl RelinkPane {
);
}
RelinkMsg::RelinkIn(folder) => self.relink_in(studio, folder),
- RelinkMsg::Dismiss => self.open = false,
+ RelinkMsg::Dismiss => self.dismiss(),
}
}
+ /// Opens the dialog on a project's missing files, as opening a project
+ /// does. A dismissal is about the project it was made in, so one from
+ /// an earlier project is forgotten here.
+ fn show(&mut self, items: Vec<MissingMedia>) {
+ self.open = true;
+ self.items = items;
+ self.dismissed.clear();
+ }
+
+ /// Applies a check made while the project is open - on a return to the
+ /// front - to the dialog: media that is back is forgotten, dismissed
+ /// media stays quiet, and the rest is the dialog's list.
+ fn recheck(&mut self, missing: Vec<MissingMedia>) {
+ let still: HashSet<&str> = missing.iter().map(|item| item.id.as_str()).collect();
+ self.dismissed.retain(|id| still.contains(id.as_str()));
+ self.items = missing
+ .into_iter()
+ .filter(|item| !self.dismissed.contains(&item.id))
+ .collect();
+ self.open = !self.items.is_empty();
+ }
+
+ /// Closes the dialog, and keeps it closed for what it was listing
+ /// until those files are back and go missing again.
+ fn dismiss(&mut self) {
+ self.dismissed
+ .extend(self.items.iter().map(|item| item.id.clone()));
+ self.open = false;
+ }
+
/// Relinks missing media by searching `folder` (recursively) for files
/// whose basename matches: each missing item looks for its own filename
/// inside it. Successful relinks go through the editor as
@@ -126,8 +163,12 @@ impl RelinkPane {
}
// Re-check what is still missing: the dialog updates to the
- // remainder (often empty, in which case it closes).
+ // remainder (often empty, in which case it closes). A dismissal
+ // only outlives its file while that file is missing - one that is
+ // relinked here and lost again is news.
let remaining = studio.project().missing_media();
+ let still: HashSet<&str> = remaining.iter().map(|item| item.id.as_str()).collect();
+ self.dismissed.retain(|id| still.contains(id.as_str()));
if remaining.is_empty() {
self.open = false;
self.items.clear();
@@ -163,3 +204,86 @@ impl RelinkPane {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn missing(id: &str, path: &str) -> MissingMedia {
+ MissingMedia {
+ id: id.to_owned(),
+ name: format!("{id}.mp4"),
+ path: path.to_owned(),
+ }
+ }
+
+ #[test]
+ fn a_recheck_opens_the_dialog_on_what_is_missing() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ assert!(pane.open);
+ assert_eq!(pane.items.len(), 1);
+ assert_eq!(pane.items[0].id, "m1");
+ }
+
+ #[test]
+ fn a_dismissed_file_stays_quiet_while_it_is_missing() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ pane.dismiss();
+ assert!(!pane.open, "dismissing closes the dialog");
+
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ assert!(!pane.open, "and the same missing file does not reopen it");
+ assert!(pane.items.is_empty());
+ }
+
+ #[test]
+ fn a_file_that_comes_back_and_goes_missing_again_is_news() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ pane.dismiss();
+ // Back on disk: the check finds nothing and forgets the dismissal.
+ pane.recheck(Vec::new());
+ assert!(!pane.open);
+ // Gone a second time: the dialog should be back.
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ assert!(pane.open);
+ assert_eq!(pane.items.len(), 1);
+ }
+
+ #[test]
+ fn a_new_missing_file_opens_the_dialog_beside_a_dismissed_one() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ pane.dismiss();
+ pane.recheck(vec![
+ missing("m1", "/gone/a.mp4"),
+ missing("m2", "/gone/b.mp4"),
+ ]);
+ assert!(pane.open);
+ assert_eq!(pane.items.len(), 1);
+ assert_eq!(pane.items[0].id, "m2", "only the news is listed");
+ }
+
+ #[test]
+ fn a_recheck_that_finds_nothing_closes_the_dialog() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ pane.recheck(Vec::new());
+ assert!(!pane.open);
+ assert!(pane.items.is_empty());
+ }
+
+ #[test]
+ fn opening_a_project_forgets_an_earlier_projects_dismissals() {
+ let mut pane = RelinkPane::default();
+ pane.recheck(vec![missing("m1", "/gone/a.mp4")]);
+ pane.dismiss();
+ // Another project opens with the same id missing: Show is the
+ // project-open path, and it starts the dialog afresh.
+ pane.show(vec![missing("m1", "/gone/a.mp4")]);
+ assert!(pane.open);
+ assert_eq!(pane.items.len(), 1);
+ }
+}
diff --git a/src/crates/concat/src/platform.rs b/src/crates/concat/src/platform.rs
index dd1cfe17..7176b74c 100644
--- a/src/crates/concat/src/platform.rs
+++ b/src/crates/concat/src/platform.rs
@@ -141,6 +141,10 @@ struct DropHandler {
/// says where it moved, and a press says only that it happened.
cursor: Option<(f32, f32)>,
on_pressed_away: Box<dyn Fn()>,
+ /// The window came back to the front: the moment a person returns from
+ /// moving a file, and the one where a file that went missing can be
+ /// noticed. See `Studio::check_missing_media`.
+ on_focused: Box<dyn Fn()>,
/// Whether this window draws its own resize edges: Linux, undecorated.
edges: bool,
/// The edge the pointer is on, while it is on one.
@@ -195,6 +199,7 @@ impl DropHandler {
fn new(
on_dropped: impl Fn(Vec<PathBuf>) + 'static,
on_pressed_away: impl Fn() + 'static,
+ on_focused: impl Fn() + 'static,
) -> Self {
Self {
pending: Vec::new(),
@@ -205,6 +210,7 @@ impl DropHandler {
fitted: false,
cursor: None,
on_pressed_away: Box::new(on_pressed_away),
+ on_focused: Box::new(on_focused),
edges: cfg!(not(any(
target_os = "macos",
target_os = "windows",
@@ -267,6 +273,10 @@ impl CustomApplicationHandler for DropHandler {
match event {
WindowEvent::ScaleFactorChanged { .. } => reapply_ui_scale(),
WindowEvent::DroppedFile(path) => self.pending.push(path.clone()),
+ // Back at the front, after Explorer or the file manager: what a
+ // dropped file is to an import, a return is to a look for one
+ // that went away while the window was open.
+ WindowEvent::Focused(true) => (self.on_focused)(),
WindowEvent::CursorMoved { position, .. } => {
let scale = slint_window
.map(|window| f64::from(window.scale_factor()))
@@ -399,11 +409,13 @@ pub fn phone() -> bool {
/// a file manager - batched into one call per drag. It is taken here,
/// before the window exists, because the backend - and the hook into its
/// event loop that OS drops arrive through - has to be selected before
-/// anything is built on top of it; see [`DropHandler`].
+/// anything is built on top of it; see [`DropHandler`]. `on_focused` fires
+/// the same way each time the window is brought back to the front.
#[cfg(not(target_os = "android"))]
pub fn select_backend(
on_files_dropped: impl Fn(Vec<PathBuf>) + 'static,
on_pressed_away: impl Fn() + 'static,
+ on_focused: impl Fn() + 'static,
) -> Result<Option<Gpu>, PlatformError> {
// The device the renderer and the monitor share. Taken first, because
// the backend is selected with it.
@@ -431,7 +443,11 @@ pub fn select_backend(
let mut selector = slint::BackendSelector::new()
.backend_name("winit".into())
- .with_winit_custom_application_handler(DropHandler::new(on_files_dropped, on_pressed_away));
+ .with_winit_custom_application_handler(DropHandler::new(
+ on_files_dropped,
+ on_pressed_away,
+ on_focused,
+ ));
selector = match &gpu {
Some(gpu) => selector.require_wgpu_30(gpu.configuration()),
None => {
@@ -640,6 +656,9 @@ pub fn select_backend(
// Android has no pointer to press away with; the screen's own keyboard
// dismisses, and the field goes with it.
_on_pressed_away: impl Fn() + 'static,
+ // Nor a window that loses and regains the front: the activity owns the
+ // screen, and a file comes back through the picker.
+ _on_focused: impl Fn() + 'static,
) -> Result<Option<Gpu>, PlatformError> {
let _ = on_files_dropped;
Ok(None)
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index f5653c0f..ef7f520e 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -8151,6 +8151,9 @@ impl Studio {
log::info!("{swept} stale proxies swept from {}", project_dir.display());
}
self.session = Some(session);
+ // The relink dialog belongs to the project that opened it;
+ // this project's own check follows below.
+ self.relink = Default::default();
crate::host::next_project_epoch();
self.forget_art();
self.art_failed.clear();
@@ -8256,6 +8259,46 @@ impl Studio {
}
}
+ /// Looks for media the open project can no longer find, and opens the
+ /// relink dialog on whatever is missing that the user has not already
+ /// dismissed.
+ ///
+ /// Runs when the window is brought back to the front - the moment a
+ /// person returns from moving a file - since the check
+ /// [`Studio::open_project`] makes cannot see a file that went away
+ /// afterwards: the bin and the timeline keep the item, the preview
+ /// only fails to read it, and nothing else would say why.
+ ///
+ /// Returns whether the dialog changed, so the caller publishes only
+ /// when there is something new to show.
+ pub fn check_missing_media(&mut self) -> bool {
+ if self.on_start || self.session.is_none() {
+ return false;
+ }
+ let missing = self
+ .session
+ .as_ref()
+ .map(|session| session.project().missing_media())
+ .unwrap_or_default();
+ let before: Vec<String> = self
+ .relink
+ .items
+ .iter()
+ .map(|item| item.id.clone())
+ .collect();
+ let was_open = self.relink.open;
+ self.handle(crate::panes::Msg::Relink(
+ crate::panes::relink::RelinkMsg::Recheck(missing),
+ ));
+ let after: Vec<String> = self
+ .relink
+ .items
+ .iter()
+ .map(|item| item.id.clone())
+ .collect();
+ self.relink.open != was_open || before != after
+ }
+
/// Clears all cached artwork and waveforms from the current project.
pub fn clear_project_cache(&mut self) {
let Some(path) = self
@@ -8349,6 +8392,9 @@ impl Studio {
self.captions.pace = Default::default();
self.speech.running = false;
self.speech.pace = Default::default();
+ // No dialog about files the project that just closed could not
+ // find stays up over the launch screen.
+ self.relink = Default::default();
self.source = None;
// A take running as the project closes stops, keeping its file;
// the next project's speakers are not left silent.