Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge main into #604: dialog hook in the new app creator; Install… keeps showing why a template was refused (#611)

Brandon Thomasf8701860d83d
diff --cc apps/filmcraft/src/main.rs
index d0870b642,d824eb8e0..dd0057899
--- a/apps/filmcraft/src/main.rs
+++ b/apps/filmcraft/src/main.rs
@@@ -133,166 -179,160 +179,167 @@@ fn native_options(agent: bool) -> efram
.with_icon(app_icon())
// Wayland matches the window to `packaging/linux/ai.storyteller.filmcraft.desktop`.
.with_app_id(APP_ID),
- event_loop_builder: agent_event_loop(control_port.is_some()),
+ event_loop_builder: agent_event_loop(agent),
..Default::default()
- };
- // Before eframe creates the wgpu instance: leave OpenGL out on Windows (see graphics.rs).
- #[cfg(target_os = "windows")]
- let options = {
- let mut options = options;
- graphics::configure(&mut options, eframe::wgpu::Backends::from_env());
- options
- };
- let started = eframe::run_native(
- "FilmCraft",
- options,
- Box::new(move |cc| {
- let mut session = Session::default();
- if let Some(dir) = data_dir.clone().or_else(default_data_dir) {
- let mut cfg = AutosaveConfig::new(dir);
- cfg.local_offset = local_offset;
- if let Err(e) = session.start_autosave(cfg) {
- log::warn!("auto-save and crash recovery unavailable: {e}");
+ }
+ }
+
+ /// Creates the app once eframe has its window and graphics device; sets `created` when it runs,
+ /// and confirms the graphics mode once two frames have painted.
+ fn app_creator(launch: Launch, graphics: graphics::GraphicsStart, created: Arc<AtomicBool>) -> eframe::AppCreator<'static> {
+ let Launch { control_port, control_input_only, files, demo, startup_flag, recover, data_dir, graphics: _ } = launch;
+ Box::new(move |cc| {
+ created.store(true, Ordering::Relaxed);
+ // A fallback graphics mode says so in the window, with a button back to the default.
+ let notice = graphics.degraded().then(|| {
+ let start = graphics.clone();
+ filmcraft_ui_egui::graphics_notice::GraphicsNotice::new(graphics.mode().label(), Box::new(move || start.reset_to_default()))
+ });
+ let confirmed = AtomicBool::new(false);
+ cc.egui_ctx.on_end_pass(
+ "graphics-start",
+ Arc::new(move |ui| {
+ if ui.ctx().cumulative_frame_nr() >= 2 && !confirmed.swap(true, Ordering::Relaxed) {
+ graphics.confirm();
}
+ }),
+ );
+ let mut session = Session::default();
+ if let Some(dir) = data_dir.clone().or_else(default_data_dir) {
+ let mut cfg = AutosaveConfig::new(dir);
+ cfg.local_offset = local_offset;
+ if let Err(e) = session.start_autosave(cfg) {
+ log::warn!("auto-save and crash recovery unavailable: {e}");
}
- // voice-over recording reads the microphone through cpal
- session.voiceover.input = Some(Box::new(audio_in::CpalIn::new(&session.prefs.audio_hardware.device_class)));
- let project = files.iter().find(|f| f.ends_with(".fcproj")).cloned();
- if let Some(p) = project {
- if let Err(e) = session.execute("file.open", json!({"path": p})) {
- log::error!("{e}");
- }
- } else if !startup_flag && session.prefs.general.at_startup == "openMostRecent" {
- // Settings ▸ General ▸ At Startup ▸ Open Most Recent
- let recent = session.prefs.general.recent_projects.iter().find(|p| std::path::Path::new(p).exists()).cloned();
- match recent {
- Some(p) => {
- if let Err(e) = session.execute("file.open", json!({"path": p})) {
- log::error!("{e}");
- }
- }
- None => {
- let _ = session.execute("file.openDemoProject", json!({}));
+ }
+ // voice-over recording reads the microphone through cpal
+ session.voiceover.input = Some(Box::new(audio_in::CpalIn::new(&session.prefs.audio_hardware.device_class)));
+ let (project, media) = args::project_and_media(&files);
+ if let Some(p) = project {
+ if let Err(e) = session.execute("file.open", json!({"path": p})) {
+ log::error!("{e}");
+ }
+ } else if !startup_flag && session.prefs.general.at_startup == "openMostRecent" {
+ // Settings ▸ General ▸ At Startup ▸ Open Most Recent
+ let recent = session.prefs.general.recent_projects.iter().find(|p| std::path::Path::new(p).exists()).cloned();
+ match recent {
+ Some(p) => {
+ if let Err(e) = session.execute("file.open", json!({"path": p})) {
+ log::error!("{e}");
}
}
- } else if !startup_flag && session.prefs.general.at_startup == "emptyProject" {
- } else if demo {
- let _ = session.execute("file.openDemoProject", json!({}));
- }
- let media: Vec<String> = files.iter().filter(|f| !f.ends_with(".fcproj")).cloned().collect();
- if !media.is_empty() {
- let _ = session.execute("file.import", json!({"paths": media}));
- }
- if recover == Some(true) && !session.recovery_candidates().is_empty() {
- let id = session.recovery_candidates()[0].id.clone();
- match session.execute("file.recover", json!({"id": id})) {
- Ok(r) => log::info!("recovered {r}"),
- Err(e) => log::error!("recovery failed: {e}"),
+ None => {
+ let _ = session.execute("file.openDemoProject", json!({}));
}
}
- let mut app = FilmcraftApp::new(session);
- if recover == Some(false) {
- app.dialog = None;
- }
- app.integrated_titlebar = cfg!(target_os = "macos");
- if let Some(rs) = cc.wgpu_render_state.clone()
- && std::env::var_os("FILMCRAFT_CPU_COMPOSITE").is_none()
- {
- app.set_wgpu(rs);
- }
- // Keep device selection available even when the default device is unavailable.
- // Settings ▸ Audio Hardware is applied on the first frame (`apply_prefs`).
- app.audio = Some(Box::new(audio::CpalOut::new()));
- app.hooks.pick_files = Some(Box::new(|exts: &[&str]| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t("Media"), &file_filters::extensions(exts))
- .pick_files()
- .unwrap_or_default()
- .into_iter()
- .map(|p| p.to_string_lossy().to_string())
- .collect()
- }));
- // Link Media ▸ Locate…, Attach Proxies, Reconnect Full Resolution: one path, not imported.
- app.hooks.pick_file_for_relink = Some(Box::new(|exts: &[&str], _hint| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t("Media"), &file_filters::extensions(exts))
- .pick_file()
- .map(|p| p.to_string_lossy().to_string())
- }));
- app.hooks.pick_save = Some(Box::new(|name: &str| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t("FilmCraft Project"), &file_filters::extensions(&["fcproj"]))
- .set_file_name(name)
- .save_file()
- .map(|p| p.to_string_lossy().to_string())
- }));
- app.hooks.pick_save_as = Some(Box::new(|filter: &str, exts: &[&str], name: &str| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t(filter), &file_filters::extensions(exts))
- .set_file_name(name)
- .save_file()
- .map(|p| p.to_string_lossy().to_string())
- }));
- app.hooks.pick_folder = Some(Box::new(|| rfd::FileDialog::new().pick_folder().map(|p| p.to_string_lossy().to_string())));
- app.hooks.pick_folder_at =
- Some(Box::new(|dir: &str| rfd::FileDialog::new().set_directory(dir).pick_folder().map(|p| p.to_string_lossy().into_owned())));
- // Linux: the XDG portal call blocks until the user chooses, which would stop the frame
- // loop (GNOME offers to force-quit the window after about five seconds, #260). Show the
- // dialog on its own thread instead; the app keeps running and acts on the answer.
- #[cfg(target_os = "linux")]
- {
- app.hooks.run_dialog = Some(Box::new(run_dialog_off_thread));
- }
- app.hooks.open_path = Some(Box::new(open_path));
- // Help menu, About and Discord links (#642): eframe is built without its `links`
- // feature, so `ctx.open_url` does nothing on the desktop. Detached, so a launcher
- // that waits for the browser never freezes the UI.
- app.hooks.open_url = Some(Box::new(|url: &str| open::that_detached(url).map_err(|e| e.to_string())));
- app.hooks.clipboard_media = Some(Box::new(clipboard_media));
- // Settings ▸ General ▸ Interface Language ▸ System Language (#218).
- app.hooks.cursor_screen_position = Some(Box::new(filmcraft_platform::cursor::cursor_screen_position));
- app.hooks.system_languages = Some(Box::new(|| sys_locale::get_locales().collect()));
- // Settings ▸ Appearance ▸ Appearance Mode ▸ Sync with system on Linux desktops whose
- // compositor reports no theme to winit (no polling: see appearance.rs).
- app.hooks.system_theme = appearance::service();
- app.hooks.raise_without_focus = Some(Box::new(|| {
- window_raise::raise_without_focus();
- }));
- app.hooks.pick_open_file = Some(Box::new(|filter: &str, exts: &[&str]| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t(filter), &file_filters::extensions(exts))
- .pick_file()
- .map(|p| p.to_string_lossy().to_string())
- }));
- app.hooks.pick_open_project = Some(Box::new(|| {
- rfd::FileDialog::new()
- .add_filter(filmcraft_ui_egui::i18n::t("FilmCraft Project"), &file_filters::extensions(&["fcproj"]))
- .pick_file()
- .map(|p| p.to_string_lossy().to_string())
- }));
- #[cfg(target_os = "macos")]
- {
- let (rx, update) = native_menu::install(&app, cc.egui_ctx.clone());
- app.command_inbox = Some(rx);
- app.hooks.shortcuts_changed = Some(update);
- app.ui.show_menu_bar = false;
- }
- if let Some(port) = control_port {
- let rx = control_server::start(port, cc.egui_ctx.clone());
- app = app.with_control(rx);
+ } else if !startup_flag && session.prefs.general.at_startup == "emptyProject" {
+ } else if demo {
+ let _ = session.execute("file.openDemoProject", json!({}));
+ }
+ if !media.is_empty() {
+ let _ = session.execute("file.import", json!({"paths": media}));
+ }
+ if recover == Some(true) && !session.recovery_candidates().is_empty() {
+ let id = session.recovery_candidates()[0].id.clone();
+ match session.execute("file.recover", json!({"id": id})) {
+ Ok(r) => log::info!("recovered {r}"),
+ Err(e) => log::error!("recovery failed: {e}"),
}
- Ok(Box::new(app))
- }),
- );
- // The window could not be created (no usable GPU / graphics driver, no display): say so
- // instead of exiting silently, and keep the reason in the crash log.
- if let Err(e) = &started {
- let msg = format!("FilmCraft could not start its window: {e}\n\nUpdating the graphics driver usually fixes this.");
- log::error!("{msg}");
- filmcraft_ui_egui::crash::record(&msg);
- let _ = rfd::MessageDialog::new().set_title("FilmCraft").set_description(&msg).set_level(rfd::MessageLevel::Error).show();
- }
- started
+ }
+ let mut app = FilmcraftApp::new(session);
+ app.graphics_notice = notice;
+ if recover == Some(false) {
+ app.dialog = None;
+ }
+ app.integrated_titlebar = cfg!(target_os = "macos");
+ if let Some(rs) = cc.wgpu_render_state.clone()
+ && std::env::var_os("FILMCRAFT_CPU_COMPOSITE").is_none()
+ {
+ app.set_wgpu(rs);
+ }
+ // Keep device selection available even when the default device is unavailable.
+ // Settings ▸ Audio Hardware is applied on the first frame (`apply_prefs`).
+ app.audio = Some(Box::new(audio::CpalOut::new()));
+ app.hooks.pick_files = Some(Box::new(|exts: &[&str]| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t("Media"), &file_filters::extensions(exts))
+ .pick_files()
+ .unwrap_or_default()
+ .into_iter()
+ .map(|p| p.to_string_lossy().to_string())
+ .collect()
+ }));
+ // Link Media ▸ Locate…, Attach Proxies, Reconnect Full Resolution: one path, not imported.
+ app.hooks.pick_file_for_relink = Some(Box::new(|exts: &[&str], _hint| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t("Media"), &file_filters::extensions(exts))
+ .pick_file()
+ .map(|p| p.to_string_lossy().to_string())
+ }));
+ app.hooks.pick_save = Some(Box::new(|name: &str| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t("FilmCraft Project"), &file_filters::extensions(&["fcproj"]))
+ .set_file_name(name)
+ .save_file()
+ .map(|p| p.to_string_lossy().to_string())
+ }));
+ app.hooks.pick_save_as = Some(Box::new(|filter: &str, exts: &[&str], name: &str| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t(filter), &file_filters::extensions(exts))
+ .set_file_name(name)
+ .save_file()
+ .map(|p| p.to_string_lossy().to_string())
+ }));
+ app.hooks.pick_folder = Some(Box::new(|| rfd::FileDialog::new().pick_folder().map(|p| p.to_string_lossy().to_string())));
+ app.hooks.pick_folder_at =
+ Some(Box::new(|dir: &str| rfd::FileDialog::new().set_directory(dir).pick_folder().map(|p| p.to_string_lossy().into_owned())));
++ // Linux: the XDG portal call blocks until the user chooses, which would stop the frame
++ // loop (GNOME offers to force-quit the window after about five seconds, #260). Show the
++ // dialog on its own thread instead; the app keeps running and acts on the answer.
++ #[cfg(target_os = "linux")]
++ {
++ app.hooks.run_dialog = Some(Box::new(run_dialog_off_thread));
++ }
+ app.hooks.open_path = Some(Box::new(open_path));
+ // Help menu, About and Discord links (#642): eframe is built without its `links`
+ // feature, so `ctx.open_url` does nothing on the desktop. Detached, so a launcher
+ // that waits for the browser never freezes the UI.
+ app.hooks.open_url = Some(Box::new(|url: &str| open::that_detached(url).map_err(|e| e.to_string())));
+ app.hooks.clipboard_media = Some(Box::new(clipboard_media));
+ // Settings ▸ General ▸ Interface Language ▸ System Language (#218).
+ app.hooks.cursor_screen_position = Some(Box::new(filmcraft_platform::cursor::cursor_screen_position));
+ app.hooks.system_languages = Some(Box::new(|| sys_locale::get_locales().collect()));
+ // Settings ▸ Appearance ▸ Appearance Mode ▸ Sync with system on Linux desktops whose
+ // compositor reports no theme to winit (no polling: see appearance.rs).
+ app.hooks.system_theme = appearance::service();
+ app.hooks.raise_without_focus = Some(Box::new(|| {
+ window_raise::raise_without_focus();
+ }));
+ app.hooks.pick_open_file = Some(Box::new(|filter: &str, exts: &[&str]| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t(filter), &file_filters::extensions(exts))
+ .pick_file()
+ .map(|p| p.to_string_lossy().to_string())
+ }));
+ app.hooks.pick_open_project = Some(Box::new(|| {
+ rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t("FilmCraft Project"), &file_filters::extensions(&["fcproj"]))
+ .pick_file()
+ .map(|p| p.to_string_lossy().to_string())
+ }));
+ #[cfg(target_os = "macos")]
+ {
+ let (rx, update) = native_menu::install(&app, cc.egui_ctx.clone());
+ app.command_inbox = Some(rx);
+ app.hooks.shortcuts_changed = Some(update);
+ app.ui.show_menu_bar = false;
+ }
+ if let Some(port) = control_port {
+ let rx = control_server::start(port, cc.egui_ctx.clone());
+ app = if control_input_only { app.with_control_input_only(rx) } else { app.with_control(rx) };
+ }
+ Ok(Box::new(app))
+ })
}
/// Files copied in the file manager, else an image, on the system clipboard (Paste, #611).
diff --cc crates/ui-egui/src/panels/frame_export.rs
index b3a8f8dd2,33ec63f7e..5e20887e3
--- a/crates/ui-egui/src/panels/frame_export.rs
+++ b/crates/ui-egui/src/panels/frame_export.rs
@@@ -209,19 -208,17 +209,19 @@@ pub fn show(app: &mut FilmcraftApp, ctx
for (id, rect, label) in elems {
app.auto.add(&id, rect, &label);
}
- close |= ctx.input(|i| i.key_pressed(egui::Key::Escape));
+ close |= crate::widgets::escape_closes(ctx);
if browse && !close {
let folder = filmcraft_engine::export_tools::expand_home(d.folder.trim());
- let picked = match app.hooks.pick_folder_at.as_mut() {
- Some(pick) => pick(&folder),
- None => app.hooks.pick_folder.as_mut().and_then(|pick| pick()),
- };
- if let Some(path) = picked {
- d.folder = path;
- d.replace = None;
- }
+ let ctx = ctx.clone();
+ // into the dialog's stored draft, if it is still open when the folder comes back
+ app.pick_ui(FileDialog::Folder { at: Some(folder) }, move |_, paths| {
+ let Some(path) = paths.into_iter().next() else { return };
+ if let Some(Some(mut d)) = ctx.data(|m| m.get_temp::<Option<Draft>>(draft_id())) {
+ d.folder = path;
+ d.replace = None;
+ ctx.data_mut(|m| m.insert_temp(draft_id(), Some(d)));
+ }
+ });
}
if (apply || replace) && !close {
let mut stem = clean(&d.name);
diff --cc crates/ui-egui/src/panels/graphics_templates.rs
index 39d29baf8,da5b635c1..527fde42e
--- a/crates/ui-egui/src/panels/graphics_templates.rs
+++ b/crates/ui-egui/src/panels/graphics_templates.rs
@@@ -590,13 -589,15 +590,18 @@@ pub fn route(app: &mut FilmcraftApp, ct
let empty = params.as_object().is_none_or(|m| m.is_empty());
match id {
"graphics.template.install" if params.get("path").is_none() => {
- let path = app.hooks.pick_open_file.as_mut().and_then(|f| f(tl!("FilmCraft Graphics Template"), &["fcgt"]))?;
- let r = app.session.execute(id, json!({"path": path})).map_err(|e| e.to_string());
- // The Browse panel's Install… button calls this directly and drops the result
- // (#611); report a refused file here, so every caller shows why nothing happened.
- if let Err(e) = &r {
- app.ui.status = e.clone();
- }
- invalidate(ctx);
- Some(r)
+ let (id, ctx) = (id.to_string(), ctx.clone());
+ Some(app.pick(FileDialog::open_file(tl!("FilmCraft Graphics Template"), &["fcgt"]), move |app, paths| {
+ let Some(path) = paths.into_iter().next() else { return Ok(Value::Null) };
+ let r = app.session.execute(&id, json!({"path": path})).map_err(|e| e.to_string());
++ // The Browse panel's Install… button calls this directly and drops the result
++ // (#611); report a refused file here, so every caller shows why nothing happened.
++ if let Err(e) = &r {
++ app.ui.status = e.clone();
++ }
+ invalidate(&ctx);
+ r
+ }))
}
"graphics.template.export" | "file.exportGraphicsTemplate" if empty => {
let clip = filmcraft_engine::graphics::target_clip(&app.session, &Value::Null);
diff --cc crates/ui-egui/src/panels/media_dialogs.rs
index 101ff592b,eb4653915..55370b225
--- a/crates/ui-egui/src/panels/media_dialogs.rs
+++ b/crates/ui-egui/src/panels/media_dialogs.rs
@@@ -621,21 -634,5 +622,21 @@@ fn project_manager(app: &mut FilmcraftA
Err(e) => d.message = e.to_string(),
}
}
- app.ui.project_manager = (keep && !ctx.input(|i| i.key_pressed(egui::Key::Escape))).then_some(d);
+ app.ui.project_manager = (keep && !crate::widgets::escape_closes(ctx)).then_some(d);
}
+
+/// Link Media: relink `item` to `path` with the dialog's matching options; the result goes into `d`.
+fn relink_to(app: &mut FilmcraftApp, d: &mut LinkMediaDraft, item: &Value, path: String) {
+ let mut p = match_params(d);
+ p["item"] = item.clone();
+ p["path"] = json!(path);
+ match app.session.execute("media.relink", p) {
+ Ok(v) => {
+ d.message.clear();
+ d.candidates.clear();
+ d.candidate = None;
+ app.ui.status = tlf!("Linked {n} clip(s)", n = v["relinked"].as_array().map_or(0, Vec::len));
+ }
+ Err(e) => d.message = e.to_string(),
+ }
+}
diff --cc crates/ui-egui/src/panels/menu_dialogs.rs
index 5f4dfe0d7,7c6b4bc7b..196c4376f
--- a/crates/ui-egui/src/panels/menu_dialogs.rs
+++ b/crates/ui-egui/src/panels/menu_dialogs.rs
@@@ -827,18 -825,12 +830,18 @@@ pub fn show(app: &mut FilmcraftApp, ctx
for (id, r, l) in elems {
app.auto.add(&id, r, &l);
}
- if let Some(k) = browse
- && let Some(dir) = app.hooks.pick_folder.as_mut().and_then(|f| f())
- {
- d.params[k.as_str()] = json!(dir);
+ if let Some(k) = browse {
+ // into the dialog's parameters, if the same dialog is still open when the folder comes back
+ let command = d.command.clone();
+ app.pick_ui(FileDialog::Folder { at: None }, move |app, paths| {
+ if let (Some(dir), Some(d)) = (paths.into_iter().next(), app.ui.extras.dialog.as_mut())
+ && d.command == command
+ {
+ d.params[k.as_str()] = json!(dir);
+ }
+ });
}
- if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ if crate::widgets::escape_closes(ctx) {
action = Some("cancel");
}
match action {
diff --cc crates/ui-egui/src/panels/settings.rs
index 3a2d6d880,6ca2dda57..bc1b867f1
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@@ -17,7 -17,7 +17,8 @@@ use filmcraft_project::Label
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value, json};
+ use crate::icons::Icon;
+use crate::native_dialogs::FileDialog;
use crate::theme::Tokens;
use crate::{AudioDevices, Dialog, FilmcraftApp};