From a8e089735fcee9f996d398db6dddcec2207c8c2e Mon Sep 17 00:00:00 2001 From: Mehfuz Hossain Date: Fri, 13 Nov 2026 16:45:40 -0800 Subject: [PATCH 1/2] Export: share link status shows at once, from what this computer last knew The note under the project's link waited for the server's list of links (about a second). Projects with a video behind their link are now kept in shared-projects in the config folder, so the dialog opens with the right note; the server's answer corrects it in the background. --- apps/studio/src/export.rs | 11 +++++++--- apps/studio/src/share.rs | 44 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/apps/studio/src/export.rs b/apps/studio/src/export.rs index efb1062..b9d9504 100644 --- a/apps/studio/src/export.rs +++ b/apps/studio/src/export.rs @@ -303,8 +303,10 @@ impl ExportDialog { if let Ok(link) = r { // a link made before ids were derived from the project counts as // nothing uploaded: the next share moves the project to its own link - let own = crate::share::link_url(self.project_link_for.as_deref().unwrap_or_default()); + let asked = self.project_link_for.clone().unwrap_or_default(); + let own = crate::share::link_url(&asked); self.project_link = link.filter(|l| *l == own); + crate::share::remember_uploaded(&asked, self.project_link.is_some()); self.project_link_known = true; } } @@ -640,14 +642,17 @@ impl ExportDialog { self.last_link.clone().and_then(Result::ok) } - /// Whether a video is behind the link (None: not known yet). + /// Whether a video is behind the link: the server's answer, or until it comes what this + /// computer last knew (so the dialog does not change as it opens). fn uploaded(&self) -> Option { if matches!(self.last_link, Some(Ok(_))) || self.project_link.is_some() { Some(true) } else if self.project_link_known { Some(false) - } else { + } else if self.project_id.is_empty() { None + } else { + Some(crate::share::known_uploaded(&self.project_id)) } } diff --git a/apps/studio/src/share.rs b/apps/studio/src/share.rs index 4e96040..3b3f32b 100644 --- a/apps/studio/src/share.rs +++ b/apps/studio/src/share.rs @@ -250,8 +250,9 @@ fn upload(project: &Path, video: &Path, title: &str, (width, height, duration_ms let mut req = auth.clone(); req["action"] = "create".into(); // the project's one link (the server reuses it) - if let Ok(pkg) = sf_project::ProjectPackage::open(project) { - req["project"] = pkg.project.id.into(); + let project_id = sf_project::ProjectPackage::open(project).ok().map(|pkg| pkg.project.id); + if let Some(id) = &project_id { + req["project"] = id.clone().into(); } req["title"] = title.into(); req["bytes"] = bytes.into(); @@ -281,7 +282,44 @@ fn upload(project: &Path, video: &Path, title: &str, (width, height, duration_ms req["action"] = "complete".into(); req["id"] = id.into(); let done = call(req)?; - done["url"].as_str().map(String::from).ok_or_else(|| "The share server sent no link.".into()) + let url = done["url"].as_str().map(String::from).ok_or("The share server sent no link.")?; + if let Some(id) = &project_id { + remember_uploaded(id, true); + } + Ok(url) +} + +/// Projects this computer knows have a video behind their link, so Export says so as it opens +/// instead of after asking the server (which corrects it in the background). Kept on disk. +static UPLOADED: std::sync::Mutex>> = std::sync::Mutex::new(None); + +fn uploaded_file() -> Option { + setting_file().map(|f| f.with_file_name("shared-projects")) +} + +/// Whether this project's link has a video, as last known on this computer. +pub fn known_uploaded(project: &str) -> bool { + let mut set = UPLOADED.lock().unwrap_or_else(|e| e.into_inner()); + set.get_or_insert_with(|| uploaded_file().and_then(|f| std::fs::read_to_string(f).ok()).map(|s| s.lines().map(str::to_string).collect()).unwrap_or_default()).contains(project) +} + +pub fn remember_uploaded(project: &str, uploaded: bool) { + if known_uploaded(project) == uploaded { + return; + } + let mut guard = UPLOADED.lock().unwrap_or_else(|e| e.into_inner()); + let set = guard.get_or_insert_with(Default::default); + if uploaded { + set.insert(project.to_string()); + } else { + set.remove(project); + } + if let Some(f) = uploaded_file() { + let _ = std::fs::create_dir_all(f.parent().unwrap()); + let mut lines: Vec<&str> = set.iter().map(String::as_str).collect(); + lines.sort(); + let _ = std::fs::write(f, lines.join("\n")); + } } /// The video file as the upload body, reporting progress and stopping when cancelled. From 33cf883d5e1e1d31e138483379fb696ff7d90437 Mon Sep 17 00:00:00 2001 From: Mehfuz Hossain Date: Fri, 13 Nov 2026 16:47:44 -0800 Subject: [PATCH 2/2] Export: one fixed note under the share link The note under the project's link changed with what was known about its upload. It is now the same sentence everywhere (settings and the progress dialog). The app no longer asks the server for its links or keeps an uploaded-projects cache: the link is derived from the project id. --- apps/studio/src/export.rs | 104 +++++--------------------------------- apps/studio/src/share.rs | 79 ----------------------------- 2 files changed, 12 insertions(+), 171 deletions(-) diff --git a/apps/studio/src/export.rs b/apps/studio/src/export.rs index b9d9504..b211201 100644 --- a/apps/studio/src/export.rs +++ b/apps/studio/src/export.rs @@ -87,18 +87,11 @@ pub struct ExportDialog { share_with_export: bool, /// The running or finished export makes a link too: step 2 of the progress dialog. export_shared: bool, - /// This project's link as the server has it (one per project), shown whenever the dialog - /// is open; asked again each time it opens. `project_link_for`: the project asked about. - project_link: Option, - /// Whether the server has answered for this project (so "nothing uploaded yet" is known). - project_link_known: bool, - project_link_for: Option, /// The editor's project id (set by the editor every frame): its link is known without /// asking the server (`share::link_url`). pub project_id: String, /// The QR code under the link is showing. qr_open: bool, - project_link_rx: Option, String>>>, } /// An empty dialog: no file reads, no network. `std::mem::take` puts one in place every frame @@ -106,7 +99,7 @@ pub struct ExportDialog { /// that loads the license and talks to the backend. impl Default for ExportDialog { fn default() -> Self { - ExportDialog { open: false, license: sf_license::Status::Invalid("no key".into()), email: String::new(), activation: None, check_in: None, activation_msg: None, code_sent_to: None, code: String::new(), signing_in: false, promo: String::new(), promo_open: false, checkout: None, claim_until: None, next_claim: None, claim: None, free_left: None, free_rx: None, was_open: false, license_seen: 0, free_job: false, format: Format::Mp4, fps: 60.0, height: 1080, quality: QualityPreset::SocialMedia, codec: VideoCodec::H264, audio: true, job: None, progress: None, result: None, started: None, share_request: None, share_running: None, share_cancel: false, last_link: None, share_with_export: false, export_shared: false, project_link: None, project_link_known: false, project_link_for: None, project_id: String::new(), qr_open: false, project_link_rx: None } + ExportDialog { open: false, license: sf_license::Status::Invalid("no key".into()), email: String::new(), activation: None, check_in: None, activation_msg: None, code_sent_to: None, code: String::new(), signing_in: false, promo: String::new(), promo_open: false, checkout: None, claim_until: None, next_claim: None, claim: None, free_left: None, free_rx: None, was_open: false, license_seen: 0, free_job: false, format: Format::Mp4, fps: 60.0, height: 1080, quality: QualityPreset::SocialMedia, codec: VideoCodec::H264, audio: true, job: None, progress: None, result: None, started: None, share_request: None, share_running: None, share_cancel: false, last_link: None, share_with_export: false, export_shared: false, project_id: String::new(), qr_open: false } } } @@ -289,31 +282,7 @@ impl ExportDialog { self.license = sf_license::load_saved().map(|k| sf_license::verify(&k)).unwrap_or_else(|| sf_license::Status::Invalid("no key".into())); } self.poll_checkout(ctx); - if self.open && !self.was_open { - // asked again (the link may have been made or deleted elsewhere); the last answer - // shows meanwhile - self.project_link_for = None; - } self.poll_free_exports(ctx); - if let Some(rx) = &self.project_link_rx { - match rx.try_recv() { - Ok(r) => { - self.project_link_rx = None; - // offline or a server error: keep what was shown - if let Ok(link) = r { - // a link made before ids were derived from the project counts as - // nothing uploaded: the next share moves the project to its own link - let asked = self.project_link_for.clone().unwrap_or_default(); - let own = crate::share::link_url(&asked); - self.project_link = link.filter(|l| *l == own); - crate::share::remember_uploaded(&asked, self.project_link.is_some()); - self.project_link_known = true; - } - } - Err(std::sync::mpsc::TryRecvError::Empty) => ctx.request_repaint_after(std::time::Duration::from_millis(200)), - Err(std::sync::mpsc::TryRecvError::Disconnected) => self.project_link_rx = None, - } - } if let Some(rx) = &self.check_in { match rx.try_recv() { Ok(r) => { @@ -485,9 +454,9 @@ impl ExportDialog { } }); - // 2. its share link: made by this export, or the project's link from before (shown - // so it is always at hand, with its QR code) - if sharing || (crate::share::allowed() && self.uploaded() == Some(true)) { + // 2. the project's share link, always at hand (with its QR code); this export puts its + // video behind it with "Make a share link too" + if sharing || crate::share::allowed() { ui.add_space(10.0); let state = match (&self.share_running, &self.last_link) { _ if !sharing => StepState::Done, @@ -499,19 +468,8 @@ impl ExportDialog { let pct = self.share_running.as_ref().map(|(f, _)| format!("{:.0}%", f * 100.0)); step_header(ui, 2, "Share link", state, pct); step_body(ui, |ui| { - if sharing && exporting { - // the link is known already: it can be copied (or scanned) while this runs - if let Some(url) = self.shown_link() { - widgets::link_field_qr(ui, &url, &mut self.qr_open); - ui.add_space(6.0); - } - widgets::hint(ui, "Uploads when the video is ready."); - } else { - self.link_status_ui(ui); - if !sharing { - widgets::hint(ui, "Plays the last video shared from this project: export with \u{201c}Make a share link too\u{201d} to update it."); - } - } + self.link_status_ui(ui); + widgets::hint(ui, LINK_HINT); }); } @@ -586,26 +544,6 @@ impl ExportDialog { crate::share::ShareSettings { fps, max_height, quality, include_audio: self.audio } } - /// Ask the server for this project's link, once per open of the dialog. - fn ask_project_link(&mut self, project: &str) { - if self.project_link_for.as_deref() == Some(project) { - return; - } - if self.project_link_for.as_deref().is_some_and(|p| p != project) { - // another project's link must not show while this one's is asked for - self.project_link = None; - self.project_link_known = false; - } - self.project_link_for = Some(project.to_string()); - let (tx, rx) = channel(); - let id = project.to_string(); - std::thread::spawn(move || { - let _ = tx.send(crate::share::project_link(&id)); - }); - self.project_link_rx = Some(rx); - } - - /// The share being made (progress bar and Cancel), or the project's link in a text box /// (copy, open), or why it failed. fn link_status_ui(&mut self, ui: &mut egui::Ui) { @@ -625,11 +563,9 @@ impl ExportDialog { } }); }); - widgets::hint(ui, if self.uploaded() == Some(true) { "The link plays the previous video until this upload finishes." } else { "Copy the link now: it plays the video once the upload finishes." }); + ui.add_space(4.0); } else if let Some(Err(e)) = self.last_link.clone() { ui.add(egui::Label::new(RichText::new(format!("The upload failed: {e}")).size(13.0).color(pal.danger)).wrap()); - } else if self.uploaded() == Some(false) { - widgets::hint(ui, "Nothing is uploaded yet: export with \u{201c}Make a share link too\u{201d} to put this video behind the link."); } } @@ -642,20 +578,6 @@ impl ExportDialog { self.last_link.clone().and_then(Result::ok) } - /// Whether a video is behind the link: the server's answer, or until it comes what this - /// computer last knew (so the dialog does not change as it opens). - fn uploaded(&self) -> Option { - if matches!(self.last_link, Some(Ok(_))) || self.project_link.is_some() { - Some(true) - } else if self.project_link_known { - Some(false) - } else if self.project_id.is_empty() { - None - } else { - Some(crate::share::known_uploaded(&self.project_id)) - } - } - /// Cloud share links (Pro): made by Export with "Make a share link too"; others see what /// it is. fn share_ui(&mut self, ui: &mut egui::Ui) { @@ -672,11 +594,9 @@ impl ExportDialog { ui.separator(); return; } - // the project's one link, always: exporting with the box ticked puts the video behind it + // the project's one link, always, with the same words whatever is uploaded self.link_status_ui(ui); - if self.share_running.is_none() && self.uploaded() == Some(true) && !matches!(self.last_link, Some(Err(_))) { - widgets::hint(ui, "This project's link. Export with \u{201c}Make a share link too\u{201d} to update its video."); - } + widgets::hint(ui, LINK_HINT); ui.add_space(2.0); if ui.checkbox(&mut self.share_with_export, "Make a share link too").on_hover_text("Export uploads the video it writes and copies a link anyone can watch").changed() { crate::share::set_with_export(self.share_with_export); @@ -775,9 +695,6 @@ impl ExportDialog { ui.separator(); } if self.license.is_valid() { - if crate::share::allowed() { - self.ask_project_link(&ed.session.pkg.project.id); - } self.share_ui(ui); } widgets::title(ui, "Format"); @@ -913,6 +830,9 @@ enum StepState { Failed, } +/// The one note under a project's share link, the same whatever is uploaded. +const LINK_HINT: &str = "This project's link. Export with \u{201c}Make a share link too\u{201d} to put the latest video behind it."; + /// A numbered step of the export dialog: its marker (number, or a check once done), its name, /// and on the right its percentage while it runs. fn step_header(ui: &mut egui::Ui, n: u32, name: &str, state: StepState, right: Option) { diff --git a/apps/studio/src/share.rs b/apps/studio/src/share.rs index 3b3f32b..0a3a4ba 100644 --- a/apps/studio/src/share.rs +++ b/apps/studio/src/share.rs @@ -283,45 +283,9 @@ fn upload(project: &Path, video: &Path, title: &str, (width, height, duration_ms req["id"] = id.into(); let done = call(req)?; let url = done["url"].as_str().map(String::from).ok_or("The share server sent no link.")?; - if let Some(id) = &project_id { - remember_uploaded(id, true); - } Ok(url) } -/// Projects this computer knows have a video behind their link, so Export says so as it opens -/// instead of after asking the server (which corrects it in the background). Kept on disk. -static UPLOADED: std::sync::Mutex>> = std::sync::Mutex::new(None); - -fn uploaded_file() -> Option { - setting_file().map(|f| f.with_file_name("shared-projects")) -} - -/// Whether this project's link has a video, as last known on this computer. -pub fn known_uploaded(project: &str) -> bool { - let mut set = UPLOADED.lock().unwrap_or_else(|e| e.into_inner()); - set.get_or_insert_with(|| uploaded_file().and_then(|f| std::fs::read_to_string(f).ok()).map(|s| s.lines().map(str::to_string).collect()).unwrap_or_default()).contains(project) -} - -pub fn remember_uploaded(project: &str, uploaded: bool) { - if known_uploaded(project) == uploaded { - return; - } - let mut guard = UPLOADED.lock().unwrap_or_else(|e| e.into_inner()); - let set = guard.get_or_insert_with(Default::default); - if uploaded { - set.insert(project.to_string()); - } else { - set.remove(project); - } - if let Some(f) = uploaded_file() { - let _ = std::fs::create_dir_all(f.parent().unwrap()); - let mut lines: Vec<&str> = set.iter().map(String::as_str).collect(); - lines.sort(); - let _ = std::fs::write(f, lines.join("\n")); - } -} - /// The video file as the upload body, reporting progress and stopping when cancelled. struct Counting<'a> { inner: std::fs::File, @@ -347,34 +311,6 @@ impl Read for Counting<'_> { } } -/// A link of this account, as `share` lists them. -#[derive(Clone, Debug)] -pub struct Link { - pub url: String, - /// The project (file id) the link belongs to: one link per project. - pub project: Option, -} - -/// This account's links, newest first. -pub fn list() -> Result, String> { - let mut req = sf_license::owner_auth().ok_or("Sign in to see your share links.")?; - req["action"] = "list".into(); - let r = call(req)?; - Ok(r["links"] - .as_array() - .map(|a| { - a.iter() - .filter_map(|l| { - Some(Link { - url: l["url"].as_str()?.into(), - project: l["project"].as_str().map(str::to_string), - }) - }) - .collect() - }) - .unwrap_or_default()) -} - /// The page a link id opens. pub const PAGE_URL: &str = "https://screenforge.studio/s/"; @@ -394,11 +330,6 @@ pub fn link_url(project: &str) -> String { format!("{PAGE_URL}{}", link_id(project)) } -/// The link of the project with this id, if it has one. -pub fn project_link(project: &str) -> Result, String> { - Ok(list()?.into_iter().find(|l| l.project.as_deref() == Some(project)).map(|l| l.url)) -} - /// Where "Make a share link too" is remembered (`allowed_file` sits next to it). fn setting_file() -> Option { directories::ProjectDirs::from("dev", "screenforge", "ScreenForge").map(|d| d.config_dir().join("share-with-export")) @@ -475,16 +406,6 @@ mod tests { assert_eq!(link_url("abc"), "https://screenforge.studio/s/LyVS9w6Jh3S9"); } - /// Against the live backend: the account's links, with the project each belongs to. - /// `cargo test -p studio list_shows_projects -- --ignored --nocapture` - #[test] - #[ignore] - fn list_shows_projects() { - for l in list().unwrap() { - println!("{} {:?}", l.url, l.project); - } - } - /// Against the live backend with this computer's license: one project, one link. /// `cargo test -p studio share_again_keeps_the_link -- --ignored` #[test]