Compare commits
25 Commits
@@ -17,7 +17,7 @@ A <a href="https://github.com/Dreamacro/clash">Clash</a> GUI based on <a href="h
|
||||
|
||||
## Install
|
||||
|
||||
Download from [release](https://github.com/zzzgydi/clash-verge/releases). Supports Windows x64 and macOS 11+
|
||||
Download from [release](https://github.com/zzzgydi/clash-verge/releases). Supports Windows x64, Linux x86_64 and macOS 11+
|
||||
|
||||
Or you can build it yourself. Supports Windows, Linux and macOS 10.15+
|
||||
|
||||
|
||||
33
UPDATELOG.md
33
UPDATELOG.md
@@ -1,3 +1,36 @@
|
||||
## v0.0.26
|
||||
|
||||
### Features
|
||||
|
||||
- silent start
|
||||
- profile editor
|
||||
- profile enhance mode supports more fields
|
||||
- optimize profile enhance mode strategy
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- fix csp restriction on macOS
|
||||
- window controllers on Linux
|
||||
|
||||
---
|
||||
|
||||
## v0.0.25
|
||||
|
||||
### Features
|
||||
|
||||
- update clash core version
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- app updater error
|
||||
- display window controllers on Linux
|
||||
|
||||
### Notes
|
||||
|
||||
If you can't update the app properly, please consider downloading the latest version from github release.
|
||||
|
||||
---
|
||||
|
||||
## v0.0.24
|
||||
|
||||
### Features
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "clash-verge",
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.26",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"dev": "tauri dev",
|
||||
@@ -25,6 +25,7 @@
|
||||
"axios": "^0.26.0",
|
||||
"dayjs": "^1.10.8",
|
||||
"i18next": "^21.6.14",
|
||||
"monaco-editor": "^0.33.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-i18next": "^11.15.6",
|
||||
@@ -49,7 +50,8 @@
|
||||
"pretty-quick": "^3.1.3",
|
||||
"sass": "^1.49.7",
|
||||
"typescript": "^4.5.5",
|
||||
"vite": "^2.8.6"
|
||||
"vite": "^2.8.6",
|
||||
"vite-plugin-monaco-editor": "^1.0.10"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
|
||||
@@ -16,7 +16,7 @@ function resolveClash() {
|
||||
|
||||
const CLASH_URL_PREFIX =
|
||||
"https://github.com/Dreamacro/clash/releases/download/premium/";
|
||||
const CLASH_LATEST_DATE = "2022.03.19";
|
||||
const CLASH_LATEST_DATE = "2022.03.21";
|
||||
|
||||
// todo
|
||||
const map = {
|
||||
|
||||
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@@ -441,6 +441,7 @@ dependencies = [
|
||||
"log",
|
||||
"log4rs",
|
||||
"nanoid",
|
||||
"open",
|
||||
"port_scanner",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
||||
@@ -15,13 +15,14 @@ tauri-build = { version = "1.0.0-rc.4", features = [] }
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
dirs = "4.0.0"
|
||||
open = "2.1.1"
|
||||
dunce = "1.0.2"
|
||||
nanoid = "0.4.0"
|
||||
chrono = "0.4.19"
|
||||
serde_json = "1.0"
|
||||
serde_yaml = "0.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.0.0-rc.4", features = ["shell-all", "system-tray", "updater", "window-all"] }
|
||||
tauri = { version = "1.0.0-rc.4", features = ["process-all", "shell-all", "system-tray", "updater", "window-all"] }
|
||||
window-shadows = { git = "https://github.com/tauri-apps/window-shadows" }
|
||||
window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy" }
|
||||
|
||||
@@ -41,3 +42,9 @@ winreg = { version = "0.10", features = ["transactions"] }
|
||||
default = [ "custom-protocol" ]
|
||||
custom-protocol = [ "tauri/custom-protocol" ]
|
||||
verge-dev = []
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
use crate::{ret_err, wrap_err};
|
||||
use anyhow::Result;
|
||||
use serde_yaml::Mapping;
|
||||
use std::{path::PathBuf, process::Command};
|
||||
use std::process::Command;
|
||||
use tauri::{api, Manager, State};
|
||||
|
||||
/// get all profiles from `profiles.yaml`
|
||||
@@ -88,7 +88,7 @@ pub async fn update_profile(
|
||||
// reactivate the profile
|
||||
if Some(index) == profiles.get_current() {
|
||||
let clash = clash_state.0.lock().unwrap();
|
||||
wrap_err!(clash.activate(&profiles, false))?;
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -105,7 +105,7 @@ pub fn select_profile(
|
||||
wrap_err!(profiles.put_current(index))?;
|
||||
|
||||
let clash = clash_state.0.lock().unwrap();
|
||||
wrap_err!(clash.activate(&profiles, false))
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))
|
||||
}
|
||||
|
||||
/// change the profile chain
|
||||
@@ -122,7 +122,7 @@ pub fn change_profile_chain(
|
||||
profiles.put_chain(chain);
|
||||
clash.set_window(app_handle.get_window("main"));
|
||||
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false))
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))
|
||||
}
|
||||
|
||||
/// manually exec enhanced profile
|
||||
@@ -137,7 +137,7 @@ pub fn enhance_profiles(
|
||||
|
||||
clash.set_window(app_handle.get_window("main"));
|
||||
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false))
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))
|
||||
}
|
||||
|
||||
/// delete profile item
|
||||
@@ -151,7 +151,7 @@ pub fn delete_profile(
|
||||
|
||||
if wrap_err!(profiles.delete_item(index))? {
|
||||
let clash = clash_state.0.lock().unwrap();
|
||||
wrap_err!(clash.activate(&profiles, false))?;
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -195,21 +195,50 @@ pub fn view_profile(index: String, profiles_state: State<'_, ProfilesState>) ->
|
||||
.arg(path)
|
||||
.spawn()
|
||||
{
|
||||
log::error!("{err}");
|
||||
log::error!("failed to open file by VScode for {err}");
|
||||
return Err("failed to open file by VScode".into());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
if let Err(err) = Command::new(code).arg(path).spawn() {
|
||||
log::error!("{err}");
|
||||
log::error!("failed to open file by VScode for {err}");
|
||||
return Err("failed to open file by VScode".into());
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
open_path_cmd(path, "failed to open file by `open`")
|
||||
wrap_err!(open::that(path))
|
||||
}
|
||||
|
||||
/// read the profile item file data
|
||||
#[tauri::command]
|
||||
pub fn read_profile_file(
|
||||
index: String,
|
||||
profiles_state: State<'_, ProfilesState>,
|
||||
) -> Result<String, String> {
|
||||
let profiles = profiles_state.0.lock().unwrap();
|
||||
let item = wrap_err!(profiles.get_item(&index))?;
|
||||
let data = wrap_err!(item.read_file())?;
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// save the profile item file data
|
||||
#[tauri::command]
|
||||
pub fn save_profile_file(
|
||||
index: String,
|
||||
file_data: Option<String>,
|
||||
profiles_state: State<'_, ProfilesState>,
|
||||
) -> Result<(), String> {
|
||||
if file_data.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let profiles = profiles_state.0.lock().unwrap();
|
||||
let item = wrap_err!(profiles.get_item(&index))?;
|
||||
wrap_err!(item.save_file(file_data.unwrap()))
|
||||
}
|
||||
|
||||
/// restart the sidecar
|
||||
@@ -295,7 +324,7 @@ pub fn patch_verge_config(
|
||||
|
||||
wrap_err!(clash.tun_mode(tun_mode.unwrap()))?;
|
||||
clash.update_config();
|
||||
wrap_err!(clash.activate(&profiles, false))?;
|
||||
wrap_err!(clash.activate_enhanced(&profiles, false, false))?;
|
||||
}
|
||||
|
||||
let mut verge = verge_state.0.lock().unwrap();
|
||||
@@ -323,66 +352,12 @@ pub fn kill_sidecars() {
|
||||
#[tauri::command]
|
||||
pub fn open_app_dir() -> Result<(), String> {
|
||||
let app_dir = dirs::app_home_dir();
|
||||
open_path_cmd(app_dir, "failed to open app dir")
|
||||
wrap_err!(open::that(app_dir))
|
||||
}
|
||||
|
||||
/// open logs dir
|
||||
#[tauri::command]
|
||||
pub fn open_logs_dir() -> Result<(), String> {
|
||||
let log_dir = dirs::app_logs_dir();
|
||||
open_path_cmd(log_dir, "failed to open logs dir")
|
||||
}
|
||||
|
||||
/// use the os default open command to open file or dir
|
||||
fn open_path_cmd(path: PathBuf, err_str: &str) -> Result<(), String> {
|
||||
let result;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
||||
result = Command::new("explorer")
|
||||
.creation_flags(0x08000000)
|
||||
.arg(&path)
|
||||
.spawn();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
result = Command::new("open").arg(&path).spawn();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
result = Command::new("xdg-open").arg(&path).spawn();
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(child) => match child.wait_with_output() {
|
||||
Ok(out) => {
|
||||
// 退出码不为0 不一定没有调用成功
|
||||
// 因此仅做warn log且不返回错误
|
||||
if let Some(code) = out.status.code() {
|
||||
if code != 0 {
|
||||
log::warn!("failed to open {:?} (code {})", &path, code);
|
||||
log::warn!(
|
||||
"open cmd stdout: {}, stderr: {}",
|
||||
String::from_utf8_lossy(&out.stdout),
|
||||
String::from_utf8_lossy(&out.stderr),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("failed to open {:?} for {err}", &path);
|
||||
return Err(err_str.into());
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
log::error!("failed to open {:?} for {err}", &path);
|
||||
return Err(err_str.into());
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
wrap_err!(open::that(log_dir))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::{PrfEnhancedResult, Profiles, Verge};
|
||||
use crate::log_if_err;
|
||||
use crate::utils::{config, dirs, help};
|
||||
use anyhow::{bail, Result};
|
||||
use reqwest::header::HeaderMap;
|
||||
@@ -176,7 +177,8 @@ impl Clash {
|
||||
self.update_config();
|
||||
self.drop_sidecar()?;
|
||||
self.run_sidecar()?;
|
||||
self.activate(profiles, false)
|
||||
self.activate(profiles)?;
|
||||
self.activate_enhanced(profiles, false, true)
|
||||
}
|
||||
|
||||
/// update the clash info
|
||||
@@ -221,7 +223,7 @@ impl Clash {
|
||||
}
|
||||
|
||||
/// enable tun mode
|
||||
/// only revise the config and restart the
|
||||
/// only revise the config
|
||||
pub fn tun_mode(&mut self, enable: bool) -> Result<()> {
|
||||
// Windows 需要wintun.dll文件
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -354,62 +356,57 @@ impl Clash {
|
||||
}
|
||||
|
||||
/// enhanced profiles mode
|
||||
/// only change the enhanced profiles
|
||||
pub fn activate_enhanced(&self, profiles: &Profiles, delay: bool) -> Result<()> {
|
||||
/// - (sync) refresh config if enhance chain is null
|
||||
/// - (async) enhanced config
|
||||
pub fn activate_enhanced(&self, profiles: &Profiles, delay: bool, skip: bool) -> Result<()> {
|
||||
if self.window.is_none() {
|
||||
bail!("failed to get the main window");
|
||||
}
|
||||
|
||||
let win = self.window.clone().unwrap();
|
||||
let event_name = help::get_uid("e");
|
||||
let event_name = format!("enhanced-cb-{event_name}");
|
||||
|
||||
let info = self.info.clone();
|
||||
let mut config = self.config.clone();
|
||||
|
||||
// generate the payload
|
||||
let payload = profiles.gen_enhanced(event_name.clone())?;
|
||||
let window = self.window.clone();
|
||||
|
||||
win.once(&event_name, move |event| {
|
||||
let info = self.info.clone();
|
||||
|
||||
// do not run enhanced
|
||||
if payload.chain.len() == 0 {
|
||||
if skip {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut config = self.config.clone();
|
||||
let filter_data = Clash::strict_filter(payload.current);
|
||||
|
||||
for (key, value) in filter_data.into_iter() {
|
||||
config.insert(key, value);
|
||||
}
|
||||
|
||||
return Clash::_activate(info, config, self.window.clone());
|
||||
}
|
||||
|
||||
let window = self.window.clone().unwrap();
|
||||
let window_move = self.window.clone();
|
||||
|
||||
window.once(&event_name, move |event| {
|
||||
if let Some(result) = event.payload() {
|
||||
let result: PrfEnhancedResult = serde_json::from_str(result).unwrap();
|
||||
|
||||
if let Some(data) = result.data {
|
||||
// all of these can not be revised by script
|
||||
// http/https/socks port should be under control
|
||||
let not_allow = vec![
|
||||
"port",
|
||||
"socks-port",
|
||||
"mixed-port",
|
||||
"allow-lan",
|
||||
"mode",
|
||||
"external-controller",
|
||||
"secret",
|
||||
"log-level",
|
||||
];
|
||||
let mut config = Clash::read_config();
|
||||
let filter_data = Clash::loose_filter(data); // loose filter
|
||||
|
||||
for (key, value) in data.into_iter() {
|
||||
key.as_str().map(|key_str| {
|
||||
// change to lowercase
|
||||
let mut key_str = String::from(key_str);
|
||||
key_str.make_ascii_lowercase();
|
||||
|
||||
// filter
|
||||
if !not_allow.contains(&&*key_str) {
|
||||
config.insert(Value::String(key_str), value);
|
||||
}
|
||||
});
|
||||
for (key, value) in filter_data.into_iter() {
|
||||
config.insert(key, value);
|
||||
}
|
||||
|
||||
log_if_err!(Clash::_activate(info, config, window_move));
|
||||
log::info!("profile enhanced status {}", result.status);
|
||||
|
||||
Self::_activate(info, config, window).unwrap();
|
||||
}
|
||||
|
||||
if let Some(error) = result.error {
|
||||
log::error!("{error}");
|
||||
}
|
||||
result.error.map(|err| log::error!("{err}"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -418,7 +415,7 @@ impl Clash {
|
||||
if delay {
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
}
|
||||
win.emit("script-handler", payload).unwrap();
|
||||
window.emit("script-handler", payload).unwrap();
|
||||
});
|
||||
|
||||
Ok(())
|
||||
@@ -426,17 +423,83 @@ impl Clash {
|
||||
|
||||
/// activate the profile
|
||||
/// auto activate enhanced profile
|
||||
pub fn activate(&self, profiles: &Profiles, delay: bool) -> Result<()> {
|
||||
let gen_map = profiles.gen_activate()?;
|
||||
pub fn activate(&self, profiles: &Profiles) -> Result<()> {
|
||||
let data = profiles.gen_activate()?;
|
||||
let data = Clash::strict_filter(data);
|
||||
|
||||
let info = self.info.clone();
|
||||
let mut config = self.config.clone();
|
||||
|
||||
for (key, value) in gen_map.into_iter() {
|
||||
for (key, value) in data.into_iter() {
|
||||
config.insert(key, value);
|
||||
}
|
||||
|
||||
Self::_activate(info, config, self.window.clone())?;
|
||||
self.activate_enhanced(profiles, delay)
|
||||
Clash::_activate(info, config, self.window.clone())
|
||||
}
|
||||
|
||||
/// only 5 default fields available (clash config fields)
|
||||
/// convert to lowercase
|
||||
fn strict_filter(config: Mapping) -> Mapping {
|
||||
// Only the following fields are allowed:
|
||||
// proxies/proxy-providers/proxy-groups/rule-providers/rules
|
||||
let valid_keys = vec![
|
||||
"proxies",
|
||||
"proxy-providers",
|
||||
"proxy-groups",
|
||||
"rules",
|
||||
"rule-providers",
|
||||
];
|
||||
|
||||
let mut new_config = Mapping::new();
|
||||
|
||||
for (key, value) in config.into_iter() {
|
||||
key.as_str().map(|key_str| {
|
||||
// change to lowercase
|
||||
let mut key_str = String::from(key_str);
|
||||
key_str.make_ascii_lowercase();
|
||||
|
||||
// filter
|
||||
if valid_keys.contains(&&*key_str) {
|
||||
new_config.insert(Value::String(key_str), value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
new_config
|
||||
}
|
||||
|
||||
/// more clash config fields available
|
||||
/// convert to lowercase
|
||||
fn loose_filter(config: Mapping) -> Mapping {
|
||||
// all of these can not be revised by script or merge
|
||||
// http/https/socks port should be under control
|
||||
let not_allow = vec![
|
||||
"port",
|
||||
"socks-port",
|
||||
"mixed-port",
|
||||
"allow-lan",
|
||||
"mode",
|
||||
"external-controller",
|
||||
"secret",
|
||||
"log-level",
|
||||
];
|
||||
|
||||
let mut new_config = Mapping::new();
|
||||
|
||||
for (key, value) in config.into_iter() {
|
||||
key.as_str().map(|key_str| {
|
||||
// change to lowercase
|
||||
let mut key_str = String::from(key_str);
|
||||
key_str.make_ascii_lowercase();
|
||||
|
||||
// filter
|
||||
if !not_allow.contains(&&*key_str) {
|
||||
new_config.insert(Value::String(key_str), value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
new_config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::utils::{config, dirs, help, tmpl};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use serde_yaml::Mapping;
|
||||
use std::{fs, io::Write};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
@@ -279,6 +279,28 @@ impl PrfItem {
|
||||
file_data: Some(tmpl::ITEM_SCRIPT.into()),
|
||||
})
|
||||
}
|
||||
|
||||
/// get the file data
|
||||
pub fn read_file(&self) -> Result<String> {
|
||||
if self.file.is_none() {
|
||||
bail!("could not find the file");
|
||||
}
|
||||
|
||||
let file = self.file.clone().unwrap();
|
||||
let path = dirs::app_profiles_dir().join(file);
|
||||
fs::read_to_string(path).context("failed to read the file")
|
||||
}
|
||||
|
||||
/// save the file data
|
||||
pub fn save_file(&self, data: String) -> Result<()> {
|
||||
if self.file.is_none() {
|
||||
bail!("could not find the file");
|
||||
}
|
||||
|
||||
let file = self.file.clone().unwrap();
|
||||
let path = dirs::app_profiles_dir().join(file);
|
||||
fs::write(path, data.as_bytes()).context("failed to save the file")
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
@@ -553,32 +575,7 @@ impl Profiles {
|
||||
bail!("failed to read the file \"{}\"", file_path.display());
|
||||
}
|
||||
|
||||
let mut new_config = Mapping::new();
|
||||
let def_config = config::read_yaml::<Mapping>(file_path.clone());
|
||||
|
||||
// Only the following fields are allowed:
|
||||
// proxies/proxy-providers/proxy-groups/rule-providers/rules
|
||||
let valid_keys = vec![
|
||||
"proxies",
|
||||
"proxy-providers",
|
||||
"proxy-groups",
|
||||
"rule-providers",
|
||||
"rules",
|
||||
];
|
||||
|
||||
for (key, value) in def_config.into_iter() {
|
||||
key.as_str().map(|key_str| {
|
||||
// change to lowercase
|
||||
let mut key_str = String::from(key_str);
|
||||
key_str.make_ascii_lowercase();
|
||||
|
||||
if valid_keys.contains(&&*key_str) {
|
||||
new_config.insert(Value::String(key_str), value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new_config);
|
||||
return Ok(config::read_yaml::<Mapping>(file_path.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,11 +609,11 @@ impl Profiles {
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PrfEnhanced {
|
||||
current: Mapping,
|
||||
pub current: Mapping,
|
||||
|
||||
chain: Vec<PrfData>,
|
||||
pub chain: Vec<PrfData>,
|
||||
|
||||
callback: String,
|
||||
pub callback: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@@ -31,6 +31,9 @@ pub struct VergeConfig {
|
||||
/// can the app auto startup
|
||||
pub enable_auto_launch: Option<bool>,
|
||||
|
||||
/// not show the window on launch
|
||||
pub enable_silent_start: Option<bool>,
|
||||
|
||||
/// set system proxy
|
||||
pub enable_system_proxy: Option<bool>,
|
||||
|
||||
@@ -197,6 +200,9 @@ impl Verge {
|
||||
if patch.traffic_graph.is_some() {
|
||||
self.config.traffic_graph = patch.traffic_graph;
|
||||
}
|
||||
if patch.enable_silent_start.is_some() {
|
||||
self.config.enable_silent_start = patch.enable_silent_start;
|
||||
}
|
||||
|
||||
// should update system startup
|
||||
if patch.enable_auto_launch.is_some() {
|
||||
|
||||
@@ -118,7 +118,9 @@ fn main() -> std::io::Result<()> {
|
||||
cmds::get_profiles,
|
||||
cmds::sync_profiles,
|
||||
cmds::enhance_profiles,
|
||||
cmds::change_profile_chain
|
||||
cmds::change_profile_chain,
|
||||
cmds::read_profile_file,
|
||||
cmds::save_profile_file
|
||||
]);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -4,8 +4,6 @@ use tauri::{App, AppHandle, Manager};
|
||||
|
||||
/// handle something when start app
|
||||
pub fn resolve_setup(app: &App) {
|
||||
resolve_window(app);
|
||||
|
||||
// setup a simple http server for singleton
|
||||
server::embed_server(&app.handle());
|
||||
|
||||
@@ -26,7 +24,8 @@ pub fn resolve_setup(app: &App) {
|
||||
*profiles = Profiles::read_file();
|
||||
|
||||
clash.set_window(app.get_window("main"));
|
||||
log_if_err!(clash.activate(&profiles, true));
|
||||
log_if_err!(clash.activate(&profiles));
|
||||
log_if_err!(clash.activate_enhanced(&profiles, true, true));
|
||||
|
||||
verge.init_sysproxy(clash.info.port.clone());
|
||||
// enable tun mode
|
||||
@@ -46,6 +45,8 @@ pub fn resolve_setup(app: &App) {
|
||||
.get_item("system_proxy")
|
||||
.set_selected(enable));
|
||||
});
|
||||
|
||||
resolve_window(app, verge.config.enable_silent_start.clone());
|
||||
}
|
||||
|
||||
/// reset system proxy
|
||||
@@ -57,9 +58,16 @@ pub fn resolve_reset(app_handle: &AppHandle) {
|
||||
}
|
||||
|
||||
/// customize the window theme
|
||||
fn resolve_window(app: &App) {
|
||||
fn resolve_window(app: &App, hide: Option<bool>) {
|
||||
let window = app.get_window("main").unwrap();
|
||||
|
||||
// silent start
|
||||
hide.map(|hide| {
|
||||
if hide {
|
||||
window.hide().unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use window_shadows::set_shadow;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"package": {
|
||||
"productName": "Clash Verge",
|
||||
"version": "0.0.24"
|
||||
"version": "0.0.26"
|
||||
},
|
||||
"build": {
|
||||
"distDir": "../dist",
|
||||
@@ -64,6 +64,9 @@
|
||||
},
|
||||
"window": {
|
||||
"all": true
|
||||
},
|
||||
"process": {
|
||||
"all": true
|
||||
}
|
||||
},
|
||||
"windows": [
|
||||
@@ -80,7 +83,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
|
||||
"csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src 'self';"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +80,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
.windows.layout {
|
||||
.layout__right .the-content {
|
||||
top: 30px;
|
||||
.linux,
|
||||
.windows,
|
||||
.unknown {
|
||||
&.layout {
|
||||
.layout__right .the-content {
|
||||
top: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import dayjs from "dayjs";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { styled, Box, ListItem, IconButton, ListItemText } from "@mui/material";
|
||||
import { styled, ListItem, IconButton, ListItemText } from "@mui/material";
|
||||
import { CloseRounded } from "@mui/icons-material";
|
||||
import { ApiType } from "../../services/types";
|
||||
import { deleteConnection } from "../../services/api";
|
||||
|
||||
const Tag = styled(Box)(({ theme }) => ({
|
||||
const Tag = styled("span")(({ theme }) => ({
|
||||
display: "inline-block",
|
||||
fontSize: "12px",
|
||||
padding: "0 4px",
|
||||
@@ -37,16 +37,19 @@ const ConnectionItem = (props: Props) => {
|
||||
<ListItemText
|
||||
primary={value.metadata.host || value.metadata.destinationIP}
|
||||
secondary={
|
||||
<Box>
|
||||
<>
|
||||
<Tag sx={{ textTransform: "uppercase", color: "success" }}>
|
||||
{value.metadata.network}
|
||||
</Tag>
|
||||
|
||||
<Tag>{value.metadata.type}</Tag>
|
||||
|
||||
{value.chains.length > 0 && (
|
||||
<Tag>{value.chains[value.chains.length - 1]}</Tag>
|
||||
)}
|
||||
|
||||
<Tag>{dayjs(value.start).fromNow()}</Tag>
|
||||
</Box>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useSWR from "swr";
|
||||
import snarkdown from "snarkdown";
|
||||
import { useState, useMemo } from "react";
|
||||
import { useMemo } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
||||
import { killSidecars, restartSidecar } from "../../services/cmds";
|
||||
import { atomUpdateState } from "../../services/states";
|
||||
import Notice from "../base/base-notice";
|
||||
|
||||
interface Props {
|
||||
@@ -24,8 +26,6 @@ const UpdateLog = styled(Box)(() => ({
|
||||
"h1,h2,h3,ul,ol,p": { margin: "0.5em 0", color: "inherit" },
|
||||
}));
|
||||
|
||||
let uploadingState = false;
|
||||
|
||||
const UpdateDialog = (props: Props) => {
|
||||
const { open, onClose } = props;
|
||||
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
||||
@@ -33,22 +33,22 @@ const UpdateDialog = (props: Props) => {
|
||||
revalidateIfStale: false,
|
||||
focusThrottleInterval: 36e5, // 1 hour
|
||||
});
|
||||
const [uploading, setUploading] = useState(uploadingState);
|
||||
|
||||
const [updateState, setUpdateState] = useRecoilState(atomUpdateState);
|
||||
|
||||
const onUpdate = async () => {
|
||||
setUploading(true);
|
||||
uploadingState = true;
|
||||
if (updateState) return;
|
||||
setUpdateState(true);
|
||||
|
||||
try {
|
||||
await installUpdate();
|
||||
await killSidecars();
|
||||
await installUpdate();
|
||||
await relaunch();
|
||||
} catch (err: any) {
|
||||
await restartSidecar();
|
||||
Notice.error(err?.message || err.toString());
|
||||
} finally {
|
||||
setUploading(false);
|
||||
uploadingState = false;
|
||||
setUpdateState(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ const UpdateDialog = (props: Props) => {
|
||||
<Button
|
||||
autoFocus
|
||||
variant="contained"
|
||||
disabled={uploading}
|
||||
disabled={updateState}
|
||||
onClick={onUpdate}
|
||||
>
|
||||
Update
|
||||
|
||||
@@ -6,6 +6,8 @@ const Item = styled(Box)(({ theme }) => ({
|
||||
margin: "0 12px",
|
||||
lineHeight: 1.35,
|
||||
borderBottom: `1px solid ${theme.palette.divider}`,
|
||||
fontSize: "0.875rem",
|
||||
userSelect: "text",
|
||||
"& .time": {},
|
||||
"& .type": {
|
||||
display: "inline-block",
|
||||
|
||||
98
src/components/profile/file-editor.tsx
Normal file
98
src/components/profile/file-editor.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import useSWR from "swr";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
} from "@mui/material";
|
||||
import {
|
||||
getVergeConfig,
|
||||
readProfileFile,
|
||||
saveProfileFile,
|
||||
} from "../../services/cmds";
|
||||
import Notice from "../base/base-notice";
|
||||
|
||||
import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
|
||||
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";
|
||||
import "monaco-editor/esm/vs/editor/contrib/folding/browser/folding.js";
|
||||
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
|
||||
|
||||
interface Props {
|
||||
uid: string;
|
||||
open: boolean;
|
||||
mode: "yaml" | "javascript";
|
||||
onClose: () => void;
|
||||
onChange?: () => void;
|
||||
}
|
||||
|
||||
const FileEditor = (props: Props) => {
|
||||
const { uid, open, mode, onClose, onChange } = props;
|
||||
|
||||
const { t } = useTranslation();
|
||||
const editorRef = useRef<any>();
|
||||
const instanceRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||
const { theme_mode } = vergeConfig ?? {};
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
|
||||
readProfileFile(uid).then((data) => {
|
||||
const dom = editorRef.current;
|
||||
|
||||
if (!dom) return;
|
||||
if (instanceRef.current) instanceRef.current.dispose();
|
||||
|
||||
instanceRef.current = editor.create(editorRef.current, {
|
||||
value: data,
|
||||
language: mode,
|
||||
theme: theme_mode === "light" ? "vs" : "vs-dark",
|
||||
minimap: { enabled: false },
|
||||
});
|
||||
});
|
||||
|
||||
return () => {
|
||||
if (instanceRef.current) {
|
||||
instanceRef.current.dispose();
|
||||
instanceRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const onSave = useLockFn(async () => {
|
||||
const value = instanceRef.current?.getValue();
|
||||
|
||||
if (value == null) return;
|
||||
|
||||
try {
|
||||
await saveProfileFile(uid, value);
|
||||
onChange?.();
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose}>
|
||||
<DialogTitle>{t("Edit File")}</DialogTitle>
|
||||
|
||||
<DialogContent sx={{ width: 520, pb: 1 }}>
|
||||
<div style={{ width: "100%", height: "420px" }} ref={editorRef} />
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions>
|
||||
<Button onClick={onClose}>{t("Cancel")}</Button>
|
||||
<Button onClick={onSave} variant="contained">
|
||||
{t("Save")}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default FileEditor;
|
||||
@@ -1,7 +1,8 @@
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
alpha,
|
||||
@@ -16,9 +17,11 @@ import {
|
||||
} from "@mui/material";
|
||||
import { RefreshRounded } from "@mui/icons-material";
|
||||
import { CmdType } from "../../services/types";
|
||||
import { atomLoadingCache } from "../../services/states";
|
||||
import { updateProfile, deleteProfile, viewProfile } from "../../services/cmds";
|
||||
import parseTraffic from "../../utils/parse-traffic";
|
||||
import ProfileEdit from "./profile-edit";
|
||||
import FileEditor from "./file-editor";
|
||||
import Notice from "../base/base-notice";
|
||||
|
||||
const Wrapper = styled(Box)(({ theme }) => ({
|
||||
@@ -37,9 +40,6 @@ const round = keyframes`
|
||||
to { transform: rotate(360deg); }
|
||||
`;
|
||||
|
||||
// save the state of each item loading
|
||||
const loadingCache: Record<string, boolean> = {};
|
||||
|
||||
interface Props {
|
||||
selected: boolean;
|
||||
itemData: CmdType.ProfileItem;
|
||||
@@ -51,11 +51,11 @@ const ProfileItem = (props: Props) => {
|
||||
|
||||
const { t } = useTranslation();
|
||||
const { mutate } = useSWRConfig();
|
||||
const [loading, setLoading] = useState(loadingCache[itemData.uid] ?? false);
|
||||
const [anchorEl, setAnchorEl] = useState<any>(null);
|
||||
const [position, setPosition] = useState({ left: 0, top: 0 });
|
||||
const [loadingCache, setLoadingCache] = useRecoilState(atomLoadingCache);
|
||||
|
||||
const { name = "Profile", extra, updated = 0 } = itemData;
|
||||
const { uid, name = "Profile", extra, updated = 0 } = itemData;
|
||||
const { upload = 0, download = 0, total = 0 } = extra ?? {};
|
||||
const from = parseUrl(itemData.url);
|
||||
const expire = parseExpire(extra?.expire);
|
||||
@@ -68,23 +68,19 @@ const ProfileItem = (props: Props) => {
|
||||
const hasUrl = !!itemData.url;
|
||||
const hasExtra = !!extra; // only subscription url has extra info
|
||||
|
||||
useEffect(() => {
|
||||
loadingCache[itemData.uid] = loading;
|
||||
}, [itemData, loading]);
|
||||
const loading = loadingCache[itemData.uid] ?? false;
|
||||
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const onEdit = () => {
|
||||
const [fileOpen, setFileOpen] = useState(false);
|
||||
|
||||
const onEditInfo = () => {
|
||||
setAnchorEl(null);
|
||||
setEditOpen(true);
|
||||
};
|
||||
|
||||
const onView = async () => {
|
||||
const onEditFile = () => {
|
||||
setAnchorEl(null);
|
||||
try {
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
}
|
||||
setFileOpen(true);
|
||||
};
|
||||
|
||||
const onForceSelect = () => {
|
||||
@@ -92,19 +88,28 @@ const ProfileItem = (props: Props) => {
|
||||
onSelect(true);
|
||||
};
|
||||
|
||||
const onUpdateWrapper = (withProxy: boolean) => async () => {
|
||||
const onOpenFile = useLockFn(async () => {
|
||||
setAnchorEl(null);
|
||||
if (loading) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
await updateProfile(itemData.uid, { with_proxy: withProxy });
|
||||
setLoading(false);
|
||||
mutate("getProfiles");
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
setLoading(false);
|
||||
Notice.error(err?.message || err.toString());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const onUpdate = useLockFn(async (withProxy: boolean) => {
|
||||
setAnchorEl(null);
|
||||
setLoadingCache((cache) => ({ ...cache, [itemData.uid]: true }));
|
||||
|
||||
try {
|
||||
await updateProfile(itemData.uid, { with_proxy: withProxy });
|
||||
mutate("getProfiles");
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
} finally {
|
||||
setLoadingCache((cache) => ({ ...cache, [itemData.uid]: false }));
|
||||
}
|
||||
});
|
||||
|
||||
const onDelete = useLockFn(async () => {
|
||||
setAnchorEl(null);
|
||||
@@ -125,16 +130,18 @@ const ProfileItem = (props: Props) => {
|
||||
|
||||
const urlModeMenu = [
|
||||
{ label: "Select", handler: onForceSelect },
|
||||
{ label: "Edit", handler: onEdit },
|
||||
{ label: "File", handler: onView },
|
||||
{ label: "Update", handler: onUpdateWrapper(false) },
|
||||
{ label: "Update(Proxy)", handler: onUpdateWrapper(true) },
|
||||
{ label: "Edit Info", handler: onEditInfo },
|
||||
{ label: "Edit File", handler: onEditFile },
|
||||
{ label: "Open File", handler: onOpenFile },
|
||||
{ label: "Update", handler: () => onUpdate(false) },
|
||||
{ label: "Update(Proxy)", handler: () => onUpdate(true) },
|
||||
{ label: "Delete", handler: onDelete },
|
||||
];
|
||||
const fileModeMenu = [
|
||||
{ label: "Select", handler: onForceSelect },
|
||||
{ label: "Edit", handler: onEdit },
|
||||
{ label: "File", handler: onView },
|
||||
{ label: "Edit Info", handler: onEditInfo },
|
||||
{ label: "Edit File", handler: onEditFile },
|
||||
{ label: "Open File", handler: onOpenFile },
|
||||
{ label: "Delete", handler: onDelete },
|
||||
];
|
||||
|
||||
@@ -199,7 +206,7 @@ const ProfileItem = (props: Props) => {
|
||||
disabled={loading}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onUpdateWrapper(false)();
|
||||
onUpdate(false);
|
||||
}}
|
||||
>
|
||||
<RefreshRounded />
|
||||
@@ -259,6 +266,7 @@ const ProfileItem = (props: Props) => {
|
||||
onClose={() => setAnchorEl(null)}
|
||||
anchorPosition={position}
|
||||
anchorReference="anchorPosition"
|
||||
transitionDuration={225}
|
||||
onContextMenu={(e) => {
|
||||
setAnchorEl(null);
|
||||
e.preventDefault();
|
||||
@@ -282,6 +290,15 @@ const ProfileItem = (props: Props) => {
|
||||
onClose={() => setEditOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{fileOpen && (
|
||||
<FileEditor
|
||||
uid={uid}
|
||||
open={fileOpen}
|
||||
mode="yaml"
|
||||
onClose={() => setFileOpen(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import dayjs from "dayjs";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLockFn } from "ahooks";
|
||||
import {
|
||||
alpha,
|
||||
Box,
|
||||
@@ -12,9 +13,10 @@ import {
|
||||
} from "@mui/material";
|
||||
import { CmdType } from "../../services/types";
|
||||
import { viewProfile } from "../../services/cmds";
|
||||
import ProfileEdit from "./profile-edit";
|
||||
import Notice from "../base/base-notice";
|
||||
import enhance from "../../services/enhance";
|
||||
import ProfileEdit from "./profile-edit";
|
||||
import FileEditor from "./file-editor";
|
||||
import Notice from "../base/base-notice";
|
||||
|
||||
const Wrapper = styled(Box)(({ theme }) => ({
|
||||
width: "100%",
|
||||
@@ -57,6 +59,7 @@ const ProfileMore = (props: Props) => {
|
||||
const [anchorEl, setAnchorEl] = useState<any>(null);
|
||||
const [position, setPosition] = useState({ left: 0, top: 0 });
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [fileOpen, setFileOpen] = useState(false);
|
||||
const [status, setStatus] = useState(enhance.status(uid));
|
||||
|
||||
// unlisten when unmount
|
||||
@@ -65,40 +68,47 @@ const ProfileMore = (props: Props) => {
|
||||
// error during enhanced mode
|
||||
const hasError = selected && status?.status === "error";
|
||||
|
||||
const onEdit = () => {
|
||||
const onEditInfo = () => {
|
||||
setAnchorEl(null);
|
||||
setEditOpen(true);
|
||||
};
|
||||
|
||||
const onView = async () => {
|
||||
const onEditFile = () => {
|
||||
setAnchorEl(null);
|
||||
setFileOpen(true);
|
||||
};
|
||||
|
||||
const onOpenFile = useLockFn(async () => {
|
||||
setAnchorEl(null);
|
||||
try {
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const closeWrapper = (fn: () => void) => () => {
|
||||
const fnWrapper = (fn: () => void) => () => {
|
||||
setAnchorEl(null);
|
||||
return fn();
|
||||
};
|
||||
|
||||
const enableMenu = [
|
||||
{ label: "Disable", handler: closeWrapper(onDisable) },
|
||||
{ label: "Refresh", handler: closeWrapper(onEnhance) },
|
||||
{ label: "Edit", handler: onEdit },
|
||||
{ label: "File", handler: onView },
|
||||
{ label: "To Top", show: !hasError, handler: closeWrapper(onMoveTop) },
|
||||
{ label: "To End", show: !hasError, handler: closeWrapper(onMoveEnd) },
|
||||
{ label: "Delete", handler: closeWrapper(onDelete) },
|
||||
{ label: "Disable", handler: fnWrapper(onDisable) },
|
||||
{ label: "Refresh", handler: fnWrapper(onEnhance) },
|
||||
{ label: "Edit Info", handler: onEditInfo },
|
||||
{ label: "Edit File", handler: onEditFile },
|
||||
{ label: "Open File", handler: onOpenFile },
|
||||
{ label: "To Top", show: !hasError, handler: fnWrapper(onMoveTop) },
|
||||
{ label: "To End", show: !hasError, handler: fnWrapper(onMoveEnd) },
|
||||
{ label: "Delete", handler: fnWrapper(onDelete) },
|
||||
];
|
||||
|
||||
const disableMenu = [
|
||||
{ label: "Enable", handler: closeWrapper(onEnable) },
|
||||
{ label: "Edit", handler: onEdit },
|
||||
{ label: "File", handler: onView },
|
||||
{ label: "Delete", handler: closeWrapper(onDelete) },
|
||||
{ label: "Enable", handler: fnWrapper(onEnable) },
|
||||
{ label: "Edit Info", handler: onEditInfo },
|
||||
{ label: "Edit File", handler: onEditFile },
|
||||
{ label: "Open File", handler: onOpenFile },
|
||||
{ label: "Delete", handler: fnWrapper(onDelete) },
|
||||
];
|
||||
|
||||
const boxStyle = {
|
||||
@@ -208,6 +218,7 @@ const ProfileMore = (props: Props) => {
|
||||
onClose={() => setAnchorEl(null)}
|
||||
anchorPosition={position}
|
||||
anchorReference="anchorPosition"
|
||||
transitionDuration={225}
|
||||
onContextMenu={(e) => {
|
||||
setAnchorEl(null);
|
||||
e.preventDefault();
|
||||
@@ -233,6 +244,15 @@ const ProfileMore = (props: Props) => {
|
||||
onClose={() => setEditOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{fileOpen && (
|
||||
<FileEditor
|
||||
uid={uid}
|
||||
open={fileOpen}
|
||||
mode={type === "merge" ? "yaml" : "javascript"}
|
||||
onClose={() => setFileOpen(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import useSWR, { useSWRConfig } from "swr";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import { Box, IconButton, TextField } from "@mui/material";
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "@mui/icons-material";
|
||||
import { ApiType } from "../../services/types";
|
||||
import { updateProxy } from "../../services/api";
|
||||
import { getProfiles, patchProfile } from "../../services/cmds";
|
||||
import delayManager from "../../services/delay";
|
||||
import useFilterProxy from "./use-filter-proxy";
|
||||
import ProxyItem from "./proxy-item";
|
||||
@@ -23,6 +24,7 @@ interface Props {
|
||||
proxies: ApiType.ProxyItem[];
|
||||
}
|
||||
|
||||
// this component will be used for DIRECT/GLOBAL
|
||||
const ProxyGlobal = (props: Props) => {
|
||||
const { groupName, curProxy, proxies } = props;
|
||||
|
||||
@@ -35,10 +37,27 @@ const ProxyGlobal = (props: Props) => {
|
||||
const virtuosoRef = useRef<any>();
|
||||
const filterProxies = useFilterProxy(proxies, groupName, filterText);
|
||||
|
||||
const { data: profiles } = useSWR("getProfiles", getProfiles);
|
||||
|
||||
const onChangeProxy = useLockFn(async (name: string) => {
|
||||
await updateProxy("GLOBAL", name);
|
||||
mutate("getProxies");
|
||||
await updateProxy(groupName, name);
|
||||
setNow(name);
|
||||
|
||||
if (groupName === "DIRECT") return;
|
||||
|
||||
// update global selected
|
||||
const profile = profiles?.items?.find((p) => p.uid === profiles.current);
|
||||
if (!profile) return;
|
||||
if (!profile.selected) profile.selected = [];
|
||||
|
||||
const index = profile.selected.findIndex((item) => item.name === groupName);
|
||||
if (index < 0) {
|
||||
profile.selected.unshift({ name: groupName, now: name });
|
||||
} else {
|
||||
profile.selected[index] = { name: groupName, now: name };
|
||||
}
|
||||
|
||||
await patchProfile(profiles!.current!, { selected: profile.selected });
|
||||
});
|
||||
|
||||
const onLocation = (smooth = true) => {
|
||||
@@ -72,8 +91,24 @@ const ProxyGlobal = (props: Props) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (groupName === "DIRECT") setNow("DIRECT");
|
||||
if (groupName === "GLOBAL") setNow(curProxy || "DIRECT");
|
||||
}, [groupName, curProxy]);
|
||||
else if (groupName === "GLOBAL") {
|
||||
if (profiles) {
|
||||
const current = profiles.current;
|
||||
const profile = profiles.items?.find((p) => p.uid === current);
|
||||
|
||||
profile?.selected?.forEach((item) => {
|
||||
if (item.name === "GLOBAL") {
|
||||
if (item.now && item.now !== curProxy) {
|
||||
updateProxy("GLOBAL", item.now).then(() => setNow(item!.now!));
|
||||
mutate("getProxies");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setNow(curProxy || "DIRECT");
|
||||
}
|
||||
}, [groupName, curProxy, profiles]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -19,6 +19,7 @@ const SettingSystem = ({ onError }: Props) => {
|
||||
const {
|
||||
enable_tun_mode,
|
||||
enable_auto_launch,
|
||||
enable_silent_start,
|
||||
enable_system_proxy,
|
||||
system_proxy_bypass,
|
||||
enable_proxy_guard,
|
||||
@@ -59,6 +60,20 @@ const SettingSystem = ({ onError }: Props) => {
|
||||
</GuardState>
|
||||
</SettingItem>
|
||||
|
||||
<SettingItem>
|
||||
<ListItemText primary={t("Silent Start")} />
|
||||
<GuardState
|
||||
value={enable_silent_start ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onChange={(e) => onChangeData({ enable_silent_start: e })}
|
||||
onGuard={(e) => patchVergeConfig({ enable_silent_start: e })}
|
||||
>
|
||||
<Switch edge="end" />
|
||||
</GuardState>
|
||||
</SettingItem>
|
||||
|
||||
<SettingItem>
|
||||
<ListItemText
|
||||
primary={
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
"New": "New",
|
||||
"Close All": "Close All",
|
||||
"Select": "Select",
|
||||
"Edit": "Edit",
|
||||
"File": "File",
|
||||
"Edit Info": "Edit Info",
|
||||
"Edit File": "Edit File",
|
||||
"Open File": "Open File",
|
||||
"Update": "Update",
|
||||
"Update(Proxy)": "Update(Proxy)",
|
||||
"Delete": "Delete",
|
||||
@@ -41,6 +42,7 @@
|
||||
"Clash core": "Clash core",
|
||||
"Tun Mode": "Tun Mode",
|
||||
"Auto Launch": "Auto Launch",
|
||||
"Silent Start": "Silent Start",
|
||||
"System Proxy": "System Proxy",
|
||||
"Proxy Guard": "Proxy Guard",
|
||||
"Proxy Bypass": "Proxy Bypass",
|
||||
@@ -50,5 +52,8 @@
|
||||
"Language": "Language",
|
||||
"Open App Dir": "Open App Dir",
|
||||
"Open Logs Dir": "Open Logs Dir",
|
||||
"Version": "Version"
|
||||
"Version": "Version",
|
||||
|
||||
"Save": "Save",
|
||||
"Cancel": "Cancel"
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
"New": "新建",
|
||||
"Close All": "关闭全部",
|
||||
"Select": "使用",
|
||||
"Edit": "编辑信息",
|
||||
"File": "打开文件",
|
||||
"Edit Info": "编辑信息",
|
||||
"Edit File": "编辑文件",
|
||||
"Open File": "打开文件",
|
||||
"Update": "更新",
|
||||
"Update(Proxy)": "更新(代理)",
|
||||
"Delete": "删除",
|
||||
@@ -41,6 +42,7 @@
|
||||
"Clash core": "Clash 内核",
|
||||
"Tun Mode": "Tun 模式",
|
||||
"Auto Launch": "开机自启",
|
||||
"Silent Start": "静默启动",
|
||||
"System Proxy": "系统代理",
|
||||
"Proxy Guard": "系统代理守卫",
|
||||
"Proxy Bypass": "Proxy Bypass",
|
||||
@@ -50,5 +52,8 @@
|
||||
"Language": "语言设置",
|
||||
"Open App Dir": "应用目录",
|
||||
"Open Logs Dir": "日志目录",
|
||||
"Version": "版本"
|
||||
"Version": "版本",
|
||||
|
||||
"Save": "保存",
|
||||
"Cancel": "取消"
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@ import LayoutItem from "../components/layout/layout-item";
|
||||
import LayoutControl from "../components/layout/layout-control";
|
||||
import LayoutTraffic from "../components/layout/layout-traffic";
|
||||
import UpdateButton from "../components/layout/update-button";
|
||||
import getSystem from "../utils/get-system";
|
||||
import "dayjs/locale/zh-cn";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
const isWinOs = /win64|win32/i.test(navigator.userAgent);
|
||||
const OS = getSystem();
|
||||
|
||||
const Layout = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -85,11 +86,11 @@ const Layout = () => {
|
||||
<Paper
|
||||
square
|
||||
elevation={0}
|
||||
className={`${isWinOs ? "windows " : ""}layout`}
|
||||
className={`${OS} layout`}
|
||||
onPointerDown={onDragging}
|
||||
onContextMenu={(e) => {
|
||||
// only prevent it on Windows
|
||||
if (isWinOs) e.preventDefault();
|
||||
if (OS === "windows") e.preventDefault();
|
||||
}}
|
||||
sx={[
|
||||
(theme) => ({
|
||||
@@ -118,7 +119,7 @@ const Layout = () => {
|
||||
</div>
|
||||
|
||||
<div className="layout__right" data-windrag>
|
||||
{isWinOs && (
|
||||
{OS !== "macos" && (
|
||||
<div className="the-bar">
|
||||
<LayoutControl />
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@ const ConnectionsPage = () => {
|
||||
const initConn = { uploadTotal: 0, downloadTotal: 0, connections: [] };
|
||||
|
||||
const { t } = useTranslation();
|
||||
const [conn, setConn] = useState<ApiType.Connections>(initConn);
|
||||
const [connData, setConnData] = useState<ApiType.Connections>(initConn);
|
||||
|
||||
useEffect(() => {
|
||||
let ws: WebSocket | null = null;
|
||||
@@ -23,7 +23,35 @@ const ConnectionsPage = () => {
|
||||
|
||||
ws.addEventListener("message", (event) => {
|
||||
const data = JSON.parse(event.data) as ApiType.Connections;
|
||||
setConn(data);
|
||||
setConnData((old) => {
|
||||
const oldConn = old.connections;
|
||||
const oldList = oldConn.map((each) => each.id);
|
||||
const maxLen = data.connections.length;
|
||||
|
||||
const connections: typeof oldConn = [];
|
||||
|
||||
// 与前一次连接的顺序尽量保持一致
|
||||
data.connections
|
||||
.filter((each) => {
|
||||
const index = oldList.indexOf(each.id);
|
||||
|
||||
if (index >= 0 && index < maxLen) {
|
||||
connections[index] = each;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.forEach((each) => {
|
||||
for (let i = 0; i < maxLen; ++i) {
|
||||
if (!connections[i]) {
|
||||
connections[i] = each;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return { ...data, connections };
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +78,7 @@ const ConnectionsPage = () => {
|
||||
<Paper sx={{ boxShadow: 2, height: "100%" }}>
|
||||
<Virtuoso
|
||||
initialTopMostItemIndex={999}
|
||||
data={conn.connections}
|
||||
data={connData.connections}
|
||||
itemContent={(index, item) => <ConnectionItem value={item} />}
|
||||
/>
|
||||
</Paper>
|
||||
|
||||
@@ -29,6 +29,7 @@ const ProfilePage = () => {
|
||||
|
||||
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
||||
|
||||
// distinguish type
|
||||
const { regularItems, enhanceItems } = useMemo(() => {
|
||||
const items = profiles.items || [];
|
||||
const chain = profiles.chain || [];
|
||||
@@ -48,6 +49,7 @@ const ProfilePage = () => {
|
||||
return { regularItems, enhanceItems };
|
||||
}, [profiles]);
|
||||
|
||||
// sync selected proxy
|
||||
useEffect(() => {
|
||||
if (profiles.current == null) return;
|
||||
|
||||
@@ -65,9 +67,10 @@ const ProfilePage = () => {
|
||||
selected.map((each) => [each.name!, each.now!])
|
||||
);
|
||||
|
||||
// todo: enhance error handle
|
||||
let hasChange = false;
|
||||
proxiesData.groups.forEach((group) => {
|
||||
|
||||
const { global, groups } = proxiesData;
|
||||
[global, ...groups].forEach((group) => {
|
||||
const { name, now } = group;
|
||||
|
||||
if (!now || selectedMap[name] === now) return;
|
||||
@@ -78,15 +81,14 @@ const ProfilePage = () => {
|
||||
updateProxy(name, selectedMap[name]);
|
||||
}
|
||||
});
|
||||
|
||||
// update profile selected list
|
||||
profile.selected = Object.entries(selectedMap).map(([name, now]) => ({
|
||||
name,
|
||||
now,
|
||||
}));
|
||||
|
||||
patchProfile(current!, { selected: profile.selected }).catch(
|
||||
console.error
|
||||
);
|
||||
patchProfile(current!, { selected: profile.selected });
|
||||
// update proxies cache
|
||||
if (hasChange) mutate("getProxies", getProxies());
|
||||
}, 100);
|
||||
|
||||
@@ -25,6 +25,14 @@ export async function viewProfile(index: string) {
|
||||
return invoke<void>("view_profile", { index });
|
||||
}
|
||||
|
||||
export async function readProfileFile(index: string) {
|
||||
return invoke<string>("read_profile_file", { index });
|
||||
}
|
||||
|
||||
export async function saveProfileFile(index: string, fileData: string) {
|
||||
return invoke<void>("save_profile_file", { index, fileData });
|
||||
}
|
||||
|
||||
export async function importProfile(url: string) {
|
||||
return invoke<void>("import_profile", {
|
||||
url,
|
||||
|
||||
@@ -1,48 +1,80 @@
|
||||
import { emit, listen } from "@tauri-apps/api/event";
|
||||
import { CmdType } from "./types";
|
||||
import ignoreCase from "../utils/ignore-case";
|
||||
|
||||
const DEFAULT_FIELDS = [
|
||||
"rules",
|
||||
"proxies",
|
||||
"proxy-groups",
|
||||
"proxy-providers",
|
||||
"rule-providers",
|
||||
] as const;
|
||||
|
||||
const USE_FLAG_FIELDS = [
|
||||
"tun",
|
||||
"dns",
|
||||
"hosts",
|
||||
"script",
|
||||
"profile",
|
||||
"payload",
|
||||
"interface-name",
|
||||
"routing-mark",
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* process the merge mode
|
||||
*/
|
||||
function toMerge(
|
||||
merge: CmdType.ProfileMerge,
|
||||
data: CmdType.ProfileData
|
||||
): CmdType.ProfileData {
|
||||
if (!merge) return data;
|
||||
function toMerge(merge: CmdType.ProfileMerge, data: CmdType.ProfileData) {
|
||||
if (!merge) return { data, use: [] };
|
||||
|
||||
const newData = { ...data };
|
||||
const {
|
||||
use,
|
||||
"prepend-rules": preRules,
|
||||
"append-rules": postRules,
|
||||
"prepend-proxies": preProxies,
|
||||
"append-proxies": postProxies,
|
||||
"prepend-proxy-groups": preProxyGroups,
|
||||
"append-proxy-groups": postProxyGroups,
|
||||
...mergeConfig
|
||||
} = merge;
|
||||
|
||||
[...DEFAULT_FIELDS, ...USE_FLAG_FIELDS].forEach((key) => {
|
||||
// the value should not be null
|
||||
if (mergeConfig[key] != null) {
|
||||
data[key] = mergeConfig[key];
|
||||
}
|
||||
});
|
||||
|
||||
// init
|
||||
if (!data.rules) data.rules = [];
|
||||
if (!data.proxies) data.proxies = [];
|
||||
if (!data["proxy-groups"]) data["proxy-groups"] = [];
|
||||
|
||||
// rules
|
||||
if (Array.isArray(merge["prepend-rules"])) {
|
||||
if (!newData.rules) newData.rules = [];
|
||||
newData.rules.unshift(...merge["prepend-rules"]);
|
||||
if (Array.isArray(preRules)) {
|
||||
data.rules.unshift(...preRules);
|
||||
}
|
||||
if (Array.isArray(merge["append-rules"])) {
|
||||
if (!newData.rules) newData.rules = [];
|
||||
newData.rules.push(...merge["append-rules"]);
|
||||
if (Array.isArray(postRules)) {
|
||||
data.rules.push(...postRules);
|
||||
}
|
||||
|
||||
// proxies
|
||||
if (Array.isArray(merge["prepend-proxies"])) {
|
||||
if (!newData.proxies) newData.proxies = [];
|
||||
newData.proxies.unshift(...merge["prepend-proxies"]);
|
||||
if (Array.isArray(preProxies)) {
|
||||
data.proxies.unshift(...preProxies);
|
||||
}
|
||||
if (Array.isArray(merge["append-proxies"])) {
|
||||
if (!newData.proxies) newData.proxies = [];
|
||||
newData.proxies.push(...merge["append-proxies"]);
|
||||
if (Array.isArray(postProxies)) {
|
||||
data.proxies.push(...postProxies);
|
||||
}
|
||||
|
||||
// proxy-groups
|
||||
if (Array.isArray(merge["prepend-proxy-groups"])) {
|
||||
if (!newData["proxy-groups"]) newData["proxy-groups"] = [];
|
||||
newData["proxy-groups"].unshift(...merge["prepend-proxy-groups"]);
|
||||
if (Array.isArray(preProxyGroups)) {
|
||||
data["proxy-groups"].unshift(...preProxyGroups);
|
||||
}
|
||||
if (Array.isArray(merge["append-proxy-groups"])) {
|
||||
if (!newData["proxy-groups"]) newData["proxy-groups"] = [];
|
||||
newData["proxy-groups"].push(...merge["append-proxy-groups"]);
|
||||
if (Array.isArray(postProxyGroups)) {
|
||||
data["proxy-groups"].push(...postProxyGroups);
|
||||
}
|
||||
|
||||
return newData;
|
||||
return { data, use: Array.isArray(use) ? use : [] };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,70 +131,75 @@ class Enhance {
|
||||
|
||||
listen("script-handler", async (event) => {
|
||||
const payload = event.payload as CmdType.EnhancedPayload;
|
||||
let pdata = payload.current || {};
|
||||
|
||||
let hasScript = false;
|
||||
const result = await this.runner(payload).catch((err: any) => ({
|
||||
data: null,
|
||||
status: "error",
|
||||
error: err.message,
|
||||
}));
|
||||
|
||||
for (const each of payload.chain) {
|
||||
const { uid, type = "" } = each.item;
|
||||
|
||||
try {
|
||||
// process script
|
||||
if (type === "script") {
|
||||
// support async main function
|
||||
pdata = await toScript(each.script!, { ...pdata });
|
||||
hasScript = true;
|
||||
}
|
||||
|
||||
// process merge
|
||||
else if (type === "merge") {
|
||||
pdata = toMerge(each.merge!, { ...pdata });
|
||||
}
|
||||
|
||||
// invalid type
|
||||
else {
|
||||
throw new Error(`invalid enhanced profile type "${type}"`);
|
||||
}
|
||||
|
||||
this.exec(uid, { status: "ok" });
|
||||
} catch (err: any) {
|
||||
this.exec(uid, {
|
||||
status: "error",
|
||||
message: err.message || err.toString(),
|
||||
});
|
||||
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// If script is never used
|
||||
// filter other fields
|
||||
if (!hasScript) {
|
||||
const validKeys = [
|
||||
"proxies",
|
||||
"proxy-providers",
|
||||
"proxy-groups",
|
||||
"rule-providers",
|
||||
"rules",
|
||||
];
|
||||
|
||||
// to lowercase
|
||||
const newData: any = {};
|
||||
Object.keys(pdata).forEach((key) => {
|
||||
const newKey = key.toLowerCase();
|
||||
if (validKeys.includes(newKey)) {
|
||||
newData[newKey] = (pdata as any)[key];
|
||||
}
|
||||
});
|
||||
|
||||
pdata = newData;
|
||||
}
|
||||
|
||||
const result = { data: pdata, status: "ok" };
|
||||
emit(payload.callback, JSON.stringify(result)).catch(console.error);
|
||||
});
|
||||
}
|
||||
|
||||
// enhanced mode runner
|
||||
private async runner(payload: CmdType.EnhancedPayload) {
|
||||
const chain = payload.chain || [];
|
||||
|
||||
if (!Array.isArray(chain)) throw new Error("unhandle error");
|
||||
|
||||
let pdata = payload.current || {};
|
||||
let useList = [] as string[];
|
||||
|
||||
for (const each of chain) {
|
||||
const { uid, type = "" } = each.item;
|
||||
|
||||
try {
|
||||
// process script
|
||||
if (type === "script") {
|
||||
// support async main function
|
||||
pdata = await toScript(each.script!, ignoreCase(pdata));
|
||||
}
|
||||
|
||||
// process merge
|
||||
else if (type === "merge") {
|
||||
const temp = toMerge(each.merge!, ignoreCase(pdata));
|
||||
pdata = temp.data;
|
||||
useList = useList.concat(temp.use || []);
|
||||
}
|
||||
|
||||
// invalid type
|
||||
else {
|
||||
throw new Error(`invalid enhanced profile type "${type}"`);
|
||||
}
|
||||
|
||||
this.exec(uid, { status: "ok" });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
|
||||
this.exec(uid, {
|
||||
status: "error",
|
||||
message: err.message || err.toString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pdata = ignoreCase(pdata);
|
||||
|
||||
// filter the data
|
||||
const filterData: typeof pdata = {};
|
||||
Object.keys(pdata).forEach((key: any) => {
|
||||
if (
|
||||
DEFAULT_FIELDS.includes(key) ||
|
||||
(USE_FLAG_FIELDS.includes(key) && useList.includes(key))
|
||||
) {
|
||||
filterData[key] = pdata[key];
|
||||
}
|
||||
});
|
||||
|
||||
return { data: filterData, status: "ok" };
|
||||
}
|
||||
|
||||
// exec the listener
|
||||
private exec(uid: string, status: EStatus) {
|
||||
this.resultMap.set(uid, status);
|
||||
|
||||
@@ -10,3 +10,15 @@ export const atomLogData = atom<ApiType.LogItem[]>({
|
||||
key: "atomLogData",
|
||||
default: [],
|
||||
});
|
||||
|
||||
// save the state of each profile item loading
|
||||
export const atomLoadingCache = atom<Record<string, boolean>>({
|
||||
key: "atomLoadingCache",
|
||||
default: {},
|
||||
});
|
||||
|
||||
// save update state
|
||||
export const atomUpdateState = atom<boolean>({
|
||||
key: "atomUpdateState",
|
||||
default: false,
|
||||
});
|
||||
|
||||
@@ -126,12 +126,39 @@ export namespace CmdType {
|
||||
traffic_graph?: boolean;
|
||||
enable_tun_mode?: boolean;
|
||||
enable_auto_launch?: boolean;
|
||||
enable_silent_start?: boolean;
|
||||
enable_system_proxy?: boolean;
|
||||
enable_proxy_guard?: boolean;
|
||||
system_proxy_bypass?: string;
|
||||
}
|
||||
|
||||
export type ProfileMerge = Record<string, any>;
|
||||
type ClashConfigValue = any;
|
||||
|
||||
export interface ProfileMerge {
|
||||
// clash config fields (default supports)
|
||||
rules?: ClashConfigValue;
|
||||
proxies?: ClashConfigValue;
|
||||
"proxy-groups"?: ClashConfigValue;
|
||||
"proxy-providers"?: ClashConfigValue;
|
||||
"rule-providers"?: ClashConfigValue;
|
||||
// clash config fields (use flag)
|
||||
tun?: ClashConfigValue;
|
||||
dns?: ClashConfigValue;
|
||||
hosts?: ClashConfigValue;
|
||||
script?: ClashConfigValue;
|
||||
profile?: ClashConfigValue;
|
||||
payload?: ClashConfigValue;
|
||||
"interface-name"?: ClashConfigValue;
|
||||
"routing-mark"?: ClashConfigValue;
|
||||
// functional fields
|
||||
use?: string[];
|
||||
"prepend-rules"?: any[];
|
||||
"append-rules"?: any[];
|
||||
"prepend-proxies"?: any[];
|
||||
"append-proxies"?: any[];
|
||||
"prepend-proxy-groups"?: any[];
|
||||
"append-proxy-groups"?: any[];
|
||||
}
|
||||
|
||||
// partial of the clash config
|
||||
export type ProfileData = Partial<{
|
||||
@@ -140,6 +167,8 @@ export namespace CmdType {
|
||||
"proxy-groups": any[];
|
||||
"proxy-providers": any[];
|
||||
"rule-providers": any[];
|
||||
|
||||
[k: string]: any;
|
||||
}>;
|
||||
|
||||
export interface ChainItem {
|
||||
|
||||
13
src/utils/get-system.ts
Normal file
13
src/utils/get-system.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// get the system os
|
||||
// according to UA
|
||||
export default function getSystem() {
|
||||
const ua = navigator.userAgent;
|
||||
|
||||
if (ua.includes("Mac OS X")) return "macos";
|
||||
|
||||
if (/win64|win32/i.test(ua)) return "windows";
|
||||
|
||||
if (/linux/i.test(ua)) return "linux";
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
14
src/utils/ignore-case.ts
Normal file
14
src/utils/ignore-case.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Deep copy and change all keys to lowercase
|
||||
type TData = Record<string, any>;
|
||||
|
||||
export default function ignoreCase(data: TData): TData {
|
||||
if (!data) return data;
|
||||
|
||||
const newData = {} as TData;
|
||||
|
||||
Object.entries(data).forEach(([key, value]) => {
|
||||
newData[key.toLowerCase()] = JSON.parse(JSON.stringify(value));
|
||||
});
|
||||
|
||||
return newData;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import monaco from "vite-plugin-monaco-editor";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
root: "src",
|
||||
plugins: [react()],
|
||||
plugins: [react(), monaco()],
|
||||
build: {
|
||||
outDir: "../dist",
|
||||
emptyOutDir: true,
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@@ -1476,6 +1476,11 @@ minimist@^1.2.5:
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
|
||||
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
|
||||
|
||||
monaco-editor@^0.33.0:
|
||||
version "0.33.0"
|
||||
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.33.0.tgz#842e244f3750a2482f8a29c676b5684e75ff34af"
|
||||
integrity sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==
|
||||
|
||||
mri@^1.1.5:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mri/-/mri-1.2.0.tgz#6721480fec2a11a4889861115a48b6cbe7cc8f0b"
|
||||
@@ -1922,6 +1927,11 @@ universalify@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
|
||||
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
|
||||
|
||||
vite-plugin-monaco-editor@^1.0.10:
|
||||
version "1.0.10"
|
||||
resolved "https://registry.yarnpkg.com/vite-plugin-monaco-editor/-/vite-plugin-monaco-editor-1.0.10.tgz#cd370f68d4121bced6f902c6284649cc8eca4170"
|
||||
integrity sha512-7yTAFIE0SefjCmfnjrvXOl53wkxeSASc/ZIcB5tZeEK3vAmHhveV8y3f90Vp8b+PYdbUipjqf91mbFbSENkpcw==
|
||||
|
||||
vite@^2.8.6:
|
||||
version "2.8.6"
|
||||
resolved "https://registry.yarnpkg.com/vite/-/vite-2.8.6.tgz#32d50e23c99ca31b26b8ccdc78b1d72d4d7323d3"
|
||||
|
||||
Reference in New Issue
Block a user