The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
feat(android): a finished export goes into the phone's Movies, where the gallery shows it
Jareer63f263349433
diff --git a/src/crates/concat-android/java/ConcatFiles.java b/src/crates/concat-android/java/ConcatFiles.javaindex 798beef4..6d19ae8d 100644--- a/src/crates/concat-android/java/ConcatFiles.java+++ b/src/crates/concat-android/java/ConcatFiles.java@@ -6,12 +6,18 @@ package app.concat.editor;import android.app.Activity;import android.app.Fragment;import android.content.ClipData;+import android.content.ContentResolver;+import android.content.ContentValues;import android.content.Intent;import android.database.Cursor;import android.net.Uri;+import android.os.Build;+import android.os.Environment;+import android.provider.MediaStore;import android.provider.OpenableColumns;import java.io.File;+import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;@@ -35,6 +41,11 @@ import java.util.List;* what the engine is handed - through the native method below, which the* Rust side registers before it asks for a pick.*+ * The way out is here as well: a finished export is written into the+ * app's own folder, which on a phone nothing but the app can open, so+ * {@link #publishVideo} moves it into the phone's Movies through the+ * media store, where the gallery and every file manager show it.+ ** Compiled by build.rs with the SDK's javac and d8, and loaded at run time* from the dex inside the binary; see src/lib.rs.*/@@ -42,6 +53,87 @@ public class ConcatFiles extends Fragment {private static final int REQUEST_PICK = 0xC0C4;private static final String TAG = "concat-files";+ /**+ * Where a finished export goes, under the phone's storage: Movies/Concat.+ * Null before Android 10, which has no media store an app can write+ * through without a permission; there the file stays in the app's folder.+ */+ public static String publishedFolder() {+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {+ return null;+ }+ return Environment.DIRECTORY_MOVIES + "/Concat";+ }++ /**+ * Moves the video at {@code path} into {@link #publishedFolder()} through+ * the media store and deletes the original. Two strings come back: the+ * file's path under the phone's storage and null, or null and why it+ * could not be moved - in which case the original is still where it was.+ * Blocking: a video is big and the copy takes a while, so this is called+ * off the window's thread.+ */+ public static String[] publishVideo(Activity activity, String path) {+ String folder = publishedFolder();+ if (folder == null) {+ return new String[] {null, "this phone has no media store to put it in"};+ }+ File file = new File(path);+ ContentResolver resolver = activity.getContentResolver();+ ContentValues values = new ContentValues();+ values.put(MediaStore.Video.Media.DISPLAY_NAME, file.getName());+ values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");+ values.put(MediaStore.Video.Media.RELATIVE_PATH, folder);+ values.put(MediaStore.Video.Media.IS_PENDING, 1);+ Uri collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);+ Uri uri;+ try {+ uri = resolver.insert(collection, values);+ } catch (Exception e) {+ return new String[] {null, "the media store refused the file: " + e.getMessage()};+ }+ if (uri == null) {+ return new String[] {null, "the media store refused the file"};+ }+ InputStream in = null;+ OutputStream out = null;+ try {+ in = new FileInputStream(file);+ out = resolver.openOutputStream(uri);+ if (out == null) {+ throw new IOException("the media store would not open the file for writing");+ }+ byte[] buffer = new byte[1 << 16];+ int read;+ while ((read = in.read(buffer)) > 0) {+ out.write(buffer, 0, read);+ }+ out.close();+ out = null;+ values.clear();+ values.put(MediaStore.Video.Media.IS_PENDING, 0);+ resolver.update(uri, values, null, null);+ } catch (Exception e) {+ try {+ resolver.delete(uri, null, null);+ } catch (Exception ignored) {+ }+ return new String[] {null, e.getMessage() == null ? e.toString() : e.getMessage()};+ } finally {+ try {+ if (in != null) in.close();+ } catch (IOException ignored) {+ }+ try {+ if (out != null) out.close();+ } catch (IOException ignored) {+ }+ }+ file.delete();+ // The store may have renamed it: a second "name.mp4" is "name (1).mp4".+ return new String[] {folder + "/" + displayName(activity, uri), null};+ }+/** Registered from Rust: the picked files' paths, or none. */public static native void filesPicked(String[] paths);diff --git a/src/crates/concat-android/src/lib.rs b/src/crates/concat-android/src/lib.rsindex 2daea09f..18bd5742 100644--- a/src/crates/concat-android/src/lib.rs+++ b/src/crates/concat-android/src/lib.rs@@ -96,62 +96,42 @@ mod activity {}}-/// The system's document picker, reached through the Java in java/.+/// The Java in java/, and the way to it.///-/// The window is a NativeActivity with no Java of its own, and a picker's-/// answer comes back only through Java; so the Java is a fragment-/// compiled by build.rs into a dex the binary carries, loaded here through-/// an in-memory class loader, and told - by registering a native method on-/// it - where to bring the answer. The picked files are copied into the-/// app's own storage by the Java, and their paths are what comes back.+/// The window is a NativeActivity with no Java of its own, and some of+/// what a phone does - a picker's answer, the media store - comes only+/// through Java; so the Java is a fragment compiled by build.rs into a dex+/// the binary carries, loaded here through an in-memory class loader+/// once, and reached through [`java::with_class`].#[cfg(target_os = "android")]-mod picker {+mod java {use std::ffi::c_void;- use std::path::PathBuf;- use std::sync::{Mutex, OnceLock};+ use std::sync::OnceLock;- use jni::objects::{Global, JClass, JObject, JObjectArray, JString};- use jni::{Env, JavaVM, jni_sig, jni_str, sys};+ use jni::objects::{Global, JClass, JObject};+ use jni::{Env, JavaVM, jni_sig, jni_str};use slint::android::AndroidApp;/// The classes build.rs compiled: app.concat.editor.ConcatFiles.const DEX: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/classes.dex"));const CLASS_NAME: &str = "app.concat.editor.ConcatFiles";- type Picked = Box<dyn FnOnce(Vec<PathBuf>) + Send>;-- /// The pick in flight, waiting for Java to answer.- static PENDING: Mutex<Option<Picked>> = Mutex::new(None);/// The fragment class, loaded once and kept.static CLASS: OnceLock<Global<JClass<'static>>> = OnceLock::new();- /// Hands the window's crate a picker that runs on this activity.- pub fn install(app: &AndroidApp) {- let app = app.clone();- concat::install_file_picker(Box::new(move |on_picked| {- let previous = PENDING- .lock()- .map(|mut slot| slot.replace(on_picked))- .ok()- .flatten();- if let Some(previous) = previous {- // A pick was already up; the one that asked first is told- // it got nothing rather than left waiting for ever.- previous(Vec::new());- }- if let Err(error) = pick(&app) {- log::error!("could not show the document picker: {error}");- if let Some(pending) = PENDING.lock().ok().and_then(|mut slot| slot.take()) {- pending(Vec::new());- }- }- }));- }-- fn pick(app: &AndroidApp) -> jni::errors::Result<()> {+ /// Runs `with` on this thread, attached to the activity's JavaVM, with+ /// the activity and the fragment class - loaded the first time.+ pub fn with_class<T>(+ app: &AndroidApp,+ with: impl FnOnce(+ &mut Env<'_>,+ &JObject<'_>,+ &Global<JClass<'static>>,+ ) -> jni::errors::Result<T>,+ ) -> jni::errors::Result<T> {// SAFETY: the pointer is the activity's JavaVM, live for the// process; `from_raw` also seeds `JavaVM::singleton`, which the- // native callback below reaches for.+ // native callback reaches for.let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().cast()) };vm.attach_current_thread(|env| {// SAFETY: the activity pointer is a live reference the app@@ -165,13 +145,7 @@ mod picker {CLASS.get().expect("set just above")}};- env.call_static_method(- class,- jni_str!("pick"),- jni_sig!("(Landroid/app/Activity;)V"),- &[(&activity).into()],- )?;- Ok(())+ with(env, &activity, class)})}@@ -212,16 +186,74 @@ mod picker {jni::NativeMethod::from_raw_parts(jni_str!("filesPicked"),jni_str!("([Ljava/lang/String;)V"),- files_picked as *mut c_void,+ super::picker::files_picked as *mut c_void,)};// SAFETY: as above.unsafe { env.register_native_methods(&class, &[method]) }?;env.new_global_ref(class)}+}++/// The system's document picker.+///+/// A picker's result comes back only through an activity's or a+/// fragment's onActivityResult, so the Java fragment is added to the+/// activity for the length of one pick and told - by the native method+/// registered on it - where to bring the answer. The picked files are+/// copied into the app's own storage by the Java, and their paths are+/// what comes back.+#[cfg(target_os = "android")]+mod picker {+ use std::path::PathBuf;+ use std::sync::Mutex;++ use jni::objects::{JObjectArray, JString};+ use jni::{JavaVM, jni_sig, jni_str, sys};+ use slint::android::AndroidApp;++ type Picked = Box<dyn FnOnce(Vec<PathBuf>) + Send>;++ /// The pick in flight, waiting for Java to answer.+ static PENDING: Mutex<Option<Picked>> = Mutex::new(None);++ /// Hands the window's crate a picker that runs on this activity.+ pub fn install(app: &AndroidApp) {+ let app = app.clone();+ concat::install_file_picker(Box::new(move |on_picked| {+ let previous = PENDING+ .lock()+ .map(|mut slot| slot.replace(on_picked))+ .ok()+ .flatten();+ if let Some(previous) = previous {+ // A pick was already up; the one that asked first is told+ // it got nothing rather than left waiting for ever.+ previous(Vec::new());+ }+ if let Err(error) = pick(&app) {+ log::error!("could not show the document picker: {error}");+ if let Some(pending) = PENDING.lock().ok().and_then(|mut slot| slot.take()) {+ pending(Vec::new());+ }+ }+ }));+ }++ fn pick(app: &AndroidApp) -> jni::errors::Result<()> {+ super::java::with_class(app, |env, activity, class| {+ env.call_static_method(+ class,+ jni_str!("pick"),+ jni_sig!("(Landroid/app/Activity;)V"),+ &[activity.into()],+ )?;+ Ok(())+ })+ }/// `ConcatFiles.filesPicked`, on whichever thread the Java copied on.- unsafe extern "system" fn files_picked(+ pub(super) unsafe extern "system" fn files_picked(_env: *mut sys::JNIEnv,_class: sys::jclass,paths: sys::jobjectArray,@@ -251,6 +283,100 @@ mod picker {}}+/// Where a finished export goes.+///+/// The export writes into the app's own folder, which on a phone nothing+/// but the app can open: not the gallery, not a file manager (#280,+/// #147). So once a file is written the Java moves it into the phone's+/// Movies, under Concat, through the media store, and the sheet names+/// that folder from the start. A phone older than Android 10 has no+/// media store an app can write through without a permission; there the+/// file stays where it was written, and the sheet says so.+#[cfg(target_os = "android")]+mod publisher {+ use std::path::Path;++ use jni::objects::{JObjectArray, JString};+ use jni::refs::Reference;+ use jni::{jni_sig, jni_str};+ use slint::android::AndroidApp;++ /// Hands the window's crate the way to the media store, where this+ /// phone has one to write through.+ pub fn install(app: &AndroidApp) {+ let folder = match published_folder(app) {+ Ok(Some(folder)) => folder,+ Ok(None) => {+ log::info!(+ "exports stay in the app's folder: this phone's media store takes no files"+ );+ return;+ }+ Err(error) => {+ log::warn!("could not ask where exports go: {error}");+ return;+ }+ };+ let app = app.clone();+ concat::install_export_publisher(concat::ExportPublisher {+ folder,+ publish: Box::new(move |path| publish(&app, path)),+ });+ }++ /// `ConcatFiles.publishedFolder`: "Movies/Concat", or nothing.+ fn published_folder(app: &AndroidApp) -> jni::errors::Result<Option<String>> {+ super::java::with_class(app, |env, _activity, class| {+ let answer = env+ .call_static_method(+ class,+ jni_str!("publishedFolder"),+ jni_sig!("()Ljava/lang/String;"),+ &[],+ )?+ .l()?;+ if answer.is_null() {+ return Ok(None);+ }+ let answer = env.cast_local::<JString>(answer)?;+ Ok(Some(answer.mutf8_chars(env)?.to_string()))+ })+ }++ /// `ConcatFiles.publishVideo`: the file's path under the phone's+ /// storage once it is in Movies, or why it could not be moved.+ fn publish(app: &AndroidApp, path: &Path) -> Result<String, String> {+ let answer = super::java::with_class(app, |env, activity, class| {+ let path = env.new_string(path.to_string_lossy())?;+ let answer = env+ .call_static_method(+ class,+ jni_str!("publishVideo"),+ jni_sig!("(Landroid/app/Activity;Ljava/lang/String;)[Ljava/lang/String;"),+ &[activity.into(), (&path).into()],+ )?+ .l()?;+ let answer = env.cast_local::<JObjectArray<JString>>(answer)?;+ let mut out = Vec::new();+ for index in 0..answer.len(env)? {+ let item = answer.get_element(env, index)?;+ out.push(if item.is_null() {+ None+ } else {+ Some(item.mutf8_chars(env)?.to_string())+ });+ }+ Ok(out)+ })+ .map_err(|error| format!("could not reach the phone's media store: {error}"))?;+ match answer.as_slice() {+ [Some(path), _] => Ok(path.clone()),+ [None, Some(why)] => Err(why.clone()),+ _ => Err("the phone said nothing".to_owned()),+ }+ }+}+/// Called by the activity's native glue; the name is the contract.#[cfg(target_os = "android")]#[unsafe(no_mangle)]@@ -263,8 +389,9 @@ fn android_main(app: slint::android::AndroidApp) {log::error!("could not start the Android backend: {error}");return;}- // After the backend, which seeds the JavaVM the picker reaches for.+ // After the backend, which seeds the JavaVM the Java is reached by.picker::install(&app);+ publisher::install(&app);if let Err(error) = concat::run() {log::error!("{error}");}diff --git a/src/crates/concat/locales/de.json b/src/crates/concat/locales/de.jsonindex 0b463c39..83b248a6 100644--- a/src/crates/concat/locales/de.json+++ b/src/crates/concat/locales/de.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "Farbe","export.contents": "Inhalt",+ "export.couldNotPublish": "Konnte nicht in {0} speichern: {1}","export.couldNotShowFile": "Datei konnte nicht angezeigt werden: {0}","export.destination": "Ziel","export.exportAgain": "Erneut exportieren",diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.jsonindex 9b189378..52293a75 100644--- a/src/crates/concat/locales/en.json+++ b/src/crates/concat/locales/en.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "Colour","export.contents": "Contents",+ "export.couldNotPublish": "Could not save to {0}: {1}","export.couldNotShowFile": "Could not show the file: {0}","export.destination": "Destination","export.exportAgain": "Export again",diff --git a/src/crates/concat/locales/es.json b/src/crates/concat/locales/es.jsonindex bad7ab79..198e0c84 100644--- a/src/crates/concat/locales/es.json+++ b/src/crates/concat/locales/es.json@@ -550,6 +550,7 @@"export.codec": "Códec","export.colour": "Color","export.contents": "Contenido",+ "export.couldNotPublish": "No se pudo guardar en {0}: {1}","export.couldNotShowFile": "No se pudo mostrar el archivo: {0}","export.destination": "Destino","export.exportAgain": "Exportar de nuevo",diff --git a/src/crates/concat/locales/fa.json b/src/crates/concat/locales/fa.jsonindex 55775d30..a70d2546 100644--- a/src/crates/concat/locales/fa.json+++ b/src/crates/concat/locales/fa.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "رنگ","export.contents": "محتوا",+ "export.couldNotPublish": "ذخیره در {0} ممکن نبود: {1}","export.couldNotShowFile": "نمایش فایل ممکن نشد: {0}","export.destination": "مقصد","export.exportAgain": "خروجی گرفتن مجدد",diff --git a/src/crates/concat/locales/fr.json b/src/crates/concat/locales/fr.jsonindex 5c34c1cb..22357e48 100644--- a/src/crates/concat/locales/fr.json+++ b/src/crates/concat/locales/fr.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "Couleur","export.contents": "Contenu",+ "export.couldNotPublish": "Impossible d’enregistrer dans {0} : {1}","export.couldNotShowFile": "Impossible d'afficher le fichier : {0}","export.destination": "Destination","export.exportAgain": "Exporter à nouveau",diff --git a/src/crates/concat/locales/hr.json b/src/crates/concat/locales/hr.jsonindex 7ca8c23e..1edcc670 100644--- a/src/crates/concat/locales/hr.json+++ b/src/crates/concat/locales/hr.json@@ -550,6 +550,7 @@"export.codec": "Kodek","export.colour": "Boja","export.contents": "Sadržaj",+ "export.couldNotPublish": "Nije moguće spremiti u {0}: {1}","export.couldNotShowFile": "Nije moguće prikazati datoteku: {0}","export.destination": "Odredište","export.exportAgain": "Izvezi ponovno",diff --git a/src/crates/concat/locales/it.json b/src/crates/concat/locales/it.jsonindex e7f36300..851f471c 100644--- a/src/crates/concat/locales/it.json+++ b/src/crates/concat/locales/it.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "Colore","export.contents": "Contenuto",+ "export.couldNotPublish": "Impossibile salvare in {0}: {1}","export.couldNotShowFile": "Impossibile mostrare il file: {0}","export.destination": "Destinazione","export.exportAgain": "Esporta di nuovo",diff --git a/src/crates/concat/locales/ja.json b/src/crates/concat/locales/ja.jsonindex 456fa7a6..cef25ece 100644--- a/src/crates/concat/locales/ja.json+++ b/src/crates/concat/locales/ja.json@@ -550,6 +550,7 @@"export.codec": "コーデック","export.colour": "カラー","export.contents": "内容",+ "export.couldNotPublish": "{0} に保存できませんでした: {1}","export.couldNotShowFile": "ファイルを表示できませんでした:{0}","export.destination": "保存先","export.exportAgain": "もう一度書き出す",diff --git a/src/crates/concat/locales/ko.json b/src/crates/concat/locales/ko.jsonindex 96ff4e12..c3ef845c 100644--- a/src/crates/concat/locales/ko.json+++ b/src/crates/concat/locales/ko.json@@ -550,6 +550,7 @@"export.codec": "코덱","export.colour": "색상","export.contents": "내용",+ "export.couldNotPublish": "{0}에 저장할 수 없습니다: {1}","export.couldNotShowFile": "파일을 표시할 수 없습니다: {0}","export.destination": "대상","export.exportAgain": "다시 내보내기",diff --git a/src/crates/concat/locales/pt-BR.json b/src/crates/concat/locales/pt-BR.jsonindex e1dc94a4..4d1f7077 100644--- a/src/crates/concat/locales/pt-BR.json+++ b/src/crates/concat/locales/pt-BR.json@@ -550,6 +550,7 @@"export.codec": "Codec","export.colour": "Cor","export.contents": "Conteúdo",+ "export.couldNotPublish": "Não foi possível salvar em {0}: {1}","export.couldNotShowFile": "Não foi possível mostrar o arquivo: {0}","export.destination": "Destino","export.exportAgain": "Exportar de novo",diff --git a/src/crates/concat/locales/ru.json b/src/crates/concat/locales/ru.jsonindex e8d915b6..d4e22563 100644--- a/src/crates/concat/locales/ru.json+++ b/src/crates/concat/locales/ru.json@@ -550,6 +550,7 @@"export.codec": "Кодек","export.colour": "Цвет","export.contents": "Содержимое",+ "export.couldNotPublish": "Не удалось сохранить в {0}: {1}","export.couldNotShowFile": "Не удалось показать файл: {0}","export.destination": "Назначение","export.exportAgain": "Экспортировать ещё раз",diff --git a/src/crates/concat/locales/tr.json b/src/crates/concat/locales/tr.jsonindex 8b75d3fd..48af63a8 100644--- a/src/crates/concat/locales/tr.json+++ b/src/crates/concat/locales/tr.json@@ -550,6 +550,7 @@"export.codec": "Kodek","export.colour": "Renk","export.contents": "İçerik",+ "export.couldNotPublish": "{0} konumuna kaydedilemedi: {1}","export.couldNotShowFile": "Dosya gösterilemedi: {0}","export.destination": "Hedef","export.exportAgain": "Yeniden dışa aktar",diff --git a/src/crates/concat/locales/zh-Hans.json b/src/crates/concat/locales/zh-Hans.jsonindex e3339273..c16ed932 100644--- a/src/crates/concat/locales/zh-Hans.json+++ b/src/crates/concat/locales/zh-Hans.json@@ -550,6 +550,7 @@"export.codec": "编码器","export.colour": "颜色","export.contents": "目录",+ "export.couldNotPublish": "无法保存到 {0}:{1}","export.couldNotShowFile": "无法显示文件:{0}","export.destination": "目标位置","export.exportAgain": "再次导出",diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.jsonindex 538c7800..3e0bd005 100644--- a/src/crates/concat/locales/zh-TW.json+++ b/src/crates/concat/locales/zh-TW.json@@ -550,6 +550,7 @@"export.codec": "編碼格式","export.colour": "顏色","export.contents": "目錄",+ "export.couldNotPublish": "無法儲存到 {0}:{1}","export.couldNotShowFile": "無法顯示檔案:{0}","export.destination": "目的地","export.exportAgain": "再次匯出",diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rsindex f959490c..6ee538ed 100644--- a/src/crates/concat/src/lib.rs+++ b/src/crates/concat/src/lib.rs@@ -42,9 +42,11 @@ mod i18n;mod meters;mod platform;/// What a phone's own crate installs before the window runs: the way to-/// the system's file picker. See `platform::pick_files_async`.+/// the system's file picker, and where a finished export is put so the+/// phone shows it. See `platform::pick_files_async` and+/// `platform::publish_export`.#[cfg(any(target_os = "android", target_os = "ios"))]-pub use platform::{FilePicker, install_file_picker};+pub use platform::{ExportPublisher, FilePicker, install_export_publisher, install_file_picker};mod panes;mod prefs;mod presets;diff --git a/src/crates/concat/src/panes/export.rs b/src/crates/concat/src/panes/export.rsindex 7eb8fb58..46a7c345 100644--- a/src/crates/concat/src/panes/export.rs+++ b/src/crates/concat/src/panes/export.rs@@ -67,6 +67,9 @@ pub enum ExportMsg {},/// The render's worker is done: the file written, or why not.Finished(Result<String, String>),+ /// The phone has moved the file to where it shows it - the path under+ /// the phone's storage - or could not, and the file is where it was.+ Published(Result<String, String>),}/// The export sheet's state.@@ -213,9 +216,26 @@ impl ExportPane {ExportMsg::Finished(Ok(written)) => {self.phase = ExportPhase::Done;self.progress = 1.0;- self.written = written;+ self.written = written.clone();+ // A phone moves the file to where its gallery shows it, and+ // the sheet says "finished" once it is there.+ let handed = platform::publish_export(written.into(), |result| {+ on_ui(move |studio, _, _| {+ studio.handle(Msg::Export(ExportMsg::Published(result)));+ });+ });+ if !handed {+ studio.notify(&t("export.exportFinished"), false);+ }+ }+ ExportMsg::Published(Ok(path)) => {+ self.written = path;studio.notify(&t("export.exportFinished"), false);}+ ExportMsg::Published(Err(error)) => {+ let folder = platform::published_folder().unwrap_or_default();+ studio.notify(&tf("export.couldNotPublish", &[&folder, &error]), true);+ }ExportMsg::Finished(Err(error)) => {if self.phase == ExportPhase::Idle {// Cancelled: the sheet already went back to idle.@@ -498,7 +518,13 @@ impl ExportPane {ExportData {open: self.open,name: self.name.as_str().into(),- path: format!("{}/{}.mp4", self.folder.trim_end_matches('/'), self.name).into(),+ // Where the file ends up: on a phone, the folder its gallery+ // shows, not the app's own that the export writes into.+ path: match platform::published_folder() {+ Some(folder) => format!("{folder}/{}.mp4", self.name),+ None => format!("{}/{}.mp4", self.folder.trim_end_matches('/'), self.name),+ }+ .into(),format: format!("{width} × {height} · {rate:.2} fps").into(),duration: {let whole = studio.duration().max(0.0) as i32;diff --git a/src/crates/concat/src/platform.rs b/src/crates/concat/src/platform.rsindex f65077ca..47d523a9 100644--- a/src/crates/concat/src/platform.rs+++ b/src/crates/concat/src/platform.rs@@ -596,6 +596,74 @@ pub fn install_file_picker(picker: FilePicker) {let _ = FILE_PICKER.set(picker);}+/// What a phone does with a finished export: moves the file to where the+/// phone's own gallery and file manager show it, and says where. The+/// export itself writes into the app's own folder, which on a phone+/// nothing but the app can open. Installed by the phone's own crate before+/// the window runs, where the phone can be asked at all; see+/// [`install_export_publisher`].+#[cfg(any(target_os = "android", target_os = "ios"))]+pub struct ExportPublisher {+ /// Where the files go, as the phone names it: "Movies/Concat".+ pub folder: String,+ /// Moves the file there and answers with its path under the phone's+ /// storage, or with why it could not, leaving the file where it was.+ /// It copies a whole video, so it is called off the window's thread.+ pub publish: Box<dyn Fn(&std::path::Path) -> Result<String, String> + Send + Sync>,+}++#[cfg(any(target_os = "android", target_os = "ios"))]+static EXPORT_PUBLISHER: std::sync::OnceLock<ExportPublisher> = std::sync::OnceLock::new();++/// Installs where a phone puts a finished export. Once; a second call is+/// ignored.+#[cfg(any(target_os = "android", target_os = "ios"))]+pub fn install_export_publisher(publisher: ExportPublisher) {+ let _ = EXPORT_PUBLISHER.set(publisher);+}++/// Where a finished export ends up on this device when that is not the+/// folder the export writes into: a phone's "Movies/Concat". None on a+/// desktop, and on a phone too old to be asked, where the file stays where+/// the sheet says.+pub fn published_folder() -> Option<&'static str> {+ #[cfg(any(target_os = "android", target_os = "ios"))]+ {+ EXPORT_PUBLISHER+ .get()+ .map(|publisher| publisher.folder.as_str())+ }+ #[cfg(not(any(target_os = "android", target_os = "ios")))]+ {+ None+ }+}++/// Hands a finished export to the phone on a thread of its own, and calls+/// `on_done` with where it went or why it did not - on that thread; the+/// caller hops to the window's. False when there is nothing to hand it to:+/// the file stays where it was written, and `on_done` is never called.+pub fn publish_export(+ path: std::path::PathBuf,+ on_done: impl FnOnce(Result<String, String>) + Send + 'static,+) -> bool {+ #[cfg(any(target_os = "android", target_os = "ios"))]+ {+ let Some(publisher) = EXPORT_PUBLISHER.get() else {+ return false;+ };+ std::thread::Builder::new()+ .name("export publish".into())+ .spawn(move || on_done((publisher.publish)(&path)))+ .is_ok()+ }+ #[cfg(not(any(target_os = "android", target_os = "ios")))]+ {+ let _ = (path, on_done);+ false+ }+}+/// Asks for files and calls `on_picked` with them, on whichever thread the/// platform answers from - the caller hops to the window's thread itself.///