Skip to content
Snippets Groups Projects
Commit 2f5b8d9a authored by GyDi's avatar GyDi
Browse files

Merge branch 'main' of github.com:zzzgydi/clash-verge

parents db324f54 3242efb1
No related branches found
No related tags found
No related merge requests found
...@@ -91,7 +91,7 @@ impl Core { ...@@ -91,7 +91,7 @@ impl Core {
// timer initialize // timer initialize
let mut timer = self.timer.lock(); let mut timer = self.timer.lock();
timer.set_core(self.clone()); timer.set_core(self.clone());
log_if_err!(timer.refresh()); log_if_err!(timer.restore());
} }
/// save the window instance /// save the window instance
......
...@@ -121,7 +121,7 @@ impl Profiles { ...@@ -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 /// append new item
...@@ -178,7 +178,7 @@ impl Profiles { ...@@ -178,7 +178,7 @@ impl Profiles {
} }
self.items = Some(items); 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 /// be used to update the remote item
...@@ -286,7 +286,7 @@ impl Profiles { ...@@ -286,7 +286,7 @@ impl Profiles {
return Ok(config::read_yaml::<Mapping>(file_path.clone())); 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 /// generate the data for activate clash config
......
use super::Core; use super::Core;
use crate::log_if_err; use crate::log_if_err;
use crate::utils::help::get_now;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder}; use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
use std::collections::HashMap; use std::collections::HashMap;
...@@ -63,6 +64,34 @@ impl Timer { ...@@ -63,6 +64,34 @@ impl Timer {
Ok(()) 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 /// generate a uid -> update_interval map
fn gen_map(&self) -> HashMap<String, u64> { fn gen_map(&self) -> HashMap<String, u64> {
let profiles = self.core.as_ref().unwrap().profiles.lock(); let profiles = self.core.as_ref().unwrap().profiles.lock();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment