Skip to content

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

feat(logs): the log is an activity trail of what the person did

Jareer472ecc3fe017
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 18ec0747..357454c4 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -1271,6 +1271,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
// tree is a binding away from it; it is also remembered.
app.on_settings_theme_changed({
move |dark| {
+ log::info!("settings: theme {}", if dark { "dark" } else { "light" });
Shell::with(|shell, app| {
app.global::<Theme>().set_dark(dark);
let mut studio = shell.studio.borrow_mut();
@@ -1283,6 +1284,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
// remembered under the name the global lists it by.
app.on_settings_accent_changed({
move |index| {
+ log::info!("settings: accent {index}");
Shell::with(|shell, app| {
let theme = app.global::<Theme>();
let names = theme.get_accent_names();
@@ -1545,6 +1547,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
}));
app.on_app_menu_selected({
move |action| {
+ log::info!("menu: {action}");
Shell::with(|shell, app| {
{
let mut state = shell.studio.borrow_mut();
diff --git a/src/crates/concat/src/panes/mod.rs b/src/crates/concat/src/panes/mod.rs
index 0e57ecc2..eb97755b 100644
--- a/src/crates/concat/src/panes/mod.rs
+++ b/src/crates/concat/src/panes/mod.rs
@@ -49,3 +49,129 @@ pub enum Msg {
/// To the timeline's view.
Timeline(timeline::TimelineMsg),
}
+
+/// What a message says in the log: the activity trail of what the person
+/// did - a sheet opened, a switch flipped, an import, an export begun and
+/// ended - for whoever is chasing a bug with the log in hand. None for
+/// the messages nobody wants: every preview frame, every pointer move,
+/// every progress tick. Typing is said by name and never quoted - a
+/// project's name, a server's token - and an outcome by its path or its
+/// count rather than its data.
+pub fn activity(msg: &Msg) -> Option<(log::Level, String)> {
+ use captions::CaptionsMsg;
+ use export::ExportMsg;
+ use log::Level::{Debug, Info};
+ use media_bin::MediaMsg;
+ use monitor::MonitorMsg;
+ use relink::RelinkMsg;
+ use settings::SettingsMsg;
+ use speech::SpeechMsg;
+ use timeline::TimelineMsg;
+
+ match msg {
+ Msg::Monitor(MonitorMsg::Frame(..) | MonitorMsg::Request | MonitorMsg::ScopePoll)
+ | Msg::Timeline(
+ TimelineMsg::Hovered(_)
+ | TimelineMsg::HoverEnded
+ | TimelineMsg::Scrolled(_)
+ | TimelineMsg::Resized(_),
+ )
+ | Msg::Export(ExportMsg::Progress { .. })
+ | Msg::Captions(CaptionsMsg::Progress(_))
+ | Msg::Speech(SpeechMsg::Progress(_))
+ | Msg::Settings(SettingsMsg::ModelProgress { .. } | SettingsMsg::InstallProgress { .. }) => {
+ return None;
+ }
+ Msg::Export(ExportMsg::Start) => return Some((Info, "export: started".to_owned())),
+ Msg::Export(ExportMsg::Finished(Ok(path))) => {
+ return Some((Info, format!("export: finished, {path}")));
+ }
+ Msg::Export(ExportMsg::Finished(Err(error))) => {
+ return Some((Info, format!("export: failed, {error}")));
+ }
+ Msg::Captions(CaptionsMsg::Begin) => return Some((Info, "captions: started".to_owned())),
+ Msg::Captions(CaptionsMsg::Finished(Ok(segments))) => {
+ return Some((
+ Info,
+ format!("captions: finished, {} segments", segments.len()),
+ ));
+ }
+ Msg::Captions(CaptionsMsg::Finished(Err(error))) => {
+ return Some((Info, format!("captions: failed, {error}")));
+ }
+ Msg::Speech(SpeechMsg::Begin) => return Some((Info, "speech: started".to_owned())),
+ Msg::Speech(SpeechMsg::Finished(result)) => {
+ return Some((
+ Info,
+ match result.as_ref() {
+ Ok(summary) => format!("speech: finished, {}", summary.path),
+ Err(error) => format!("speech: failed, {error}"),
+ },
+ ));
+ }
+ Msg::Media(MediaMsg::Import(paths)) => {
+ let names: Vec<String> = paths
+ .iter()
+ .map(|path| {
+ path.file_name()
+ .map(|name| name.to_string_lossy().into_owned())
+ .unwrap_or_default()
+ })
+ .collect();
+ return Some((
+ Info,
+ format!(
+ "import: {} file(s): {}",
+ paths.len(),
+ cap(&names.join(", "), 200)
+ ),
+ ));
+ }
+ Msg::Media(MediaMsg::Imported(results)) => {
+ let failed = results.iter().filter(|result| result.is_err()).count();
+ return Some((
+ Info,
+ format!("import: {} added, {failed} failed", results.len() - failed),
+ ));
+ }
+ Msg::Relink(RelinkMsg::Show(missing)) => {
+ return Some((Info, format!("relink: {} file(s) missing", missing.len())));
+ }
+ _ => {}
+ }
+ let text = format!("{msg:?}");
+ let (outer, body) = text
+ .split_once('(')
+ .map(|(outer, rest)| (outer, rest.strip_suffix(')').unwrap_or(rest)))
+ .unwrap_or((text.as_str(), ""));
+ let inner: String = body
+ .chars()
+ .take_while(|c| c.is_ascii_alphanumeric() || *c == '_')
+ .collect();
+ let outer = outer.to_ascii_lowercase();
+ // Typing: by name, never quoted. A name, a path, a token are nothing
+ // the log needs, and a keystroke each is not worth a line at Normal.
+ if inner.ends_with("Edited") || inner == "ServerTokenGenerated" {
+ return Some((Debug, format!("{outer}: {inner}")));
+ }
+ // The view moving under the person, and a sheet's own housekeeping,
+ // are for Debug; a choice made is for Normal.
+ let level = match inner.as_str() {
+ "Select" | "Band" | "Zoomed" | "ZoomIn" | "ZoomOut" | "ZoomToFit" | "PageChanged"
+ | "Restore" | "Reset" | "Opened" | "Closed" | "SnapToggled" | "MagneticToggled"
+ | "UpdatesFetched" => Debug,
+ _ => Info,
+ };
+ Some((level, format!("{outer}: {}", cap(body, 160))))
+}
+
+/// `text`, or its first `max` characters and an ellipsis.
+fn cap(text: &str, max: usize) -> String {
+ if text.chars().count() <= max {
+ text.to_owned()
+ } else {
+ let mut cut: String = text.chars().take(max).collect();
+ cut.push('…');
+ cut
+ }
+}
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index b44cfed6..63f4fde5 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -1297,6 +1297,20 @@ fn write_keyable(clip: &mut Clip, property: model::KeyProperty, value: f64, at:
}
}
+/// A command as the activity trail names it: its kind, and for a batch
+/// the kinds inside it. Never its contents - a patch carries a title's
+/// words - which is what keeps a line a line.
+fn command_name(command: &Command) -> String {
+ if let Command::Batch { commands } = command {
+ let inside: Vec<String> = commands.iter().map(command_name).collect();
+ return format!("Batch[{}]", inside.join(", "));
+ }
+ let text = format!("{command:?}");
+ text.chars()
+ .take_while(|c| c.is_ascii_alphanumeric())
+ .collect()
+}
+
/// The commands that turn `before` into `after`, clip `id` as the echo
/// left it against the document's: a transform, a cutout, a speed, the
/// keys, and one patch for everything else that differs. Empty when
@@ -2109,6 +2123,7 @@ impl Studio {
/// A refusal becomes a notice; the echo, if any, is dropped either way,
/// because the session's project is the truth again.
pub fn apply(&mut self, command: Command) -> Option<String> {
+ log::info!("edit: {}", command_name(&command));
self.flush_commit();
self.echo = None;
// Anything but an inspector commit ends the coalescing window; the
@@ -2137,6 +2152,9 @@ impl Studio {
/// bookkeeping, but the editor folds it into the gesture's undo step
/// and the coalescing window stays open for the next move.
fn apply_within(&mut self, gesture: &str, command: Command) {
+ // A knob's gesture, folded into one step; said at Debug, since a
+ // dial turned is many of these.
+ log::debug!("edit: {} ({gesture})", command_name(&command));
self.echo = None;
let Some(session) = self.session.as_mut() else {
return;
@@ -2457,6 +2475,7 @@ impl Studio {
// pointer that happens to be over the lanes must not stay on it.
self.end_hover();
self.playing = true;
+ log::debug!("playback: playing from {:.3}s", self.playhead);
self.host.playback.play(f64::from(self.playhead));
// The clock is the audio device's; this follows it at 30 Hz and
// asks the monitor for the frame under it each time.
@@ -2502,6 +2521,9 @@ impl Studio {
}
pub fn pause(&mut self) {
+ if self.playing {
+ log::debug!("playback: paused at {:.3}s", self.playhead);
+ }
self.playing = false;
self.transport.stop();
self.host.playback.pause();
@@ -4342,6 +4364,7 @@ impl Studio {
/// so it is there next session and for every project, and registered
/// on this project; the selected title is set in the first of them.
pub fn import_fonts(&mut self, paths: Vec<std::path::PathBuf>) {
+ log::info!("fonts: importing {} file(s)", paths.len());
let mut first: Option<String> = None;
for path in paths {
let families = concat_text::families_in(&path);
@@ -6382,6 +6405,7 @@ impl Studio {
/// Opens a project as the session and leaves the launch screen, or
/// says why it could not.
pub fn open_project(&mut self, info: ProjectInfo) -> Result<(), String> {
+ log::info!("project: opening {}", info.path);
if self
.host
.open_projects
@@ -6506,6 +6530,7 @@ impl Studio {
/// Saves, then closes the session and returns to the launch screen.
pub fn close_project(&mut self) {
+ log::info!("project: closing {}", self.project_name);
// Words still being typed land in the save, not on the floor.
self.flush_commit();
self.pause();
@@ -6589,6 +6614,10 @@ impl Studio {
/// rest of the window without borrowing itself twice; a pane never
/// reads its own slot on the studio.
pub fn handle(&mut self, msg: crate::panes::Msg) {
+ // The activity trail: what the person did, for the log.
+ if let Some((level, line)) = crate::panes::activity(&msg) {
+ log::log!(level, "{line}");
+ }
match msg {
crate::panes::Msg::Export(msg) => {
let mut pane = std::mem::take(&mut self.export);
@@ -8949,6 +8978,7 @@ impl Studio {
/// A row of a bin card's menu, for the media it was opened on.
pub fn media_action(&mut self, id: &str, action: &str) {
+ log::info!("media menu: {action} on {id}");
let Some(row) = self.media.row_of(id) else {
return;
};
@@ -9375,6 +9405,7 @@ impl Studio {
/// menu's own handler in lib.rs, so a key and the row that advertises
/// it are one thing.
pub fn shortcut(&mut self, action: &str) {
+ log::info!("shortcut: {action}");
match action {
"split" => {
let at = self.playhead;
@@ -9445,6 +9476,7 @@ impl Studio {
/// keyboard's chords both land here, so a shortcut and the row that
/// advertises it cannot disagree.
pub fn clip_action(&mut self, id: &str, action: &str) {
+ log::info!("clip menu: {action} on {id}");
let Some(clip) = self.clip(id).cloned() else {
return;
};