alfred_workflow_rust_project/workflow_updater.rs
1use crate::version::Version;
2
3use serde::{Deserialize, Serialize};
4use std::time::UNIX_EPOCH;
5
6// const SYSTEM_ICON_PATH: &str = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/{}";
7// this files define the icons provided by the macos system
8
9// features: auto upgrade newer workflow
10// the config should be set in workflow env
11// url: where to download the newer version
12// duration: how often to check whether a newer version
13// is_update_check: true/false
14// url_type: github
15#[derive(Serialize, Deserialize)]
16pub struct UpdateConfig {
17 release_url: String,
18 url_type: String,
19 auto_update: bool,
20 how_often: u8,
21 last_check_time_stamp: u128,
22
23 current_version: Version,
24}
25pub fn check_update(_current_version: &Version, config: &UpdateConfig) {
26 // check the `auto_update` config is on or off
27 // exit
28 if !config.auto_update {
29 return;
30 }
31
32 // get the checking history to test whether
33 // now should to check the update
34 // exit when checking is done in checking duration
35 let time_range: u128 = (config.how_often) as u128 * 24 * 60 * 60 * 1000;
36 if config.last_check_time_stamp + time_range
37 < std::time::SystemTime::now()
38 .duration_since(UNIX_EPOCH)
39 .unwrap()
40 .as_millis()
41 {
42 return;
43 }
44
45 // get the release info
46}
47
48pub fn download_update() {}
49
50pub fn install_update() {}