mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 04:51:37 +00:00
Updates: a ready update starts its helper when the app exits (#6688)
This commit is contained in:
1 parent
8d6a8269d4
commit
13f5f00bca
3 files changed
+37
-1
No files matched your search
@@ -29,7 +29,8 @@ pdfcraft-model = { workspace = true }
|
||||
pdfcraft-platform = { workspace = true }
|
||||
egui = { workspace = true, features = ["bytemuck", "default_fonts", "monochrome_emoji_fonts"] }
|
||||
egui_extras = { workspace = true }
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit", "persistence", "links", "clipboard"] }
|
||||
# `glow` is always on: `eframe::App::on_exit` takes a GL context when that feature is enabled.
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "glow", "accesskit", "persistence", "links", "clipboard"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
log = { workspace = true }
|
||||
|
||||
@@ -468,6 +468,11 @@ impl eframe::App for PdfCraftApp {
|
||||
storage.set_string("pdfcraft", self.persist());
|
||||
}
|
||||
|
||||
/// Starts an update that waits for the exit. On macOS the process ends before the app is dropped.
|
||||
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
|
||||
self.updates.exiting();
|
||||
}
|
||||
|
||||
/// Each frame's work before drawing: opens, operating-system and control-channel requests,
|
||||
/// the quit guard, shortcuts, and the background jobs' results.
|
||||
///
|
||||
|
||||
@@ -27,6 +27,9 @@ pub(crate) struct Updates {
|
||||
startup_check: bool,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
check_requested: bool,
|
||||
/// How many times `on_exit` called [`Updates::exiting`].
|
||||
#[cfg(test)]
|
||||
exits: u32,
|
||||
}
|
||||
|
||||
impl Default for Updates {
|
||||
@@ -39,6 +42,20 @@ impl Default for Updates {
|
||||
startup_check: false,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
check_requested: false,
|
||||
#[cfg(test)]
|
||||
exits: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,3 +139,16 @@ pub(crate) fn dialog(app: &mut PdfCraftApp, ctx: &egui::Context) {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let _ = (app, ctx);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use eframe::App as _;
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user