mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 14:49:04 +00:00
feat: implemented basic update notification functionality
This commit is contained in:
parent
6f142d9ee5
commit
6694655690
2 changed files with 37 additions and 1 deletions
|
@ -117,6 +117,8 @@ pub enum Msg {
|
||||||
StartProber,
|
StartProber,
|
||||||
OnProberExit(bool),
|
OnProberExit(bool),
|
||||||
NoOp,
|
NoOp,
|
||||||
|
#[cfg(feature = "appimage")]
|
||||||
|
CheckForUpdates,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -740,6 +742,26 @@ impl AsyncComponent for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "appimage")]
|
||||||
|
Msg::CheckForUpdates => match crate::updater::check_updates_available().await {
|
||||||
|
Ok(true) => {
|
||||||
|
let notif =
|
||||||
|
gtk::gio::Notification::new(&format!("{APP_NAME}: update available"));
|
||||||
|
notif.set_body(Some(&format!(
|
||||||
|
"A new version of {APP_NAME} is available. Download it now."
|
||||||
|
)));
|
||||||
|
notif.set_default_action("app.updateapp");
|
||||||
|
notif.set_icon(>k::gio::ThemedIcon::from_names(&[
|
||||||
|
crate::constants::APP_ID,
|
||||||
|
]));
|
||||||
|
self.application.send_notification(
|
||||||
|
Some("org.gabmus.envision.update_available_notif"),
|
||||||
|
¬if,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => eprintln!("Warning: failed to check for updates: {e}"),
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,6 +966,17 @@ impl AsyncComponent for App {
|
||||||
|
|
||||||
root.insert_action_group(AppActionGroup::NAME, Some(&actions.into_action_group()));
|
root.insert_action_group(AppActionGroup::NAME, Some(&actions.into_action_group()));
|
||||||
|
|
||||||
|
#[cfg(feature = "appimage")]
|
||||||
|
{
|
||||||
|
let update_action = gtk::gio::SimpleAction::new("updateapp", None);
|
||||||
|
update_action.connect_activate(move |_, _| {
|
||||||
|
open_with_default_handler(
|
||||||
|
"https://gitlab.com/gabmus/envision/-/pipelines?ref=main&status=success",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
model.application.add_action(&update_action);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let app = &model.application;
|
let app = &model.application;
|
||||||
app.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
app.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
||||||
|
@ -970,6 +1003,9 @@ impl AsyncComponent for App {
|
||||||
|
|
||||||
model.split_view = Some(widgets.split_view.clone());
|
model.split_view = Some(widgets.split_view.clone());
|
||||||
|
|
||||||
|
#[cfg(feature = "appimage")]
|
||||||
|
sender.input(Msg::CheckForUpdates);
|
||||||
|
|
||||||
AsyncComponentParts { model, widgets }
|
AsyncComponentParts { model, widgets }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub async fn check_updates_available() -> anyhow::Result<bool> {
|
||||||
let text = res.text().await?;
|
let text = res.text().await?;
|
||||||
let commit_list: GitLabCommitList = serde_json::from_str(&text)?;
|
let commit_list: GitLabCommitList = serde_json::from_str(&text)?;
|
||||||
if commit_list
|
if commit_list
|
||||||
.get(0)
|
.first()
|
||||||
.is_some_and(|c| c.id.starts_with(shorthash))
|
.is_some_and(|c| c.id.starts_with(shorthash))
|
||||||
{
|
{
|
||||||
Ok(false)
|
Ok(false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue