Skip to content

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

Merge main into #1129: About/Discord and the translated predefined items take part in menu updates

Brandon Thomase283aa5303cd
diff --cc apps/filmcraft/src/main.rs
index 03ec08a26,dac302acf..3bb009ea5
--- a/apps/filmcraft/src/main.rs
+++ b/apps/filmcraft/src/main.rs
@@@ -133,159 -179,171 +179,171 @@@ 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())));
- 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.menu_changed = Some(update);
- app.ui.show_menu_bar = false;
+ } 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}"),
}
- 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) };
+ }
+ 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| {
+ // a full path (Quick Export, Export mode) opens the dialog in its folder
+ let path = std::path::Path::new(name);
+ let mut dialog = rfd::FileDialog::new()
+ .add_filter(filmcraft_ui_egui::i18n::t(filter), &file_filters::extensions(exts))
+ .set_file_name(path.file_name().map_or(name.into(), |n| n.to_string_lossy()));
+ if let Some(dir) = path.parent().filter(|d| d.is_dir()) {
+ dialog = dialog.set_directory(dir);
}
- 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
+ dialog.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.hooks.menu_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 apps/filmcraft/src/native_menu.rs
index cdf70ff2b,0d8fd0e2b..8ac830698
--- a/apps/filmcraft/src/native_menu.rs
+++ b/apps/filmcraft/src/native_menu.rs
@@@ -29,18 -28,32 +29,36 @@@ pub fn install(app: &FilmcraftApp, ctx
let mut titles: Vec<(String, Submenu)> = Vec::new();
let bar = Menu::new();
let app_menu = Submenu::new("FilmCraft", true);
+ let [settings_label, hide_label, hide_others_label, quit_label] = NATIVE_APP_MENU;
// FilmCraft ▸ Settings ▸ <category> (Premiere's app-menu layout; General is Cmd+,)
- let settings = Submenu::new(app.ui.language.tr("Settings"), true);
- titles.push(("Settings".into(), settings.clone()));
+ let settings = Submenu::new(app.ui.language.tr(settings_label), true);
+ titles.push((settings_label.into(), settings.clone()));
for it in items.iter().filter(|i| i.id.starts_with("app.settings.")) {
let label = it.label.trim_end_matches('…').to_string();
- let mi = MenuItem::with_id(it.id.clone(), label, true, it.shortcut.as_deref().and_then(accel));
- native.push((it.id.clone(), mi.clone()));
+ let mi = MenuItem::with_id(it.id.clone(), label, it.enabled, it.shortcut.as_deref().and_then(accel));
+ native.push((it.clone(), mi.clone()));
let _ = settings.append(&mi);
}
+ // About and Discord repeat Help menu commands: same translated labels, updated with them
+ let label = |id: &str, english: &str| items.iter().find(|i| i.id == id).map_or_else(|| english.to_string(), |i| i.label.clone());
+ let about = MenuItem::with_id("app.about", label("app.about", "About FilmCraft"), true, None);
+ let discord = MenuItem::with_id("help.discord", label("help.discord", "Join the ArtCraft Discord…"), true, None);
- native.push(("app.about".into(), about.clone()));
- native.push(("help.discord".into(), discord.clone()));
++ for (id, mi) in [("app.about", &about), ("help.discord", &discord)] {
++ if let Some(it) = items.iter().find(|i| i.id == id) {
++ // recorded as built (enabled, no shortcut), so the first update applies the real state
++ native.push((Item { enabled: true, shortcut: None, ..it.clone() }, mi.clone()));
++ }
++ }
+ // the predefined items keep their native actions; our text lets them follow the language
+ let predefined = [
+ (hide_label, PredefinedMenuItem::hide(Some(app.ui.language.tr(hide_label)))),
+ (hide_others_label, PredefinedMenuItem::hide_others(Some(app.ui.language.tr(hide_others_label)))),
+ (quit_label, PredefinedMenuItem::quit(Some(app.ui.language.tr(quit_label)))),
+ ];
+ let [(_, hide), (_, hide_others), (_, quit)] = &predefined;
let _ = app_menu.append_items(&[
- &MenuItem::with_id("app.about", "About FilmCraft", true, None),
- &MenuItem::with_id("help.discord", "Join the ArtCraft Discord…", true, None),
+ &about,
+ &discord,
&PredefinedMenuItem::separator(),
&settings,
&PredefinedMenuItem::separator(),
@@@ -114,25 -128,17 +134,28 @@@
} else {
filmcraft_ui_egui::i18n::Language::En
};
- for (title, submenu) in &titles {
- submenu.set_text(language.tr(title));
+ if language != shown_language {
+ shown_language = language;
+ for (title, submenu) in &titles {
+ submenu.set_text(language.tr(title));
+ }
}
+ for (label, item) in &predefined {
+ item.set_text(language.tr(label));
+ }
- for (id, mi) in &native {
- if let Some(it) = items.iter().find(|i| &i.id == id) {
- mi.set_text(&it.label);
+ for (shown, mi) in &mut native {
+ let Some(it) = items.iter().find(|i| i.id == shown.id) else { continue };
+ if it.label != shown.label {
+ // Settings entries drop the trailing ellipsis, as when the menu was built
+ mi.set_text(if it.id.starts_with("app.settings.") { it.label.trim_end_matches('…') } else { &it.label });
+ }
+ if it.shortcut != shown.shortcut {
let _ = mi.set_accelerator(it.shortcut.as_deref().and_then(accel));
}
+ if it.enabled != shown.enabled {
+ mi.set_enabled(it.enabled);
+ }
+ *shown = it.clone();
}
});
(rx, update)
diff --cc crates/ui-egui/src/lib.rs
index 15ab591e0,a5acdb115..9a5f923d5
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@@ -116,11 -126,11 +126,12 @@@ pub struct HostHooks
pub cursor_screen_position: Option<Box<dyn Fn() -> Option<(i32, i32)>>>,
pub pick_save: Option<Box<dyn FnMut(&str) -> Option<String>>>,
pub pick_open_project: Option<Box<dyn FnMut() -> Option<String>>>,
- /// Save dialog with a filter: (filter name, extensions, suggested file name) → path.
+ /// Save dialog with a filter: (filter name, extensions, suggested file name) → path. The
+ /// suggestion may be a full path, and the dialog then starts in its folder.
pub pick_save_as: Option<Box<dyn FnMut(&str, &[&str], &str) -> Option<String>>>,
- /// The active keyboard shortcuts changed: update native menu key equivalents.
- pub shortcuts_changed: Option<Box<dyn FnMut(&[menus::MenuItem])>>,
+ /// The menu tree changed (labels, shortcuts, enablement, checkmarks): update the native menu
+ /// bar. Called from the frame loop only when something differs from the last call.
+ pub menu_changed: Option<Box<dyn FnMut(&[menus::MenuItem])>>,
/// The user's preferred languages (locale tags, most preferred first) for Interface Language ▸
/// System Language. Without it, System Language is English.
pub system_languages: Option<Box<dyn Fn() -> Vec<String>>>,
@@@ -547,9 -576,9 +579,10 @@@ impl FilmcraftApp
last_time: 0.0,
bindings: Vec::new(),
bindings_rev: 0,
+ menu_sent: Vec::new(),
shortcut_editor: Default::default(),
toast: None,
+ graphics_notice: None,
tl: Default::default(),
command_inbox: None,
v_down: false,
@@@ -1664,8 -1718,8 +1731,9 @@@
}
self.command_inbox = Some(rx);
}
+ self.begin_press(&ctx);
self.handle_shortcuts(&ctx);
+ self.sync_native_menu();
self.advance_playback(&ctx);
self.advance_source_playback(&ctx);
self.scrub_audio(&ctx);