mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
refactor: for windows
This commit is contained in:
@@ -34,7 +34,7 @@ pub fn read_merge_mapping(path: PathBuf) -> Mapping {
|
||||
|
||||
match serde_yaml::from_str::<Value>(&yaml_str) {
|
||||
Ok(mut val) => {
|
||||
crate::log_if_err!(val.apply_merge());
|
||||
crate::log_err!(val.apply_merge());
|
||||
val.as_mapping().unwrap_or(&map).to_owned()
|
||||
}
|
||||
Err(_) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
use tauri::{
|
||||
api::path::{home_dir, resource_dir},
|
||||
@@ -23,20 +24,21 @@ static mut PORTABLE_FLAG: bool = false;
|
||||
pub static mut APP_VERSION: &str = "v1.1.1";
|
||||
|
||||
/// initialize portable flag
|
||||
#[allow(unused)]
|
||||
pub unsafe fn init_portable_flag() {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use tauri::utils::platform::current_exe;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub unsafe fn init_portable_flag() -> Result<()> {
|
||||
use tauri::utils::platform::current_exe;
|
||||
|
||||
let exe = current_exe().unwrap();
|
||||
let dir = exe.parent().unwrap();
|
||||
let exe = current_exe()?;
|
||||
|
||||
if let Some(dir) = exe.parent() {
|
||||
let dir = PathBuf::from(dir).join(".config/PORTABLE");
|
||||
|
||||
if dir.exists() {
|
||||
PORTABLE_FLAG = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// get the verge app home dir
|
||||
@@ -123,7 +125,7 @@ pub fn service_log_file() -> PathBuf {
|
||||
|
||||
let log_dir = app_logs_dir().join("service");
|
||||
|
||||
let local_time = Local::now().format("%Y-%m-%d-%H%M%S").to_string();
|
||||
let local_time = Local::now().format("%Y-%m-%d-%H%M").to_string();
|
||||
let log_file = format!("{}.log", local_time);
|
||||
let log_file = log_dir.join(log_file);
|
||||
|
||||
|
||||
@@ -3,14 +3,6 @@ use nanoid::nanoid;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub fn get_now() -> usize {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as _
|
||||
}
|
||||
|
||||
const ALPHABET: [char; 62] = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
||||
@@ -76,6 +68,7 @@ macro_rules! error {
|
||||
};
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
#[macro_export]
|
||||
macro_rules! log_if_err {
|
||||
($result: expr) => {
|
||||
|
||||
@@ -17,11 +17,11 @@ fn init_log() -> Result<()> {
|
||||
let _ = fs::create_dir_all(&log_dir);
|
||||
}
|
||||
|
||||
let local_time = Local::now().format("%Y-%m-%d-%H%M%S").to_string();
|
||||
let local_time = Local::now().format("%Y-%m-%d-%H%M").to_string();
|
||||
let log_file = format!("{}.log", local_time);
|
||||
let log_file = log_dir.join(log_file);
|
||||
|
||||
let time_format = "{d(%Y-%m-%d %H:%M:%S)} - {m}{n}";
|
||||
let time_format = "{d(%Y-%m-%d %H:%M:%S)} {l} - {m}{n}";
|
||||
let stdout = ConsoleAppender::builder()
|
||||
.encoder(Box::new(PatternEncoder::new(time_format)))
|
||||
.build();
|
||||
@@ -47,6 +47,11 @@ fn init_log() -> Result<()> {
|
||||
|
||||
/// Initialize all the files from resources
|
||||
pub fn init_config() -> Result<()> {
|
||||
#[cfg(target_os = "windows")]
|
||||
unsafe {
|
||||
let _ = dirs::init_portable_flag();
|
||||
}
|
||||
|
||||
let _ = init_log();
|
||||
|
||||
let app_dir = dirs::app_home_dir();
|
||||
@@ -94,21 +99,4 @@ pub fn init_resources(package_info: &PackageInfo) {
|
||||
let _ = fs::copy(src_path, target_path);
|
||||
}
|
||||
}
|
||||
|
||||
// // copy the resource file
|
||||
// let mmdb_path = app_dir.join("Country.mmdb");
|
||||
// let mmdb_tmpl = res_dir.join("Country.mmdb");
|
||||
// if !mmdb_path.exists() && mmdb_tmpl.exists() {
|
||||
// let _ = fs::copy(mmdb_tmpl, mmdb_path);
|
||||
// }
|
||||
|
||||
// // copy the wintun.dll
|
||||
// #[cfg(target_os = "windows")]
|
||||
// {
|
||||
// let wintun_path = app_dir.join("wintun.dll");
|
||||
// let wintun_tmpl = res_dir.join("wintun.dll");
|
||||
// if !wintun_path.exists() && wintun_tmpl.exists() {
|
||||
// let _ = fs::copy(wintun_tmpl, wintun_path);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ pub fn create_window(app_handle: &AppHandle) {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::log_if_err!(builder.decorations(true).inner_size(800.0, 642.0).build());
|
||||
crate::log_err!(builder.decorations(true).inner_size(800.0, 642.0).build());
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
crate::log_if_err!(builder
|
||||
crate::log_err!(builder
|
||||
.decorations(false)
|
||||
.transparent(true)
|
||||
.inner_size(800.0, 636.0)
|
||||
|
||||
Reference in New Issue
Block a user