refactor: fix

This commit is contained in:
GyDi 2022-11-14 01:45:58 +08:00
parent b03c52a501
commit d2852bb34a
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
4 changed files with 16 additions and 20 deletions

View File

@ -75,7 +75,7 @@ impl Timer {
let diff_map = self.gen_diff();
let mut timer_map = self.timer_map.lock();
let delay_timer = self.delay_timer.lock();
let mut delay_timer = self.delay_timer.lock();
for (uid, diff) in diff_map.into_iter() {
match diff {
@ -85,12 +85,12 @@ impl Timer {
}
DiffFlag::Add(tid, val) => {
let _ = timer_map.insert(uid.clone(), (tid, val));
crate::log_err!(self.add_task(uid, tid, val));
crate::log_err!(self.add_task(&mut delay_timer, uid, tid, val));
}
DiffFlag::Mod(tid, val) => {
let _ = timer_map.insert(uid.clone(), (tid, val));
crate::log_err!(delay_timer.remove_task(tid));
crate::log_err!(self.add_task(uid, tid, val));
crate::log_err!(self.add_task(&mut delay_timer, uid, tid, val));
}
}
}
@ -153,7 +153,13 @@ impl Timer {
}
/// add a cron task
fn add_task(&self, uid: String, tid: TaskID, minutes: u64) -> Result<()> {
fn add_task(
&self,
delay_timer: &mut DelayTimer,
uid: String,
tid: TaskID,
minutes: u64,
) -> Result<()> {
let task = TaskBuilder::default()
.set_task_id(tid)
.set_maximum_parallel_runnable_num(1)
@ -162,8 +168,7 @@ impl Timer {
.spawn_async_routine(move || Self::async_task(uid.to_owned()))
.context("failed to create timer task")?;
self.delay_timer
.lock()
delay_timer
.add_task(task)
.context("failed to add timer task")?;

View File

@ -17,9 +17,6 @@ impl Tray {
let version = app_handle.package_info().version.to_string();
dbg!(&zh);
dbg!(&version);
if zh {
SystemTrayMenu::new()
.add_item(CustomMenuItem::new("open_window", "打开面板"))
@ -128,9 +125,7 @@ impl Tray {
SystemTrayEvent::LeftClick { .. } => {
resolve::create_window(app_handle);
}
e @ _ => {
dbg!("trya");
}
_ => {}
}
}
}

View File

@ -12,7 +12,7 @@ mod feat;
mod utils;
use crate::utils::{init, resolve, server};
use tauri::{api, CustomMenuItem, Manager, SystemTray, SystemTrayMenu};
use tauri::{api, Manager, SystemTray};
fn main() -> std::io::Result<()> {
// 单例检测
@ -59,7 +59,7 @@ fn main() -> std::io::Result<()> {
cmds::view_profile,
cmds::patch_profile,
cmds::create_profile,
// cmds::import_profile,
cmds::import_profile,
cmds::update_profile,
cmds::delete_profile,
cmds::select_profile,

View File

@ -14,15 +14,11 @@ pub fn resolve_setup(app: &mut App) {
// 启动核心
log_err!(CoreManager::global().init());
// log_err!(app
// .tray_handle()
// .set_menu(tray::Tray::tray_menu(&app.app_handle())));
log_err!(tray::Tray::update_systray(&app.app_handle()));
// setup a simple http server for singleton
server::embed_server(app.app_handle());
log_err!(tray::Tray::update_systray(&app.app_handle()));
let silent_start = {
let verge = VergeN::global().config.lock();
verge.enable_silent_start.clone()