Skip to content

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

fix(macos): save the project when ⌘Q ends the app (#437)

Michael Halsteadc495a8ea107c
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 834c6fb8..fda42286 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -264,6 +264,31 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
}
});
},
+ // The loop ending. On a Mac, ⌘Q and the Dock's Quit end it inside
+ // the system's terminate, past every close road, and `run` never
+ // returns: the project is saved here or not at all. Every other way
+ // out has released the session by now, so this does nothing there.
+ // https://github.com/jub0t/Concat/issues/437
+ || {
+ let terminating = std::cell::Cell::new(false);
+ Shell::with(|shell, _| {
+ let Ok(mut studio) = shell.studio.try_borrow_mut() else {
+ log::warn!("close: app terminating mid-edit; project not saved");
+ return;
+ };
+ if studio.session.is_some() {
+ log::info!("close: app terminating");
+ terminating.set(true);
+ if let Err(error) = studio.close_project() {
+ log::warn!("close: project could not be saved: {error}");
+ }
+ }
+ });
+ // What `run` returning would have done next, had it returned.
+ if terminating.get() {
+ stop_exports();
+ }
+ },
)?;
let host = match Host::start(gpu) {
diff --git a/src/crates/concat/src/platform.rs b/src/crates/concat/src/platform.rs
index c6c95402..80f19678 100644
--- a/src/crates/concat/src/platform.rs
+++ b/src/crates/concat/src/platform.rs
@@ -153,6 +153,8 @@ struct DropHandler {
/// 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()>,
+ /// The event loop is ending, by any road: see `start` in lib.rs.
+ on_exiting: 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.
@@ -208,6 +210,7 @@ impl DropHandler {
on_dropped: impl Fn(Vec<PathBuf>) + 'static,
on_pressed_away: impl Fn() + 'static,
on_focused: impl Fn() + 'static,
+ on_exiting: impl Fn() + 'static,
) -> Self {
Self {
pending: Vec::new(),
@@ -219,6 +222,7 @@ impl DropHandler {
cursor: None,
on_pressed_away: Box::new(on_pressed_away),
on_focused: Box::new(on_focused),
+ on_exiting: Box::new(on_exiting),
edges: cfg!(not(any(
target_os = "macos",
target_os = "windows",
@@ -356,6 +360,7 @@ impl CustomApplicationHandler for DropHandler {
fn exiting(&mut self, _event_loop: &ActiveEventLoop) -> EventResult {
// Before winit closes its display, which the listener reads.
self.wayland = None;
+ (self.on_exiting)();
EventResult::Propagate
}
}
@@ -424,6 +429,7 @@ pub fn select_backend(
on_files_dropped: impl Fn(Vec<PathBuf>) + 'static,
on_pressed_away: impl Fn() + 'static,
on_focused: impl Fn() + 'static,
+ on_exiting: impl Fn() + 'static,
) -> Result<Option<Gpu>, PlatformError> {
// The device the renderer and the monitor share. Taken first, because
// the backend is selected with it.
@@ -455,6 +461,7 @@ pub fn select_backend(
on_files_dropped,
on_pressed_away,
on_focused,
+ on_exiting,
));
selector = match &gpu {
Some(gpu) => selector.require_wgpu_30(gpu.configuration()),
@@ -667,6 +674,8 @@ pub fn select_backend(
// 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,
+ // Nor a desktop event loop whose end this hook watches.
+ _on_exiting: impl Fn() + 'static,
) -> Result<Option<Gpu>, PlatformError> {
let _ = on_files_dropped;
Ok(None)