Skip to content

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

feat: startup update prompt modal and direct self-updating (#3298)

Dylan M. Taylordf106680d494
diff --git a/Cargo.lock b/Cargo.lock
index fc310ce21..e2836ad35 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -717,7 +717,7 @@ dependencies = [
"safetensors",
"thiserror 2.0.21",
"yoke",
- "zip",
+ "zip 7.2.0",
]
[[package]]
@@ -1029,6 +1029,31 @@ dependencies = [
"serde",
]
+[[package]]
+name = "craft-update"
+version = "0.1.0"
+source = "git+https://github.com/storytold/craft-libs?rev=db19c373c8d59a545972ca340987aecfb3611a4b#db19c373c8d59a545972ca340987aecfb3611a4b"
+dependencies = [
+ "chrono",
+ "dunce",
+ "egui",
+ "flate2",
+ "getrandom 0.3.4",
+ "log",
+ "plist",
+ "semver",
+ "serde",
+ "serde_json",
+ "sha2",
+ "tar",
+ "tempfile",
+ "ureq",
+ "verifysign",
+ "winreg",
+ "winsafe",
+ "zip 9.1.0",
+]
+
[[package]]
name = "crc32fast"
version = "1.5.2"
@@ -1193,6 +1218,12 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "deranged"
+version = "0.5.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
+
[[package]]
name = "digest"
version = "0.10.7"
@@ -1253,6 +1284,12 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
+[[package]]
+name = "dunce"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
+
[[package]]
name = "dyn-clone"
version = "1.0.20"
@@ -1582,7 +1619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -1679,6 +1716,16 @@ dependencies = [
"rustc_version",
]
+[[package]]
+name = "filetime"
+version = "0.2.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759"
+dependencies = [
+ "cfg-if",
+ "libc",
+]
+
[[package]]
name = "filmcraft"
version = "0.13.0"
@@ -1686,6 +1733,7 @@ dependencies = [
"arboard",
"chrono",
"cpal",
+ "craft-update",
"eframe",
"egui",
"filmcraft-engine",
@@ -2322,7 +2370,7 @@ dependencies = [
"serde_json",
"sha2",
"thiserror 2.0.21",
- "zip",
+ "zip 7.2.0",
]
[[package]]
@@ -2339,6 +2387,7 @@ version = "0.13.0"
dependencies = [
"cpu-time",
"craft-ui",
+ "craft-update",
"eframe",
"egui",
"egui_kittest",
@@ -2833,8 +2882,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"r-efi 6.0.0",
+ "wasm-bindgen",
]
[[package]]
@@ -3693,7 +3744,7 @@ dependencies = [
"once_cell",
"png",
"thiserror 2.0.21",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -3770,6 +3821,18 @@ dependencies = [
"jni-sys 0.3.1",
]
+[[package]]
+name = "nix"
+version = "0.31.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
+dependencies = [
+ "bitflags 2.13.2",
+ "cfg-if",
+ "cfg_aliases",
+ "libc",
+]
+
[[package]]
name = "nohash-hasher"
version = "0.2.0"
@@ -3811,6 +3874,12 @@ dependencies = [
"num-traits",
]
+[[package]]
+name = "num-conv"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
+
[[package]]
name = "num-derive"
version = "0.4.2"
@@ -4345,7 +4414,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.45.0",
]
[[package]]
@@ -4601,6 +4670,19 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
+[[package]]
+name = "plist"
+version = "1.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "327a4cb2ad49dc48adfdc9da89e22c64d488b508c67a044d71ba729e4521a285"
+dependencies = [
+ "base64 0.23.1",
+ "indexmap",
+ "quick-xml 0.42.0",
+ "serde",
+ "time",
+]
+
[[package]]
name = "png"
version = "0.18.1"
@@ -4687,6 +4769,12 @@ dependencies = [
"portable-atomic",
]
+[[package]]
+name = "powerfmt"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958"
+
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -4848,6 +4936,15 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "quick-xml"
+version = "0.42.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41b1177fdf999d2321d3fb46ff47159d9c1fb9ad66a4879f8c50a0b504615e9b"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "quote"
version = "1.0.47"
@@ -5235,7 +5332,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5246,6 +5343,7 @@ checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634"
dependencies = [
"log",
"once_cell",
+ "ring",
"rustls-pki-types",
"rustls-webpki 0.103.15",
"subtle",
@@ -5291,7 +5389,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5485,6 +5583,10 @@ name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
+dependencies = [
+ "serde",
+ "serde_core",
+]
[[package]]
name = "send_wrapper"
@@ -5756,7 +5858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6045,6 +6147,16 @@ dependencies = [
"version-compare",
]
+[[package]]
+name = "tar"
+version = "0.4.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840"
+dependencies = [
+ "filetime",
+ "libc",
+]
+
[[package]]
name = "target-lexicon"
version = "0.12.16"
@@ -6061,7 +6173,7 @@ dependencies = [
"getrandom 0.4.3",
"once_cell",
"rustix 1.1.5",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6127,6 +6239,36 @@ dependencies = [
"zune-jpeg",
]
+[[package]]
+name = "time"
+version = "0.3.55"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
+dependencies = [
+ "deranged",
+ "num-conv",
+ "powerfmt",
+ "serde_core",
+ "time-core",
+ "time-macros",
+]
+
+[[package]]
+name = "time-core"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
+
+[[package]]
+name = "time-macros"
+version = "0.2.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85"
+dependencies = [
+ "num-conv",
+ "time-core",
+]
+
[[package]]
name = "tokio"
version = "1.53.1"
@@ -6321,6 +6463,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e"
+[[package]]
+name = "typed-path"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
+
[[package]]
name = "typenum"
version = "1.20.1"
@@ -6335,7 +6483,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
dependencies = [
"memoffset",
"tempfile",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6409,6 +6557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a7ac20be9b7726e0bbdbf974c059676d9acb1cd414961f570a4e8231cacd7fc"
dependencies = [
"base64 0.23.1",
+ "flate2",
"log",
"percent-encoding",
"rustls",
@@ -6475,6 +6624,16 @@ dependencies = [
"vello_common",
]
+[[package]]
+name = "verifysign"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6acfcc42a8d44f340d001193d97ef56bf33210b51ad760ae8308c97d5241ca51"
+dependencies = [
+ "core-foundation 0.10.1",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "version-compare"
version = "0.2.1"
@@ -6696,7 +6855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0"
dependencies = [
"proc-macro2",
- "quick-xml",
+ "quick-xml 0.41.0",
"quote",
]
@@ -6952,7 +7111,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -7399,6 +7558,16 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "winreg"
+version = "0.55.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97"
+dependencies = [
+ "cfg-if",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "winresource"
version = "0.1.31"
@@ -7409,6 +7578,12 @@ dependencies = [
"version_check",
]
+[[package]]
+name = "winsafe"
+version = "0.0.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ef0ffc427f045c0cc9ebffd6f4f91153dcd2a1547b5c3c29ee3f541e16e95c6"
+
[[package]]
name = "wit-bindgen"
version = "0.57.1"
@@ -7714,7 +7889,24 @@ dependencies = [
"crc32fast",
"indexmap",
"memchr",
- "typed-path",
+ "typed-path 0.12.3",
+]
+
+[[package]]
+name = "zip"
+version = "9.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704"
+dependencies = [
+ "crc32fast",
+ "flate2",
+ "getrandom 0.4.3",
+ "indexmap",
+ "memchr",
+ "nix",
+ "typed-path 0.13.0",
+ "windows-sys 0.61.2",
+ "zopfli",
]
[[package]]
@@ -7729,6 +7921,18 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+[[package]]
+name = "zopfli"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11"
+dependencies = [
+ "bumpalo",
+ "crc32fast",
+ "log",
+ "simd-adler32",
+]
+
[[package]]
name = "zune-core"
version = "0.5.3"
diff --git a/Cargo.toml b/Cargo.toml
index c38391240..1c4e16ff1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -84,6 +84,7 @@ craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs",
egui = { version = "0.37", features = ["default_fonts", "monochrome_emoji_fonts"] }
eframe = { version = "0.37", default-features = false }
egui_kittest = "0.37"
+craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "db19c373c8d59a545972ca340987aecfb3611a4b", features = ["egui"] }
rfd = "0.17"
[workspace.lints.rust]
diff --git a/apps/filmcraft/Cargo.toml b/apps/filmcraft/Cargo.toml
index 7db181b39..2cf5669e5 100644
--- a/apps/filmcraft/Cargo.toml
+++ b/apps/filmcraft/Cargo.toml
@@ -62,3 +62,6 @@ zbus = "5.19"
# Icon + VERSIONINFO for filmcraft.exe (build.rs); only needed when building on Windows.
[target.'cfg(windows)'.build-dependencies]
winresource = "0.1"
+
+[target.'cfg(windows)'.dependencies]
+craft-update = { workspace = true }
diff --git a/apps/filmcraft/src/main.rs b/apps/filmcraft/src/main.rs
index 2f2b6f818..ec9d083ce 100644
--- a/apps/filmcraft/src/main.rs
+++ b/apps/filmcraft/src/main.rs
@@ -78,6 +78,11 @@ fn tell(text: &str, error: bool) {
}
fn main() -> eframe::Result {
+ // Windows: the update helper is a copy of this program started with `--finish-update`.
+ #[cfg(windows)]
+ if let Some(result) = craft_update::self_update::finish(&craft_update::suite::FILMCRAFT, &std::env::args_os().skip(1).collect::<Vec<_>>()) {
+ std::process::exit(i32::from(result.is_err()));
+ }
// First, so the panic hook and every start-up record are logged (`logging`).
let logger = logging::install();
// lossy, so a value that is not Unicode is reported like any other bad port instead of ignored
@@ -249,6 +254,7 @@ fn app_creator(launch: Launch, graphics: graphics::GraphicsStart, created: Arc<A
}
}
let mut app = FilmcraftApp::new(session);
+ app.set_startup_update_check(true);
app.graphics_notice = notice;
if recover == Some(false) {
app.dialog = None;
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index aaaccf5e7..730b48f19 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -62,3 +62,6 @@ tempfile = "3"
[build-dependencies]
serde_json = { workspace = true }
toml = "1"
+
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
+craft-update = { workspace = true }
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 01c3d57a2..dc45982b1 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -63,6 +63,7 @@ pub mod source_playback;
pub mod state;
pub mod theme;
mod theme_favorites;
+pub mod updates_ui;
pub mod widgets;
use std::collections::HashMap;
@@ -302,6 +303,7 @@ pub struct FilmcraftApp {
pub scrub: scrub::ScrubAudio,
pub hooks: HostHooks,
pub dialog: Option<Dialog>,
+ pub(crate) updates_rt: updates_ui::Runtime,
pub file_dialogs: panels::file_dialogs::FileDialogState,
/// The native file dialog the host is showing ([`Self::pick`]).
native_dialog: Option<native_dialogs::PendingDialog>,
@@ -631,6 +633,7 @@ impl FilmcraftApp {
hooks: HostHooks::default(),
// Unsaved changes left by a session that died are offered first thing.
dialog: recovery.then_some(Dialog::Recovery),
+ updates_rt: Default::default(),
file_dialogs: Default::default(),
native_dialog: None,
auto: Default::default(),
@@ -2127,6 +2130,7 @@ impl FilmcraftApp {
// the Timeline has had its chance to place a file drop this frame; anything left stays a bin import
self.pending_timeline_drop = None;
panels::dialogs::show(self, &ctx);
+ updates_ui::show(self, &ctx);
if !self.ui.show_status_bar {
return;
}
@@ -2426,6 +2430,7 @@ impl FilmcraftApp {
ctx.request_repaint_after(std::time::Duration::from_secs(1));
}
self.sync_pool();
+ updates_ui::tick(self, ctx);
#[cfg(not(target_arch = "wasm32"))]
self.tick_media_refresh(ctx, now);
}
diff --git a/crates/ui-egui/src/links.rs b/crates/ui-egui/src/links.rs
index 1053b16eb..da4fa7242 100644
--- a/crates/ui-egui/src/links.rs
+++ b/crates/ui-egui/src/links.rs
@@ -50,6 +50,7 @@ pub fn menu_hint(command: &str) -> Option<String> {
"help.revealLogFiles" => tl!("Saves this session's log and shows it in your file manager."),
"help.systemCompatibilityReport" => tl!("Shows a report on this computer."),
"app.about" => tl!("Shows the version, community links and credits in a FilmCraft window."),
+ "app.checkForUpdates" => tl!("Looks for a newer FilmCraft release and offers to update."),
_ => return None,
}
.to_string(),
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 3700e749e..c9a5c9cd5 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -146,6 +146,7 @@ pub const UI_COMMANDS: &[UiCommand] = &[
uic!("help.reportIssue", "Report an Issue…", ["Help"], None),
uic!("help.revealLogFiles", "Reveal Log Files…", ["Help"], None),
uic!("help.systemCompatibilityReport", "System Compatibility Report…", ["Help"], None),
+ uic!("app.checkForUpdates", "Check for Updates…", ["Help"], None),
uic!("app.about", "About FilmCraft", ["Help"], None),
uic!("app.keyboardShortcuts", "Keyboard Shortcuts…", ["Edit"], Some("Cmd+Alt+K")),
uic!("app.settings.general", "General…", ["Edit", "Preferences"], Some("Cmd+,")),
@@ -444,6 +445,10 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, mut params:
app.ui.mode = Mode::Export;
return Ok(Value::Null);
}
+ "app.checkForUpdates" => {
+ let _ = crate::updates_ui::check(app);
+ return Ok(serde_json::Value::Null);
+ }
"app.about" => {
app.dialog = Some(crate::Dialog::About);
return Ok(Value::Null);
diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs
new file mode 100644
index 000000000..9fcfc065f
--- /dev/null
+++ b/crates/ui-egui/src/updates_ui.rs
@@ -0,0 +1,170 @@
+//! Software updates, background check at startup, and startup prompt modal.
+
+use serde_json::Value;
+
+use crate::FilmcraftApp;
+
+#[cfg(not(target_arch = "wasm32"))]
+use craft_update::updater::{Action, Status, Updater};
+
+pub(crate) struct Runtime {
+ #[cfg(not(target_arch = "wasm32"))]
+ updater: Updater,
+ /// The desktop app turns the check at start on; tests and the web build leave it off.
+ #[cfg(not(target_arch = "wasm32"))]
+ startup_check: bool,
+ #[cfg(not(target_arch = "wasm32"))]
+ check_requested: bool,
+ /// The context of the last frame, to wake the UI when a check is queued from a menu callback.
+ #[cfg(not(target_arch = "wasm32"))]
+ repaint: Option<egui::Context>,
+ pub(crate) manual_window_open: bool,
+ pub(crate) status_message: Option<String>,
+}
+
+impl Default for Runtime {
+ fn default() -> Self {
+ Self {
+ #[cfg(not(target_arch = "wasm32"))]
+ updater: Updater::new(&craft_update::suite::FILMCRAFT, env!("CARGO_PKG_VERSION")),
+ #[cfg(not(target_arch = "wasm32"))]
+ startup_check: false,
+ #[cfg(not(target_arch = "wasm32"))]
+ check_requested: false,
+ #[cfg(not(target_arch = "wasm32"))]
+ repaint: None,
+ manual_window_open: false,
+ status_message: None,
+ }
+ }
+}
+
+impl FilmcraftApp {
+ /// Whether the app asks for a newer release when it starts (off until the desktop app turns it on).
+ #[cfg(not(target_arch = "wasm32"))]
+ pub fn set_startup_update_check(&mut self, on: bool) {
+ self.updates_rt.startup_check = on;
+ }
+}
+
+pub(crate) fn check(app: &mut FilmcraftApp) -> Result<Value, String> {
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ app.updates_rt.check_requested = true;
+ if let Some(ctx) = &app.updates_rt.repaint {
+ ctx.request_repaint();
+ }
+ Ok(Value::Null)
+ }
+ #[cfg(target_arch = "wasm32")]
+ {
+ app.updates_rt.manual_window_open = true;
+ app.updates_rt.status_message = Some("Update check is not supported in the web browser.".into());
+ Ok(Value::Null)
+ }
+}
+
+pub(crate) fn tick(app: &mut FilmcraftApp, ctx: &egui::Context) {
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ let rt = &mut app.updates_rt;
+ rt.repaint = Some(ctx.clone());
+ if std::mem::take(&mut rt.check_requested) {
+ rt.updater.check_now(ctx);
+ } else if rt.startup_check {
+ rt.updater.check_at_start(ctx);
+ }
+ rt.updater.tick(ctx);
+ }
+ #[cfg(target_arch = "wasm32")]
+ let _ = (app, ctx);
+}
+
+pub(crate) fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ // The restart helper is scheduled before the app closes, so no update starts over unsaved work.
+ let clean = !app.session.is_dirty();
+ match app.updates_rt.updater.show_if(ctx, clean) {
+ Action::OpenUrl(url) => crate::links::open(app, ctx, &url),
+ Action::Close => ctx.send_viewport_cmd(egui::ViewportCommand::Close),
+ Action::None => {}
+ }
+ // The window answers Help ▸ Check for Updates, so it follows the updater's status.
+ let rt = &mut app.updates_rt;
+ (rt.manual_window_open, rt.status_message) = match rt.updater.status() {
+ Status::Idle => (false, None),
+ Status::Checking => (true, Some(tl!("Checking for updates…").to_string())),
+ Status::UpToDate => {
+ (true, Some(tl!("FilmCraft {version} is currently the newest version available.").replace("{version}", env!("CARGO_PKG_VERSION"))))
+ }
+ Status::Failed(e) => (true, Some(tl!("Could not check for updates:\n{error}").replace("{error}", e))),
+ };
+ }
+
+ if app.updates_rt.manual_window_open {
+ let mut open = true;
+ egui::Window::new(crate::i18n::t("FilmCraft Updates"))
+ .open(&mut open)
+ .collapsible(false)
+ .resizable(false)
+ .pivot(egui::Align2::CENTER_CENTER)
+ .default_pos(ctx.content_rect().center())
+ .show(ctx, |ui| {
+ if let Some(msg) = &app.updates_rt.status_message {
+ ui.label(msg);
+ }
+ ui.add_space(8.0);
+ if ui.button(crate::i18n::t("OK")).clicked() {
+ app.updates_rt.manual_window_open = false;
+ }
+ });
+ if !open {
+ app.updates_rt.manual_window_open = false;
+ }
+ }
+
+ // Closing the window dismisses the outcome it showed.
+ #[cfg(not(target_arch = "wasm32"))]
+ if !app.updates_rt.manual_window_open {
+ app.updates_rt.updater.dismiss_status();
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn default_runtime_is_idle() {
+ let rt = Runtime::default();
+ assert!(!rt.manual_window_open);
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ assert!(!rt.startup_check);
+ assert!(!rt.updater.prompt_open());
+ assert_eq!(rt.updater.status(), &Status::Idle);
+ }
+ }
+
+ #[test]
+ #[cfg(not(target_arch = "wasm32"))]
+ fn startup_prompt_shows_and_closes() {
+ let mut app = FilmcraftApp::new(filmcraft_engine::Session::default());
+ let ctx = egui::Context::default();
+ let release = craft_update::Release {
+ tag: "v99.0.0".into(),
+ version: craft_update::parse_version("99.0.0"),
+ name: "FilmCraft 99.0.0".into(),
+ html_url: "https://github.com/storytold/filmcraft/releases/tag/v99.0.0".into(),
+ ..Default::default()
+ };
+ app.updates_rt.updater.offer(release);
+
+ let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
+ show(&mut app, ui.ctx());
+ });
+ output.textures_delta.clear();
+ assert!(app.updates_rt.updater.prompt_open());
+ }
+}