From 66ea7101b9d03a70e67a7d7fbb9090caefc0f9f6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 16:15:24 -0500 Subject: [PATCH] pdf-shell-w8: net change of 3 commits - pdf-shell-w8: written from its sheet - pdf-shell-w8: repair 1 - pdf-shell-w8: review fixes (review-1) --- crates/ui-egui/build.rs | 30 +- crates/ui-egui/src/app/window.rs | 66 ++--- crates/ui-egui/src/credits_data.rs | 5 + crates/ui-egui/src/platform/updates.rs | 384 ++++++------------------- crates/ui-egui/src/viewer_prefs.rs | 4 +- 5 files changed, 140 insertions(+), 349 deletions(-) create mode 100644 crates/ui-egui/src/credits_data.rs diff --git a/crates/ui-egui/build.rs b/crates/ui-egui/build.rs index 5419126290..dbfa7b8bfd 100644 --- a/crates/ui-egui/build.rs +++ b/crates/ui-egui/build.rs @@ -117,11 +117,11 @@ fn read(path: &std::path::Path, fallback: &str, parse: impl Fn(&str) -> Resul r.ok() } -/// A non-empty string field of someone's people.toml entry, as a Rust `Option<&str>` literal. -fn name(v: Option<&str>) -> String { +/// A non-empty string field of someone's people.toml entry, as the builder call `.("..")`; nothing when empty. +fn name(method: &str, v: Option<&str>) -> String { match v.map(str::trim).filter(|s| !s.is_empty()) { - Some(x) => format!("Some({x:?})"), - None => "None".into(), + Some(x) => format!(".{method}({x:?})"), + None => String::new(), } } @@ -139,8 +139,9 @@ fn rows(json: &Value, k: &str) -> Vec { fn generate(json: &Value, people: &toml::Table) -> String { let mut o = String::new(); - let _ = writeln!(o, "pub static TOTAL_COMMITS: u64 = {};", n(json, "commits")); - let _ = writeln!(o, "pub static CONTRIBUTORS: &[Contributor] = &["); + let _ = writeln!(o, "/// The credits tables baked from contributors/contributors.json."); + let _ = writeln!(o, "pub(crate) fn credits() -> Credits {{"); + let _ = writeln!(o, " let contributors: Vec = vec!["); for c in rows(json, "contributors") { let login = c.get("login").and_then(Value::as_str).unwrap_or(""); if login.is_empty() { @@ -155,9 +156,10 @@ fn generate(json: &Value, people: &toml::Table) -> String { .or_else(|| if synced { c.get("github_name").and_then(Value::as_str) } else { None }); let _ = writeln!( o, - " Contributor {{ login: {login:?}, display_name: {}, real_name: {}, prs: {}, commits: {}, lines_added: {}, lines_deleted: {}, binary_added: {}, binary_deleted: {}, first_commit: {}, last_commit: {} }},", - name(display), - name(field("real_name")), + " Contributor::new({login:?}){}{}.profile({:?}).counts({}, {}).lines({}, {}).binary({}, {}).active({}, {}),", + name("display_name", display), + name("real_name", field("real_name")), + format!("https://github.com/{login}"), n(&c, "prs"), n(&c, "commits"), n(&c, "lines_added"), @@ -168,12 +170,12 @@ fn generate(json: &Value, people: &toml::Table) -> String { s(&c, "last_commit"), ); } - let _ = writeln!(o, "];"); - let _ = writeln!(o, "pub static MODELS: &[Model] = &["); + let _ = writeln!(o, " ];"); + let _ = writeln!(o, " let models: Vec = vec!["); for m in rows(json, "models") { let _ = writeln!( o, - " Model {{ company: {}, model: {}, version: {}, commits: {}, lines_added: {}, lines_deleted: {} }},", + " ModelCredit::new({}, {}, {}).work({}, {}, {}),", s(&m, "company"), s(&m, "model"), s(&m, "version"), @@ -182,6 +184,8 @@ fn generate(json: &Value, people: &toml::Table) -> String { n(&m, "lines_deleted"), ); } - let _ = writeln!(o, "];"); + let _ = writeln!(o, " ];"); + let _ = writeln!(o, " Credits::new(contributors, models, {})", n(json, "commits")); + let _ = writeln!(o, "}}"); o } diff --git a/crates/ui-egui/src/app/window.rs b/crates/ui-egui/src/app/window.rs index e7035b5000..bac5e621d3 100644 --- a/crates/ui-egui/src/app/window.rs +++ b/crates/ui-egui/src/app/window.rs @@ -1,47 +1,50 @@ use super::{PdfCraftApp, QuickTool}; +use craft::host::target::Backend; +use craft::ui::runtime::windows::WindowHost; +use craft::ui::shell::ScreenMode; +use craft::window::Prefix; +use craft::window::policy::{self, TitleBarPref}; +use pdfcraft_engine::DocId; impl PdfCraftApp { - /// Whether the app draws the window's title bar, buttons and resize edges: the desktop leaves - /// the frame to the app and Use system title bar is off. - pub fn draws_window_frame(&self) -> bool { - self.window_controls.is_some() && !self.system_title_bar + /// Follow Use system title bar at once: the window gets the frame the policy decides for `pref` + /// (or loses it again). The backend is the one winit opens by default, as at start-up; the + /// host sends nothing when the decision is unchanged. + pub fn set_title_bar_choice(&self, ctx: &egui::Context, pref: TitleBarPref) { + let decision = policy::decide_for(Prefix::new("PDFCRAFT"), Backend::from_env(), pref); + WindowHost::of(ctx).set_root_frame(decision); } - /// Follow Use system title bar at once: the window starts without winit's frame wherever the - /// app may draw its own, and gets it back (or loses it again) when the preference changes. - pub(super) fn sync_window_frame(&mut self, ctx: &egui::Context) { - if self.window_controls.is_none() { - return; - } - let app_frame = self.draws_window_frame(); - if self.app_frame_shown != Some(app_frame) { - // The window opens undecorated, so only a change from that needs a command. - if self.app_frame_shown.is_some() || !app_frame { - ctx.send_viewport_cmd(egui::ViewportCommand::Decorations(!app_frame)); - } - self.app_frame_shown = Some(app_frame); - } + /// Whether the window shows the body only (Acrobat's Full Screen Mode). + pub fn full_screen(&self) -> bool { + self.screen_mode.body_only() + } + + /// The one entry point for a screen-mode change: the shell's commands, the window's own button + /// and the app's commands all write the mode here. The shell sends the OS window action when + /// the mode it follows changes. + pub(crate) fn set_screen_mode(&mut self, mode: ScreenMode) { + self.screen_mode = mode; } /// Enter or leave full-screen reading (Acrobat: View ▸ Full Screen Mode, ⌘L). - pub fn set_full_screen(&mut self, ctx: &egui::Context, on: bool) { - self.apply_full_screen(on); - ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(on)); + pub fn set_full_screen(&mut self, on: bool) { + self.set_screen_mode(if on { ScreenMode::FullScreen } else { ScreenMode::Standard }); } - /// The full-screen state without the window: every document shows one page (or spread) at a - /// time fitted to the screen while it is on (Acrobat's Full Screen Mode, #379, #1459), and - /// gets its display back when it is off. - pub fn apply_full_screen(&mut self, on: bool) { + /// Reacts to the screen mode as it stands after the shell's pass, whoever wrote it: every + /// document shows one page (or spread) at a time fitted to the screen while the body is + /// alone (Acrobat's Full Screen Mode, #379, #1459), and gets its display back afterwards. + pub(crate) fn follow_screen_mode(&mut self) { + let on = self.full_screen(); // A click turns the page only with the Select tool, and full screen hides the tools: // select it there, and give the tool back on leaving (review on #2070). - if on && !self.full_screen { + if on && self.full_screen_tool.is_none() { self.full_screen_tool = Some(self.quick_tool); self.quick_tool = QuickTool::Select; } else if !on && let Some(tool) = self.full_screen_tool.take() { self.quick_tool = tool; } - self.full_screen = on; for view in &mut self.views { if on { view.enter_presentation(); @@ -51,12 +54,11 @@ impl PdfCraftApp { } } - /// Answer the Full Screen mode prompt a document raised on opening: enter it, or leave the - /// window as it is. - pub fn resolve_full_screen_prompt(&mut self, ctx: &egui::Context, allow: bool) { - let Some(id) = self.pending_full_screen.take() else { return }; + /// Answer the Full Screen mode prompt raised for document `id` on opening: enter it, or leave + /// the window as it is. + pub fn resolve_full_screen_prompt(&mut self, id: DocId, allow: bool) { if allow && self.session.get(id).is_some() { - self.set_full_screen(ctx, true); + self.set_full_screen(true); } } } diff --git a/crates/ui-egui/src/credits_data.rs b/crates/ui-egui/src/credits_data.rs new file mode 100644 index 0000000000..eea9a68e51 --- /dev/null +++ b/crates/ui-egui/src/credits_data.rs @@ -0,0 +1,5 @@ +//! The contributor and model credits the About dialog shows, baked by `build.rs`. + +use craft::ui::patterns::form_dialogs::{Contributor, Credits, ModelCredit}; + +include!(concat!(env!("OUT_DIR"), "/credits.rs")); diff --git a/crates/ui-egui/src/platform/updates.rs b/crates/ui-egui/src/platform/updates.rs index df58adb7c5..86695208f5 100644 --- a/crates/ui-egui/src/platform/updates.rs +++ b/crates/ui-egui/src/platform/updates.rs @@ -1,11 +1,14 @@ //! Help ▸ Check for updates and the check at start, through `craft_update`: the flow itself is its -//! `Updater`; this module supplies the suite and the quit path, and shows the result in -//! `craft_update`'s `CheckResultDialog`. +//! `Updater`; this module feeds it the app's unsaved-work facts and carries out what it asks for, +//! and shows the outcome of a check in `UpdateCheckDialog` on the app's `DialogHost`. +// PLAN: `craft::update` needs the `update` feature of the craft facade in crates/ui-egui/Cargo.toml (pdf-hub-w1, L-206). #[cfg(not(target_arch = "wasm32"))] -use craft_update::updater::{Action, CheckSource, Status, Updater}; +use craft::ui::dialog::DialogResult; #[cfg(not(target_arch = "wasm32"))] -use craft_update::{CheckResultDialog, CheckResultResponse}; +use craft::update::stack_dialogs::{CheckChoice, UpdateCheckDialog}; +#[cfg(not(target_arch = "wasm32"))] +use craft::update::updater::{Action, CheckSource, Status}; use crate::PdfCraftApp; @@ -16,328 +19,105 @@ pub const RELEASES_PAGE: &str = "https://github.com/storytold/pdfcraft/releases" #[cfg(not(target_arch = "wasm32"))] pub type UpdateSource = CheckSource; -pub(crate) struct Updates { - #[cfg(not(target_arch = "wasm32"))] - updater: Updater, - /// The Updates dialog is showing. - pub(crate) open: bool, - /// Ask for a newer release at start, unless Preferences says not to; the desktop app turns - /// it on, so tests never reach the network. - #[cfg(not(target_arch = "wasm32"))] - startup_check: bool, - #[cfg(not(target_arch = "wasm32"))] - check_requested: bool, - /// How many times `on_exit` called [`Updates::exiting`]. - #[cfg(test)] - exits: u32, - /// Stands in for the close that a finished installation queues in the `Updater`. - #[cfg(test)] - close_queued: bool, -} - -impl Updates { - /// The prompt that offers a newer release, after the check at start or Help ▸ Check for - /// updates, is open over the whole window. It isn't the Updates dialog (`open`), and it leaves - /// the menus on. - pub(crate) fn prompt_open(&self) -> bool { - #[cfg(not(target_arch = "wasm32"))] - { - self.updater.prompt_open() - } - #[cfg(target_arch = "wasm32")] - { - false - } - } -} - -impl Default for Updates { - fn default() -> Self { - Self { - #[cfg(not(target_arch = "wasm32"))] - updater: Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")), - open: false, - #[cfg(not(target_arch = "wasm32"))] - startup_check: false, - #[cfg(not(target_arch = "wasm32"))] - check_requested: false, - #[cfg(test)] - exits: 0, - #[cfg(test)] - close_queued: false, - } - } -} - -impl Updates { - /// Starts the helper of an update that waits for the app to exit. Later calls do nothing. - pub(crate) fn exiting(&mut self) { - #[cfg(not(target_arch = "wasm32"))] - self.updater.start_pending_update(); - #[cfg(test)] - { - self.exits += 1; - } - } - - /// Draws the startup prompt and returns what it asks for. `can_start` is false while unsaved - /// work holds back a ready update. - #[cfg(not(target_arch = "wasm32"))] - fn show_prompt(&mut self, ctx: &egui::Context, can_start: bool) -> Action { - #[cfg(test)] - if can_start && std::mem::take(&mut self.close_queued) { - return Action::Close; - } - self.updater.show_if(ctx, can_start) - } - - /// Asks the next frame that may close to close the app, so that a ready update installs. - #[cfg(not(target_arch = "wasm32"))] - fn queue_close(&mut self) { - self.updater.restart_to_update(); - #[cfg(test)] - { - self.close_queued = true; - } - } - - /// Takes the close that a finished installation queued, so a save after Cancel does not close - /// the app. `show_prompt` draws an open startup prompt, so this is for when none is open. - #[cfg(not(target_arch = "wasm32"))] - fn take_queued_close(&mut self, ctx: &egui::Context) { - let _ = self.show_prompt(ctx, true); - } -} - impl PdfCraftApp { /// Whether the app asks for a newer release on its first frame (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.startup_check = on; + self.startup_check = on; } - /// Replaces the network with `source` (tests). - #[cfg(not(target_arch = "wasm32"))] - pub fn set_update_source(&mut self, source: UpdateSource) { - self.updates.updater = Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).with_source(source); - } - - /// Help ▸ Check for updates: ask for the latest release and show the outcome. + /// Help ▸ Check for updates: ask for the latest release. The result dialog opens while the + /// updater's status is not idle ([`Self::update_logic`]). pub fn check_for_updates(&mut self) { #[cfg(not(target_arch = "wasm32"))] - { - self.updates.open = true; - self.updates.check_requested = true; - } + self.updater.check_now(); #[cfg(target_arch = "wasm32")] - { - self.open_url(RELEASES_PAGE); - } + self.open_url(RELEASES_PAGE); } - /// Starts the checks and picks up their answers (each frame). - pub(crate) fn poll_updates(&mut self) { - #[cfg(not(target_arch = "wasm32"))] - { - let Some(ctx) = self.ctx.clone() else { return }; - // Settled on the first frame: a preference turned on later waits for the next start. - let at_start = std::mem::take(&mut self.updates.startup_check) && self.update_check_at_start; - let updates = &mut self.updates; - if std::mem::take(&mut updates.check_requested) { - updates.updater.check_now(&ctx); - } else if at_start { - updates.updater.check_at_start(&ctx); - } - updates.updater.tick(&ctx); - } - } -} - -/// The startup prompt, and the Updates dialog that answers Help ▸ Check for updates. -pub(crate) fn dialog(app: &mut PdfCraftApp, ctx: &egui::Context) { + /// One frame of the update flow, before the dialog host runs: starts the checks, drives the + /// startup prompt, shows the result of a check and carries out what they ask for. #[cfg(not(target_arch = "wasm32"))] - { + pub(crate) fn update_logic(&mut self, ctx: &egui::Context) { + self.updater.tick(ctx); + // Settled on the first frame: a preference turned on later waits for the next start. + if std::mem::take(&mut self.startup_check) && self.update_check_at_start { + self.updater.check_at_start(); + } + self.show_update_check(); + // The restart helper is scheduled before the app closes, so no update starts over unsaved work. - let clean = app.first_dirty().is_none(); - match app.updates.show_prompt(ctx, clean) { + let dirty: Vec = (0..self.views.len()).filter(|&i| self.has_unsaved_work(i)).collect(); + let can_save = dirty.iter().all(|&i| self.saves_in_place(i)); + match self.updater.run_with_save(&mut self.dialogs, dirty.is_empty(), can_save) { Action::None => {} - Action::OpenUrl(url) => app.open_url(&url), + Action::OpenUrl(url) => self.open_url(&url), Action::Close => { - app.request_quit(ctx); + self.request_quit(ctx); } } - // A requested check that found a release is answered by the prompt, not by this dialog. - if app.updates.open && !app.updates.check_requested && matches!(app.updates.updater.status(), Status::Idle) { - app.updates.open = false; - } - if app.updates.open { - let dialog = CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")); - let response = dialog.show(ctx, app.updates.updater.status()); - answer_result(app, ctx, response); + if self.updater.take_save_request() { + let mut saved = true; + for &i in &dirty { + saved &= self.save_view(i, crate::editing::SaveTarget::InPlace); + } + if !saved { + // The save path has told the user why. + self.updater.save_stopped(None); + } } + self.answer_update_check(ctx, dirty.is_empty()); } + + /// Without an updater the web build has nothing to run. #[cfg(target_arch = "wasm32")] - let _ = (app, ctx); -} + pub(crate) fn update_logic(&mut self, _ctx: &egui::Context) {} -/// Carries out the answer to the Updates dialog. -#[cfg(not(target_arch = "wasm32"))] -fn answer_result(app: &mut PdfCraftApp, ctx: &egui::Context, response: CheckResultResponse) { - match response { - CheckResultResponse::None => {} - CheckResultResponse::Close => { - app.updates.open = false; - app.updates.updater.dismiss_status(); + /// Whether tab `index` saves in place without a question: it has a path that is no mail + /// temporary copy and none read back from a recovery sidecar. + #[cfg(not(target_arch = "wasm32"))] + fn saves_in_place(&self, index: usize) -> bool { + let Some(view) = self.views.get(index) else { return false }; + let path = self.session.get(view.id).and_then(|d| d.path.as_deref()); + path.is_some_and(|p| !craft::dialogs::save::is_mail_temp_copy(std::path::Path::new(p))) && !self.recovered_paths.contains(&view.id) + } + + /// Keeps the check-result dialog on the host while the updater has something to report, and + /// feeds it. + #[cfg(not(target_arch = "wasm32"))] + fn show_update_check(&mut self) { + if !self.dialogs.is_open::() && !matches!(self.updater.status(), Status::Idle) { + self.dialogs.open(UpdateCheckDialog::new(env!("CARGO_PKG_VERSION"))); } - CheckResultResponse::CheckAgain => app.updates.check_requested = true, - CheckResultResponse::RestartToUpdate => restart_to_update(app, ctx), - } -} - -/// Restart to Update. With unsaved changes the Updates dialog closes and the quit path asks about -/// them; Cancel there leaves the update ready. An open startup prompt keeps its own Restart to -/// Update and save-first note, so the app stays open. -#[cfg(not(target_arch = "wasm32"))] -fn restart_to_update(app: &mut PdfCraftApp, ctx: &egui::Context) { - if app.first_dirty().is_none() { - app.updates.queue_close(); - return; - } - app.updates.open = false; - app.updates.updater.dismiss_status(); - if app.updates.updater.prompt_open() { - return; - } - app.updates.take_queued_close(ctx); - app.request_quit(ctx); -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::CloseRequest; - use crate::editing::SaveTarget; - use eframe::App as _; - use pdfcraft_engine::{Edit, FieldValue}; - use std::path::PathBuf; - use std::sync::Arc; - - /// An app with one open document holding a form, and with `dirty` an unsaved change to it. - fn app(dirty: bool) -> PdfCraftApp { - let mut app = PdfCraftApp::new(); - app.open_bytes("source.pdf", None, include_bytes!("../../tests/data/form.pdf").to_vec()).unwrap(); - if dirty { - assert!(app.apply_edit(Edit::SetFieldValue { name: "name".into(), value: FieldValue::Text("Changed".into()) })); - assert!(app.first_dirty().is_some()); + let (status, installing, message) = (self.updater.status().clone(), self.updater.is_installing(), self.updater.status_message()); + if let Some(dialog) = self.dialogs.get_mut::() { + dialog.set_status(status); + dialog.set_installing(installing); + dialog.set_message(message); } - app.updates.open = true; - app } - /// An app with an unsaved change to a document in a new temporary folder, which Save writes - /// without asking where. Returns the document's path too. - fn app_with_file(test: &str) -> (PdfCraftApp, PathBuf) { - let dir = std::env::temp_dir().join(format!("pdfcraft-ui-updates-{test}-{}", std::process::id())); - let _ = std::fs::remove_dir_all(&dir); - std::fs::create_dir_all(&dir).unwrap(); - let path = dir.join("source.pdf"); - let bytes = include_bytes!("../../tests/data/form.pdf").to_vec(); - std::fs::write(&path, &bytes).unwrap(); - let mut app = PdfCraftApp::new(); - app.open_bytes("source.pdf", Some(path.to_string_lossy().into_owned()), bytes).unwrap(); - assert!(app.apply_edit(Edit::SetFieldValue { name: "name".into(), value: FieldValue::Text("Changed".into()) })); - app.updates.open = true; - (app, path) - } - - #[test] - fn restart_to_update_with_unsaved_changes_opens_the_save_prompt() { - let mut app = app(true); - let ctx = egui::Context::default(); - answer_result(&mut app, &ctx, CheckResultResponse::RestartToUpdate); - assert!(!app.updates.open, "the modal Updates dialog closes"); - assert_eq!(app.close_request, Some(CloseRequest::Quit), "the save prompt opens"); - assert!(!app.allow_quit); - app.resolve_close(&ctx, None); - assert!(app.close_request.is_none(), "Cancel closes the prompt"); - assert!(!app.allow_quit, "Cancel keeps the app open"); - } - - #[test] - fn restart_to_update_with_unsaved_changes_dismisses_the_check_result() { - let mut app = app(true); - app.set_update_source(Arc::new(|| Ok(None))); - let ctx = egui::Context::default(); - app.updates.updater.check_now(&ctx); - assert!(!matches!(app.updates.updater.status(), Status::Idle)); - answer_result(&mut app, &ctx, CheckResultResponse::RestartToUpdate); - assert!(matches!(app.updates.updater.status(), Status::Idle)); - } - - #[test] - fn saving_at_the_restart_prompt_writes_the_file_and_quits() { - let (mut app, path) = app_with_file("save"); - let ctx = egui::Context::default(); - answer_result(&mut app, &ctx, CheckResultResponse::RestartToUpdate); - app.resolve_close(&ctx, Some(true)); - assert!(app.allow_quit, "the app quits once the document is saved"); - - let mut reopened = PdfCraftApp::new(); - reopened.open_bytes("source.pdf", Some(path.to_string_lossy().into_owned()), std::fs::read(&path).unwrap()).unwrap(); - let doc = reopened.session.get(reopened.views[0].id).unwrap(); - let name = doc.form.iter().find(|f| f.name == "name").and_then(|f| f.value.first().cloned()); - assert_eq!(name.as_deref(), Some("Changed"), "the change is in the file"); - let _ = std::fs::remove_dir_all(path.parent().unwrap()); - } - - #[test] - fn saving_after_canceling_the_restart_keeps_the_app_open() { - let (mut app, path) = app_with_file("cancel"); - app.updates.close_queued = true; - let ctx = egui::Context::default(); - answer_result(&mut app, &ctx, CheckResultResponse::RestartToUpdate); - app.resolve_close(&ctx, None); - assert!(app.save_active(SaveTarget::InPlace)); - assert!(app.first_dirty().is_none()); - dialog(&mut app, &ctx); - assert!(!app.allow_quit, "the save does not close the app"); - assert!(app.close_request.is_none()); - let _ = std::fs::remove_dir_all(path.parent().unwrap()); - } - - #[test] - fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() { - let mut app = app(false); - let ctx = egui::Context::default(); - answer_result(&mut app, &ctx, CheckResultResponse::RestartToUpdate); - assert!(app.updates.open, "the dialog stays until the updater closes the app"); - assert!(app.close_request.is_none()); - assert!(!app.allow_quit); - dialog(&mut app, &ctx); - assert!(app.allow_quit, "the next frame closes the app"); - } - - #[test] - fn restart_to_update_with_the_startup_prompt_open_leaves_the_app_open() { - let mut app = app(true); - app.updates.updater.offer(craft_update::Release { - tag: "v99.0.0".into(), - version: craft_update::parse_version("99.0.0"), - name: "PdfCraft 99.0.0".into(), - html_url: "https://github.com/storytold/pdfcraft/releases/tag/v99.0.0".into(), - ..Default::default() - }); - assert!(app.updates.updater.prompt_open()); - answer_result(&mut app, &egui::Context::default(), CheckResultResponse::RestartToUpdate); - assert!(!app.updates.open, "the result dialog closes"); - assert!(app.updates.updater.prompt_open(), "the prompt stays"); - assert!(app.close_request.is_none(), "the prompt carries the restart"); - } - - #[test] - fn on_exit_calls_the_update_exit_hook_once() { - let mut app = PdfCraftApp::new(); - app.on_exit(None); - assert_eq!(app.updates.exits, 1); + /// Carries out the answer to the check-result dialog. With unsaved changes Restart to Update + /// dismisses the result and asks about them through the quit path; Cancel there leaves the + /// update ready. + #[cfg(not(target_arch = "wasm32"))] + fn answer_update_check(&mut self, ctx: &egui::Context, clean: bool) { + let Some(DialogResult::Ok(choice)) = self.dialogs.take::() else { + return; + }; + match choice { + CheckChoice::Close => self.updater.dismiss_status(), + CheckChoice::CheckNow | CheckChoice::CheckAgain => self.updater.check_now(), + CheckChoice::Update => { + self.updater.request_install(clean); + } + CheckChoice::Download => self.open_url(RELEASES_PAGE), + CheckChoice::RestartToUpdate if clean => self.updater.restart_to_update(), + CheckChoice::RestartToUpdate => { + self.updater.dismiss_status(); + self.request_quit(ctx); + } + _ => {} + } } } diff --git a/crates/ui-egui/src/viewer_prefs.rs b/crates/ui-egui/src/viewer_prefs.rs index 4c26ec151f..112fae898c 100644 --- a/crates/ui-egui/src/viewer_prefs.rs +++ b/crates/ui-egui/src/viewer_prefs.rs @@ -194,14 +194,14 @@ impl crate::PdfCraftApp { let Some(view) = self.views.get_mut(index) else { return }; view.interface = TabInterface::opening(HiddenInterface::asked_by(v), own_view); if !own_view && v.magnification == M::Default && matches!(v.layout, L::SinglePage | L::TwoUp | L::TwoUpCoverPage) { - view.fit = crate::canvas::Fit::Page; + view.view.fit = crate::canvas::Fit::Page; } let (doc, hidden) = (view.id, view.interface.hidden.any()); if activate && hidden { self.notify_interface_hidden(); } // A browser page can't resize or move its window. - if !cfg!(target_arch = "wasm32") && activate && only_document && !self.full_screen && (v.fit_window || v.center_window) { + if !cfg!(target_arch = "wasm32") && activate && only_document && !self.full_screen() && (v.fit_window || v.center_window) { self.pending_window = Some(PendingWindow { doc, fit: v.fit_window, center: v.center_window, frames_left: 30 }); } }