feat: in-app update notice — checks GitHub releases on startup
Adds a one-shot update check that runs on app boot and pops up a small
"Update Available" window when the GitHub releases API reports a newer
tag than this build's `CARGO_PKG_VERSION`.
- `src/update_check.rs` — async wrapper around a blocking `ureq` GET to
`api.github.com/repos/HakanSeven12/H7CAD/releases/latest`, returns
`Some(version)` when a newer release exists, `None` otherwise (silent
on network / parse failure so a missing connection never blocks
launch).
- `H7CAD::boot` chains a `Task::perform` next to the main-window open
so the check runs in parallel with first-paint.
- New window plumbed like the other floating panels (page setup, about,
etc.): `update_notice_window`/`update_notice_version` state, title
entry, `OsWindowClosed` cleanup, and a `ui::update_notice::view_window`
modal that shows installed vs. latest version plus "Later" /
"Open Release Page" buttons. Open routes through `open::that` to the
releases URL and dismisses the modal.
Dependency: adds `ureq = { version = "2", default-features = false,
features = ["tls"] }` — the smallest blocking HTTP client + TLS combo
that doesn't drag in an async runtime.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
de37ee04bf
commit
86f5ba7b62
10 changed files with 388 additions and 2 deletions
|
|
@ -98,6 +98,12 @@ pub(super) struct H7CAD {
|
|||
dimstyle_window: Option<window::Id>,
|
||||
shortcuts_window: Option<window::Id>,
|
||||
about_window: Option<window::Id>,
|
||||
/// New-release notification window — opened on startup when the
|
||||
/// GitHub releases API reports a newer version than this build.
|
||||
update_notice_window: Option<window::Id>,
|
||||
/// Tag of the latest available release (without the leading "v"),
|
||||
/// e.g. `"0.3.0"`. `None` when up-to-date or check hasn't returned.
|
||||
update_notice_version: Option<String>,
|
||||
/// In-memory clipboard: cloned entities waiting to be pasted.
|
||||
clipboard: Vec<acadrust::EntityType>,
|
||||
/// Centroid of the clipboard entities (XZ plane, Y-up).
|
||||
|
|
@ -529,6 +535,14 @@ pub enum Message {
|
|||
OsWindowClosed(window::Id),
|
||||
/// No-op — used as a fallback when a TabEvent has no host mapping.
|
||||
Noop,
|
||||
/// GitHub releases API returned a result. `Some(version)` means a
|
||||
/// newer release exists; we open the update-notice window.
|
||||
UpdateCheckResult(Option<String>),
|
||||
/// User dismissed the update-notice window.
|
||||
UpdateNoticeClose,
|
||||
/// User clicked the "Open release page" button — opens the GitHub
|
||||
/// release URL in the OS default browser and closes the notice.
|
||||
UpdateNoticeOpenRelease,
|
||||
// ── Page Setup ────────────────────────────────────────────────────────
|
||||
/// Open the Page Setup panel for the current layout.
|
||||
PageSetupOpen,
|
||||
|
|
@ -713,6 +727,8 @@ impl H7CAD {
|
|||
dimstyle_window: None,
|
||||
shortcuts_window: None,
|
||||
about_window: None,
|
||||
update_notice_window: None,
|
||||
update_notice_version: None,
|
||||
clipboard: Vec::new(),
|
||||
clipboard_centroid: glam::Vec3::ZERO,
|
||||
layout_context_menu: None,
|
||||
|
|
@ -810,8 +826,12 @@ impl H7CAD {
|
|||
});
|
||||
let mut s = state;
|
||||
s.main_window = Some(id);
|
||||
let task = open_task.map(|_| Message::Noop);
|
||||
(s, task)
|
||||
let open_main = open_task.map(|_| Message::Noop);
|
||||
let check_update = Task::perform(
|
||||
crate::update_check::check_for_update(),
|
||||
Message::UpdateCheckResult,
|
||||
);
|
||||
(s, Task::batch([open_main, check_update]))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -851,6 +871,9 @@ pub fn run() -> iced::Result {
|
|||
if Some(window_id) == state.about_window {
|
||||
return "About H7CAD".into();
|
||||
}
|
||||
if Some(window_id) == state.update_notice_window {
|
||||
return "Update Available".into();
|
||||
}
|
||||
if Some(window_id) == state.unsaved_dialog_window {
|
||||
return "Unsaved Changes".into();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -974,6 +974,9 @@ impl H7CAD {
|
|||
if self.about_window == Some(id) {
|
||||
self.about_window = None;
|
||||
}
|
||||
if self.update_notice_window == Some(id) {
|
||||
self.update_notice_window = None;
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
|
|
@ -3536,6 +3539,37 @@ impl H7CAD {
|
|||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::UpdateCheckResult(latest) => {
|
||||
let Some(version) = latest else {
|
||||
return Task::none();
|
||||
};
|
||||
self.update_notice_version = Some(version);
|
||||
if let Some(id) = self.update_notice_window {
|
||||
return window::gain_focus(id);
|
||||
}
|
||||
let (id, task) = window::open(window::Settings {
|
||||
size: iced::Size::new(480.0, 240.0),
|
||||
resizable: false,
|
||||
..Default::default()
|
||||
});
|
||||
self.update_notice_window = Some(id);
|
||||
task.map(|_| Message::Noop)
|
||||
}
|
||||
Message::UpdateNoticeClose => {
|
||||
if let Some(id) = self.update_notice_window.take() {
|
||||
window::close(id)
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::UpdateNoticeOpenRelease => {
|
||||
let _ = open::that(crate::update_check::RELEASES_PAGE);
|
||||
if let Some(id) = self.update_notice_window.take() {
|
||||
window::close(id)
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::PageSetupWidthEdit(s) => {
|
||||
self.page_setup_w = s;
|
||||
Task::none()
|
||||
|
|
|
|||
|
|
@ -190,6 +190,13 @@ impl H7CAD {
|
|||
if Some(window_id) == self.about_window {
|
||||
return crate::ui::about::view_window();
|
||||
}
|
||||
if Some(window_id) == self.update_notice_window {
|
||||
let latest = self
|
||||
.update_notice_version
|
||||
.as_deref()
|
||||
.unwrap_or("?");
|
||||
return crate::ui::update_notice::view_window(latest);
|
||||
}
|
||||
if Some(window_id) == self.unsaved_dialog_window {
|
||||
let tab_name = match &self.pending_close {
|
||||
Some(super::PendingClose::Tab(idx)) => self
|
||||
|
|
|
|||
Loading…
Reference in a new issue