mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
refactor: wip
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{config, utils::dirs};
|
||||
use crate::{config::Config, utils::dirs};
|
||||
use anyhow::{bail, Result};
|
||||
use reqwest::header::HeaderMap;
|
||||
use serde_yaml::Mapping;
|
||||
@@ -40,7 +40,7 @@ pub async fn patch_configs(config: &Mapping) -> Result<()> {
|
||||
|
||||
/// 根据clash info获取clash服务地址和请求头
|
||||
fn clash_client_info() -> Result<(String, HeaderMap)> {
|
||||
let info = { config::ClashN::global().info.lock().clone() };
|
||||
let info = { Config::clash().data().get_info()? };
|
||||
|
||||
if info.server.is_none() {
|
||||
let status = &info.status;
|
||||
|
||||
@@ -64,12 +64,12 @@ impl Hotkey {
|
||||
"clash_mode_global" => || feat::change_clash_mode("global".into()),
|
||||
"clash_mode_direct" => || feat::change_clash_mode("direct".into()),
|
||||
"clash_mode_script" => || feat::change_clash_mode("script".into()),
|
||||
"toggle_system_proxy" => || log_err!(feat::toggle_system_proxy()),
|
||||
"enable_system_proxy" => || log_err!(feat::enable_system_proxy()),
|
||||
"disable_system_proxy" => || log_err!(feat::disable_system_proxy()),
|
||||
"toggle_tun_mode" => || log_err!(feat::toggle_tun_mode()),
|
||||
"enable_tun_mode" => || log_err!(feat::enable_tun_mode()),
|
||||
"disable_tun_mode" => || log_err!(feat::disable_tun_mode()),
|
||||
"toggle_system_proxy" => || feat::toggle_system_proxy(),
|
||||
"enable_system_proxy" => || feat::enable_system_proxy(),
|
||||
"disable_system_proxy" => || feat::disable_system_proxy(),
|
||||
"toggle_tun_mode" => || feat::toggle_tun_mode(),
|
||||
"enable_tun_mode" => || feat::enable_tun_mode(),
|
||||
"disable_tun_mode" => || feat::disable_tun_mode(),
|
||||
|
||||
_ => bail!("invalid function \"{func}\""),
|
||||
};
|
||||
|
||||
@@ -144,13 +144,8 @@ impl Sysopt {
|
||||
|
||||
/// init the auto launch
|
||||
pub fn init_launch(&self) -> Result<()> {
|
||||
let enable = {
|
||||
Config::verge()
|
||||
.latest()
|
||||
.enable_auto_launch
|
||||
.clone()
|
||||
.unwrap_or(false)
|
||||
};
|
||||
let enable = { Config::verge().latest().enable_auto_launch.clone() };
|
||||
let enable = enable.unwrap_or(false);
|
||||
|
||||
let app_exe = current_exe()?;
|
||||
let app_exe = dunce::canonicalize(app_exe)?;
|
||||
@@ -213,13 +208,8 @@ impl Sysopt {
|
||||
drop(auto_launch);
|
||||
return self.init_launch();
|
||||
}
|
||||
let enable = {
|
||||
Config::verge()
|
||||
.latest()
|
||||
.enable_auto_launch
|
||||
.clone()
|
||||
.unwrap_or(false)
|
||||
};
|
||||
let enable = { Config::verge().latest().enable_auto_launch.clone() };
|
||||
let enable = enable.unwrap_or(false);
|
||||
let auto_launch = auto_launch.as_ref().unwrap();
|
||||
|
||||
match enable {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::config::{self, ProfilesN};
|
||||
use crate::config::Config;
|
||||
use crate::feat;
|
||||
use anyhow::{Context, Result};
|
||||
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
|
||||
use once_cell::sync::OnceCell;
|
||||
@@ -36,12 +37,10 @@ impl Timer {
|
||||
|
||||
let cur_timestamp = chrono::Local::now().timestamp();
|
||||
|
||||
let profiles = config::ProfilesN::global().config.lock();
|
||||
|
||||
let timer_map = self.timer_map.lock();
|
||||
let delay_timer = self.delay_timer.lock();
|
||||
|
||||
profiles.get_items().map(|items| {
|
||||
Config::profiles().latest().get_items().map(|items| {
|
||||
items
|
||||
.iter()
|
||||
// .filter_map(|item| {
|
||||
@@ -100,11 +99,9 @@ impl Timer {
|
||||
|
||||
/// generate a uid -> update_interval map
|
||||
fn gen_map(&self) -> HashMap<String, u64> {
|
||||
let profiles = config::ProfilesN::global().config.lock();
|
||||
|
||||
let mut new_map = HashMap::new();
|
||||
|
||||
if let Some(items) = profiles.get_items() {
|
||||
if let Some(items) = Config::profiles().latest().get_items() {
|
||||
for item in items.iter() {
|
||||
if item.option.is_some() {
|
||||
let option = item.option.as_ref().unwrap();
|
||||
@@ -178,7 +175,7 @@ impl Timer {
|
||||
/// the task runner
|
||||
async fn async_task(uid: String) {
|
||||
log::info!(target: "app", "running timer task `{uid}`");
|
||||
crate::log_err!(ProfilesN::global().update_item(uid, None).await);
|
||||
crate::log_err!(feat::update_profile(uid, None).await);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::log_err;
|
||||
use crate::{config::Config, feat, utils::resolve};
|
||||
use anyhow::Result;
|
||||
use tauri::{
|
||||
@@ -109,8 +108,8 @@ impl Tray {
|
||||
}
|
||||
|
||||
"open_window" => resolve::create_window(app_handle),
|
||||
"system_proxy" => log_err!(feat::toggle_system_proxy()),
|
||||
"tun_mode" => log_err!(feat::toggle_tun_mode()),
|
||||
"system_proxy" => feat::toggle_system_proxy(),
|
||||
"tun_mode" => feat::toggle_tun_mode(),
|
||||
"restart_clash" => feat::restart_clash_core(),
|
||||
"restart_app" => api::process::restart(&app_handle.env()),
|
||||
"quit" => {
|
||||
|
||||
Reference in New Issue
Block a user