Skip to main content

qcli/app/
updates.rs

1//! The ecosystem's update notice: once qcli is open it asks crates.io, at most once a day, whether a
2//! newer version of itself is out, and says so in the corner when one is.
3//!
4//! The question goes out on a thread of the framework's own, so the start never waits for it,
5//! and no network is silence. The switch is the ecosystem's, `update-notice` in the shared
6//! `quvyta.conf`, and it is read here before anything is asked: with it off nothing is asked.
7
8use qframe::prelude::*;
9use qframe::runtime::UpdateCheck;
10use qframe::storage::Ecosystem;
11
12use super::{Msg, QCli};
13use crate::config::{APP, UpdateFolders};
14
15impl QCli {
16    /// The same chat, asking at start whether a newer version is out while the ecosystem's update
17    /// notice in `folders` is on. `None` asks nothing, which is every test that has not said
18    /// otherwise.
19    #[must_use]
20    pub fn update_notice(mut self, folders: Option<UpdateFolders>) -> Self {
21        self.updates = folders;
22        self
23    }
24
25    /// The question for a newer version of qcli, when the ecosystem's switch is on.
26    pub(super) fn ask_for_update(&self) -> Command<Msg> {
27        let Some(folders) = &self.updates else { return Command::none() };
28        if !Ecosystem::QUVYTA.update_notice_in(&folders.config) {
29            return Command::none();
30        }
31        let check = UpdateCheck::new(
32            Ecosystem::QUVYTA,
33            APP,
34            env!("CARGO_PKG_NAME"),
35            env!("CARGO_PKG_VERSION"),
36            Msg::NewVersion,
37        )
38        .in_folders(folders.config.clone(), folders.state.clone());
39        Command::check_for_update(check)
40    }
41}