Skip to content

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

feat(ui): a Remote page in Settings serves the API while the window is open

Jareer26bf5901c6fa
diff --git a/src/crates/concat/Cargo.toml b/src/crates/concat/Cargo.toml
index 0770755f..ab1b3e56 100644
--- a/src/crates/concat/Cargo.toml
+++ b/src/crates/concat/Cargo.toml
@@ -97,6 +97,10 @@ concat-project.workspace = true
concat-export.workspace = true
concat-host = { workspace = true, features = ["gpu"] }
concat-speech.workspace = true
+# The Settings sheet's Remote page: the Concat API on a socket while the
+# window is open. JSON-RPC only; the gRPC feature stays with concat-cli.
+concat-server.workspace = true
+concat-api.workspace = true
# The effect catalogue: the inspector's shelves and each link's knobs.
concat-effects.workspace = true
# The cutout's mapping from a stage press to a source fraction; the model
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index 8a1131eb..e03f705b 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -4,6 +4,7 @@
},
"1 stroke": "1 stroke",
"10-bit colour": "10-bit colour",
+ "127.0.0.1 is this machine only. Any other address is reachable from the network, needs a token, and is still not encrypted.": "127.0.0.1 is this machine only. Any other address is reachable from the network, needs a token, and is still not encrypted.",
"A brighter, lighter, closer voice. Pitch at 0 follows the amount.": "A brighter, lighter, closer voice. Pitch at 0 follows the amount.",
"A concert hall: long, even reflections.": "A concert hall: long, even reflections.",
"A film curve with a real toe and shoulder, warm halation around the lights, and grain that moves. Print stock, not a filter.": "A film curve with a real toe and shoulder, warm halation around the lights, and grain that moves. Print stock, not a filter.",
@@ -31,6 +32,7 @@
"Add selected to timeline": "Add selected to timeline",
"Add track": "Add track",
"Added {0} captions": "Added {0} captions",
+ "Address": "Address",
"Adjust": "Adjust",
"Age": "Age",
"Air and presence: a lift above six kilohertz.": "Air and presence: a lift above six kilohertz.",
@@ -339,6 +341,7 @@
"Lights": "Lights",
"Line height": "Line height",
"Lines": "Lines",
+ "Listening on {0} · {1} connected": "Listening on {0} · {1} connected",
"Lo-fi": "Lo-fi",
"Loading the model": "Loading the model",
"Location": "Location",
@@ -394,6 +397,7 @@
"Natural": "Natural",
"Neon": "Neon",
"New project": "New project",
+ "New token": "New token",
"Next frame": "Next frame",
"Night": "Night",
"Night city: the lights and signs made vivid and blooming, blacks kept deep and cool, faces left clean. Made for the strip.": "Night city: the lights and signs made vivid and blooming, blacks kept deep and cool, faces left clean. Made for the strip.",
@@ -419,6 +423,7 @@
"Nothing under the playhead": "Nothing under the playhead",
"Nothing was said in that clip": "Nothing was said in that clip",
"Object": "Object",
+ "Off": "Off",
"off": "off",
"Off, a click on the ruler past the last clip lands the playhead there, and a clip placed at the playhead goes with it. On, the playhead never leaves the content.": "Off, a click on the ruler past the last clip lands the playhead there, and a clip placed at the playhead goes with it. On, the playhead never leaves the content.",
"One repeat, fading.": "One repeat, fading.",
@@ -489,6 +494,8 @@
"Reduce noise": "Reduce noise",
"Regular": "Regular",
"Relink All…": "Relink All…",
+ "Remote": "Remote",
+ "Remote control": "Remote control",
"Remove": "Remove",
"Remove background": "Remove background",
"Remove background: {0}": "Remove background: {0}",
@@ -531,6 +538,8 @@
"Semitones": "Semitones",
"Sepia": "Sepia",
"Sepia that keeps its contrast and its highlights, so it reads as old film rather than a brown wash.": "Sepia that keeps its contrast and its highlights, so it reads as old film rather than a brown wash.",
+ "Serve the API": "Serve the API",
+ "Serves the Concat API while the window is open, so a script or another program can create, edit and export projects of its own. Anything that connects can read and write files as you can.": "Serves the Concat API while the window is open, so a script or another program can create, edit and export projects of its own. Anything that connects can read and write files as you can.",
"Settings": "Settings",
"Settings…": "Settings…",
"Shadows": "Shadows",
@@ -633,6 +642,7 @@
"Title": "Title",
"Titles": "Titles",
"today": "today",
+ "Token": "Token",
"Tone": "Tone",
"Toolchain": "Toolchain",
"Top": "Top",
@@ -671,6 +681,7 @@
"Warmth": "Warmth",
"Water": "Water",
"Water and sky turned aquamarine and brightened, sand and skin left warm and clean. The beach-day look creators reach for first.": "Water and sky turned aquamarine and brightened, sand and skin left warm and clean. The beach-day look creators reach for first.",
+ "What a connection must present before its first call. Empty on 127.0.0.1 lets anything on this machine in.": "What a connection must present before its first call. Empty on 127.0.0.1 lets anything on this machine in.",
"Where each model came from": "Where each model came from",
"Where should the project folder go?": "Where should the project folder go?",
"Whites": "Whites",
@@ -685,6 +696,7 @@
"{0} days ago": "{0} days ago",
"{0} Hz": "{0} Hz",
"{0} installed · {1} MB on disk": "{0} installed · {1} MB on disk",
+ "{0} is not an address like 127.0.0.1:7420": "{0} is not an address like 127.0.0.1:7420",
"{0} K": "{0} K",
"{0} MB of {1} MB": "{0} MB of {1} MB",
"{0} media file(s) not found": "{0} media file(s) not found",
diff --git a/src/crates/concat/src/host.rs b/src/crates/concat/src/host.rs
index d0aad917..e51a65c7 100644
--- a/src/crates/concat/src/host.rs
+++ b/src/crates/concat/src/host.rs
@@ -47,6 +47,10 @@ pub struct Host {
pub cutouts: Arc<concat_host::Cutouts>,
/// The brush model, and the regions it reads under smart strokes.
pub brushes: Arc<concat_host::Brushes>,
+ /// The Concat API on a socket, while the Remote page has it on. Its
+ /// own sessions, apart from the window's: a caller edits projects of
+ /// its own, not the one on screen.
+ pub server: Option<concat_server::Server>,
}
impl Host {
@@ -70,6 +74,7 @@ impl Host {
exporter: Exporter::new(),
transcriber: Arc::new(Transcriber::new()),
speech: Arc::new(Speech::new()),
+ server: None,
})
}
}
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 88f848eb..9381ff36 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -1057,6 +1057,31 @@ pub fn run() -> Result<(), slint::PlatformError> {
state.prefs.save(&state.host.dirs);
state.apply_download_source();
}));
+ app.on_settings_server_enabled_changed(on_window!(|state, on: bool| {
+ state.prefs.server.enabled = on;
+ state.prefs.save(&state.host.dirs);
+ state.apply_server();
+ }));
+ app.on_settings_server_listen_edited(on_window!(|state, text: SharedString| {
+ let listen = text.trim().to_owned();
+ state.prefs.server.listen = if listen.is_empty() {
+ prefs::DEFAULT_LISTEN.to_owned()
+ } else {
+ listen
+ };
+ state.prefs.save(&state.host.dirs);
+ state.apply_server();
+ }));
+ app.on_settings_server_token_edited(on_window!(|state, text: SharedString| {
+ state.prefs.server.token = text.trim().to_owned();
+ state.prefs.save(&state.host.dirs);
+ state.apply_server();
+ }));
+ app.on_settings_server_token_generated(on_window!(|state| {
+ state.prefs.server.token = Studio::new_token();
+ state.prefs.save(&state.host.dirs);
+ state.apply_server();
+ }));
app.on_model_activated(on_window!(|state, id: SharedString| {
state.model_activate(id.as_str());
}));
diff --git a/src/crates/concat/src/prefs.rs b/src/crates/concat/src/prefs.rs
index 4a8b4cb1..5a033ecd 100644
--- a/src/crates/concat/src/prefs.rs
+++ b/src/crates/concat/src/prefs.rs
@@ -39,8 +39,39 @@ pub struct Preferences {
pub download_source: Option<String>,
/// The base URL a custom download source appends a model's file to.
pub download_base: Option<String>,
+ /// The Concat API on a socket while the window is open.
+ #[serde(default)]
+ pub server: ServerPrefs,
}
+/// The Settings sheet's Remote page: whether the API is served while the
+/// window is open, where, and behind which token.
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(default, rename_all = "camelCase")]
+pub struct ServerPrefs {
+ /// Serve while the window is open.
+ pub enabled: bool,
+ /// The TCP address JSON-RPC lines are served on.
+ pub listen: String,
+ /// What a connection presents first. Empty means none, which the
+ /// server only allows on loopback.
+ pub token: String,
+}
+
+impl Default for ServerPrefs {
+ fn default() -> Self {
+ ServerPrefs {
+ enabled: false,
+ listen: DEFAULT_LISTEN.to_owned(),
+ token: String::new(),
+ }
+ }
+}
+
+/// Where the window's server listens unless told otherwise: loopback, on
+/// the port `concat-cli serve` uses too.
+pub const DEFAULT_LISTEN: &str = "127.0.0.1:7420";
+
impl Preferences {
/// Reads the file, or the defaults when there is none.
pub fn load(dirs: &AppDirs) -> Self {
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 35bb41a6..9579c5ec 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -323,6 +323,9 @@ pub struct SettingsState {
pub download_source: usize,
/// The base URL of a custom download source.
pub download_base: String,
+ /// Why the server is not running when the switch is on: the bind that
+ /// failed. Empty while it runs, or is off.
+ pub server_error: String,
}
/// The missing media relink dialog state.
@@ -1489,6 +1492,7 @@ impl Studio {
studio.settings.download_source = studio.download_source().0;
studio.settings.download_base = studio.prefs.download_base.clone().unwrap_or_default();
studio.apply_download_source();
+ studio.apply_server();
studio.refresh_models();
studio
}
@@ -5998,6 +6002,78 @@ impl Studio {
(index, preference)
}
+ /// Starts or stops the API's server to match the preferences. A server
+ /// already running is stopped first, so an edited address or token
+ /// takes effect; a bind that fails turns the switch back off and says
+ /// why on the page.
+ pub fn apply_server(&mut self) {
+ if let Some(server) = self.host.server.take() {
+ server.stop();
+ }
+ self.settings.server_error.clear();
+ let prefs = &self.prefs.server;
+ if !prefs.enabled {
+ return;
+ }
+ let started = prefs
+ .listen
+ .trim()
+ .parse::<std::net::SocketAddr>()
+ .map_err(|_| {
+ tf(
+ "{0} is not an address like 127.0.0.1:7420",
+ &[&prefs.listen],
+ )
+ })
+ .and_then(|address| {
+ let config = concat_server::Config {
+ json: Some(address),
+ token: Some(prefs.token.clone()).filter(|token| !token.is_empty()),
+ ..concat_server::Config::default()
+ };
+ concat_server::Server::start(config, concat_api::Api::new)
+ });
+ match started {
+ Ok(server) => self.host.server = Some(server),
+ Err(error) => {
+ self.prefs.server.enabled = false;
+ self.prefs.save(&self.host.dirs);
+ self.settings.server_error = error.clone();
+ self.notify(&error, true);
+ }
+ }
+ }
+
+ /// What the Remote page says under the switch.
+ fn server_status(&self) -> String {
+ match &self.host.server {
+ Some(server) => {
+ let address = server
+ .json_addr()
+ .map(|address| address.to_string())
+ .unwrap_or_default();
+ tf(
+ "Listening on {0} · {1} connected",
+ &[&address, &server.connections()],
+ )
+ }
+ None if !self.settings.server_error.is_empty() => self.settings.server_error.clone(),
+ None => t("Off"),
+ }
+ }
+
+ /// A fresh token: 128 bits from the OS's randomness, as the standard
+ /// library hands it out through its hasher's seed, spelled in hex.
+ pub fn new_token() -> String {
+ use std::hash::{BuildHasher, Hasher};
+ let word = |salt: u64| {
+ let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
+ hasher.write_u64(salt);
+ hasher.finish()
+ };
+ format!("{:016x}{:016x}", word(1), word(2))
+ }
+
/// Tells the downloaders where to look first, from the preferences.
pub fn apply_download_source(&self) {
let (_, preference) = self.download_source();
@@ -6950,6 +7026,10 @@ impl Studio {
playhead_stops: self.settings.playhead_stops,
download_source: self.settings.download_source as i32,
download_base: self.settings.download_base.as_str().into(),
+ server_enabled: self.prefs.server.enabled,
+ server_listen: self.prefs.server.listen.as_str().into(),
+ server_token: self.prefs.server.token.as_str().into(),
+ server_status: self.server_status().into(),
disk: {
let installed: Vec<&ModelState> = self
.transcribers
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index 1de57571..520bd646 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -191,6 +191,10 @@ export component App inherits Window {
callback settings-playhead-stops-changed(on: bool);
callback settings-download-source-changed(index: int);
callback settings-download-base-edited(text: string);
+ callback settings-server-enabled-changed(on: bool);
+ callback settings-server-listen-edited(text: string);
+ callback settings-server-token-edited(text: string);
+ callback settings-server-token-generated();
callback model-activated(id: string);
callback model-download(id: string);
callback model-cancel(id: string);
@@ -483,6 +487,10 @@ export component App inherits Window {
playhead-stops-changed(on) => { root.settings-playhead-stops-changed(on); }
download-source-changed(index) => { root.settings-download-source-changed(index); }
download-base-edited(text) => { root.settings-download-base-edited(text); }
+ server-enabled-changed(on) => { root.settings-server-enabled-changed(on); }
+ server-listen-edited(text) => { root.settings-server-listen-edited(text); }
+ server-token-edited(text) => { root.settings-server-token-edited(text); }
+ server-token-generated => { root.settings-server-token-generated(); }
model-activated(id) => { root.model-activated(id); }
model-download(id) => { root.model-download(id); }
model-cancel(id) => { root.model-cancel(id); }
diff --git a/src/crates/concat/ui/dialogs/settings.slint b/src/crates/concat/ui/dialogs/settings.slint
index a7ac35c0..c96e2e48 100644
--- a/src/crates/concat/ui/dialogs/settings.slint
+++ b/src/crates/concat/ui/dialogs/settings.slint
@@ -45,7 +45,7 @@ export struct SystemFactData {
export struct SettingsData {
open: bool,
- /// 0 General, 1 Appearance, 2 Transcriber, 3 Speech, 4 About
+ /// 0 General, 1 Appearance, 2 Transcriber, 3 Speech, 4 Remote, 5 About
tab: int,
language: int,
/// the playhead stops at the end of the content
@@ -55,6 +55,14 @@ export struct SettingsData {
download-source: int,
/// the base URL of a custom source
download-base: string,
+ /// the Concat API served on a socket while the window is open
+ server-enabled: bool,
+ /// "127.0.0.1:7420"
+ server-listen: string,
+ /// what a connection presents first; empty for none
+ server-token: string,
+ /// "Listening on 127.0.0.1:7420 · 1 connected", "Off", or why not
+ server-status: string,
/// "3 installed · 612 MB on disk"
disk: string,
version: string,
@@ -352,6 +360,11 @@ export component SettingsDialog inherits Modal {
callback playhead-stops-changed(on: bool);
callback download-source-changed(index: int);
callback download-base-edited(text: string);
+ callback server-enabled-changed(on: bool);
+ callback server-listen-edited(text: string);
+ callback server-token-edited(text: string);
+ /// A fresh random token, in place of whatever is there.
+ callback server-token-generated();
callback model-activated(id: string);
callback model-download(id: string);
callback model-cancel(id: string);
@@ -434,11 +447,17 @@ export component SettingsDialog inherits Modal {
clicked => { root.page-changed(3); }
}
PageTab {
- label: I18n.t("About");
- glyph: Glyph.sparkle;
+ label: I18n.t("Remote");
+ glyph: Glyph.lock;
current: root.data.tab == 4;
clicked => { root.page-changed(4); }
}
+ PageTab {
+ label: I18n.t("About");
+ glyph: Glyph.sparkle;
+ current: root.data.tab == 5;
+ clicked => { root.page-changed(5); }
+ }
}
}
@@ -598,7 +617,81 @@ export component SettingsDialog inherits Modal {
}
}
+ // The API on a socket. The switch is the whole of it for most
+ // people; the address and the token are there for the one who
+ // is putting a script on another machine, and the hints say
+ // what that opens.
if root.data.tab == 4: VerticalLayout {
+ DialogSection {
+ first: true;
+ title: I18n.t("Remote control");
+ hint: I18n.t("Serves the Concat API while the window is open, so a script or another program can create, edit and export projects of its own. Anything that connects can read and write files as you can.");
+
+ HorizontalLayout {
+ spacing: 6px;
+
+ Text {
+ text: I18n.t("Serve the API");
+ color: Theme.fg;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+
+ Rectangle { horizontal-stretch: 1; }
+
+ VerticalLayout {
+ alignment: center;
+ Switch {
+ checked: root.data.server-enabled;
+ toggled(on) => { root.server-enabled-changed(on); }
+ }
+ }
+ }
+
+ Text {
+ text: root.data.server-status;
+ color: Theme.fg-muted;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+
+ DialogSection {
+ title: I18n.t("Address");
+ hint: I18n.t("127.0.0.1 is this machine only. Any other address is reachable from the network, needs a token, and is still not encrypted.");
+
+ Field {
+ value: root.data.server-listen;
+ placeholder: "127.0.0.1:7420";
+ technical: true;
+ edited(text) => { root.server-listen-edited(text); }
+ }
+ }
+
+ DialogSection {
+ title: I18n.t("Token");
+ hint: I18n.t("What a connection must present before its first call. Empty on 127.0.0.1 lets anything on this machine in.");
+
+ HorizontalLayout {
+ spacing: 6px;
+
+ Field {
+ value: root.data.server-token;
+ placeholder: I18n.t("none");
+ technical: true;
+ edited(text) => { root.server-token-edited(text); }
+ }
+
+ Button {
+ label: I18n.t("New token");
+ clicked => { root.server-token-generated(); }
+ }
+ }
+ }
+ }
+
+ if root.data.tab == 5: VerticalLayout {
DialogSection {
first: true;
title: I18n.t("About");