mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
Merge branch 'main' of github.com:zzzgydi/clash-verge
This commit is contained in:
commit
2f5b8d9abe
|
@ -91,7 +91,7 @@ impl Core {
|
|||
// timer initialize
|
||||
let mut timer = self.timer.lock();
|
||||
timer.set_core(self.clone());
|
||||
log_if_err!(timer.refresh());
|
||||
log_if_err!(timer.restore());
|
||||
}
|
||||
|
||||
/// save the window instance
|
||||
|
|
|
@ -121,7 +121,7 @@ impl Profiles {
|
|||
}
|
||||
}
|
||||
|
||||
bail!("failed to get the item by \"{}\"", uid);
|
||||
bail!("failed to get the profile item \"uid:{uid}\"");
|
||||
}
|
||||
|
||||
/// append new item
|
||||
|
@ -178,7 +178,7 @@ impl Profiles {
|
|||
}
|
||||
|
||||
self.items = Some(items);
|
||||
bail!("failed to found the uid \"{uid}\"")
|
||||
bail!("failed to find the profile item \"uid:{uid}\"")
|
||||
}
|
||||
|
||||
/// be used to update the remote item
|
||||
|
@ -286,7 +286,7 @@ impl Profiles {
|
|||
return Ok(config::read_yaml::<Mapping>(file_path.clone()));
|
||||
}
|
||||
}
|
||||
bail!("failed to found the uid \"{current}\"");
|
||||
bail!("failed to find current profile \"uid:{current}\"");
|
||||
}
|
||||
|
||||
/// generate the data for activate clash config
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use super::Core;
|
||||
use crate::log_if_err;
|
||||
use crate::utils::help::get_now;
|
||||
use anyhow::{bail, Context, Result};
|
||||
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
|
||||
use std::collections::HashMap;
|
||||
|
@ -63,6 +64,34 @@ impl Timer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// restore timer
|
||||
pub fn restore(&mut self) -> Result<()> {
|
||||
self.refresh()?;
|
||||
|
||||
let cur_timestamp = get_now(); // seconds
|
||||
let profiles = self.core.as_ref().unwrap().profiles.lock();
|
||||
|
||||
profiles
|
||||
.get_items()
|
||||
.unwrap_or(&vec![])
|
||||
.iter()
|
||||
.filter(|item| item.uid.is_some() && item.updated.is_some() && item.option.is_some())
|
||||
.filter(|item| {
|
||||
// mins to seconds
|
||||
let interval = item.option.as_ref().unwrap().update_interval.unwrap_or(0) as usize * 60;
|
||||
let updated = item.updated.unwrap();
|
||||
return interval > 0 && cur_timestamp - updated >= interval;
|
||||
})
|
||||
.for_each(|item| {
|
||||
let uid = item.uid.as_ref().unwrap();
|
||||
if let Some((task_id, _)) = self.timer_map.get(uid) {
|
||||
log_if_err!(self.delay_timer.advance_task(*task_id));
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// generate a uid -> update_interval map
|
||||
fn gen_map(&self) -> HashMap<String, u64> {
|
||||
let profiles = self.core.as_ref().unwrap().profiles.lock();
|
||||
|
|
Loading…
Reference in New Issue
Block a user