Skip to content

Commit

Permalink
chore: merge from upstream/main (#1)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency @types/react to v18.2.60

* chore(deps): update lint packages to v19 (libnyanpasu#498)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(tray): use base64 encoded id to fix item not found issue

* fix(deps): update dependency @emotion/react to v11.11.4

* chore(manifest): update manifest [skip ci]

* chore(deps): update dependency @commitlint/cli to v19.0.1

* fix(deps): update rust crate tauri to v1.6.1 (libnyanpasu#504)

* fix(deps): update rust crate open to v5.0.2

* feat: add MDYSwitch & replace all Switches with MDYSwitch

* feat: MDYSwitch support loading prop

* refactor(single-instance): refactor single instance check (libnyanpasu#499)

* fix: deps conflict

* refactor(single-instance): remove related old single instance check code

* fix: lint

* refactor: improve ux

---------

Co-authored-by: Jonson Petard <i@a632079.me>

* chore: remove console and debugger when not in dev mode

* fix: MDYSwitch switchBase padding value

* feat: refactor GuardStatus & support loading status

* fix: line breaks typos

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: keiko233 <i@elaina.moe>
Co-authored-by: 403F <4o3f@proton.me>
Co-authored-by: keiko233 <keiko23333@gmail.com>
  • Loading branch information
6 people authored Feb 28, 2024
1 parent 9b2b711 commit 18f44a8
Show file tree
Hide file tree
Showing 23 changed files with 651 additions and 710 deletions.
186 changes: 114 additions & 72 deletions backend/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/sysproxy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ iptools = "0.2.5"
winreg = { version = "0.52", features = ["transactions"] }

[target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.52"
version = "0.54"
features = [
"Win32_Networking_WinInet",
# "Win32_Networking_WinHttp",
Expand Down
6 changes: 3 additions & 3 deletions backend/sysproxy-rs/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn unset_proxy() -> Result<()> {
dwSize: size_of::<INTERNET_PER_CONN_OPTION_LISTW>() as u32,
dwOptionCount: 1,
dwOptionError: 0,
pOptions: p_opts.as_mut_ptr() as *mut INTERNET_PER_CONN_OPTIONW,
pOptions: p_opts.as_mut_ptr(),
pszConnection: PWSTR::null(),
};
let res = apply(&opts);
Expand Down Expand Up @@ -83,7 +83,7 @@ fn set_auto_proxy(url: &str) -> Result<()> {
dwSize: size_of::<INTERNET_PER_CONN_OPTION_LISTW>() as u32,
dwOptionCount: 2,
dwOptionError: 0,
pOptions: p_opts.as_mut_ptr() as *mut INTERNET_PER_CONN_OPTIONW,
pOptions: p_opts.as_mut_ptr(),
pszConnection: PWSTR::null(),
};

Expand Down Expand Up @@ -133,7 +133,7 @@ fn set_global_proxy(server: String, bypass: String) -> Result<()> {
dwSize: size_of::<INTERNET_PER_CONN_OPTION_LISTW>() as u32,
dwOptionCount: 3,
dwOptionError: 0,
pOptions: p_opts.as_mut_ptr() as *mut INTERNET_PER_CONN_OPTIONW,
pOptions: p_opts.as_mut_ptr(),
pszConnection: PWSTR::null(),
};

Expand Down
1 change: 1 addition & 0 deletions backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ tracing-log = { version = "0.2" }
tracing-appender = { version = "0.2", features = ["parking_lot"] }
single-instance = "0.3.3"
tauri-plugin-deep-link = { path = "../tauri-plugin-deep-link", version = "0.1.2" }
base64 = "0.21"

[target.'cfg(windows)'.dependencies]
deelevate = "0.2.0"
Expand Down
1 change: 1 addition & 0 deletions backend/tauri/src/core/tasks/jobs/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn clear_logs() -> Result<()> {
let minutes = {
let verge = Config::verge();
let verge = verge.data();
#[allow(deprecated)]
verge.auto_log_clean.unwrap_or(0)
};
if minutes == 0 {
Expand Down
56 changes: 40 additions & 16 deletions backend/tauri/src/core/tray/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::core::{
clash::proxies::{Proxies, ProxiesGuard, ProxiesGuardExt},
handle::Handle,
};
use anyhow::Context;
use base64::{engine::general_purpose::STANDARD as base64_standard, Engine as _};
use indexmap::IndexMap;
use tauri::SystemTrayMenu;
use tracing::{debug, error, warn};
Expand Down Expand Up @@ -135,6 +137,7 @@ fn diff_proxies(old_proxies: &TrayProxies, new_proxies: &TrayProxies) -> TrayUpd
TrayUpdateType::Part(actions)
}
}

#[instrument]
pub async fn proxies_updated_receiver() {
let (mut rx, mut tray_proxies_holder) = {
Expand Down Expand Up @@ -198,13 +201,19 @@ pub fn setup_proxies() {
mod platform_impl {
use super::{ProxySelectAction, TrayProxyItem};
use crate::core::{clash::proxies::ProxiesGuard, handle::Handle};
use base64::{engine::general_purpose::STANDARD as base64_standard, Engine as _};
use tauri::{CustomMenuItem, SystemTrayMenu, SystemTraySubmenu};
use tracing::warn;

pub fn generate_group_selector(group_name: &str, group: &TrayProxyItem) -> SystemTraySubmenu {
let mut group_menu = SystemTrayMenu::new();
for item in group.all.iter() {
let mut sub_item = CustomMenuItem::new(
format!("select_proxy_{}_{}", group_name, item),
format!(
"select_proxy_{}_{}",
base64_standard.encode(group_name),
base64_standard.encode(item)
),
item.clone(),
);
if let Some(now) = group.current.clone() {
Expand Down Expand Up @@ -252,8 +261,16 @@ mod platform_impl {
.unwrap()
.tray_handle();
for action in actions {
let from = format!("select_proxy_{}_{}", action.0, action.1);
let to = format!("select_proxy_{}_{}", action.0, action.2);
let from = format!(
"select_proxy_{}_{}",
base64_standard.encode(&action.0),
base64_standard.encode(&action.1)
);
let to = format!(
"select_proxy_{}_{}",
base64_standard.encode(&action.0),
base64_standard.encode(&action.2)
);

match tray.try_get_item(&from) {
Some(item) => {
Expand Down Expand Up @@ -294,17 +311,24 @@ pub fn on_system_tray_event(event: &str) {
if parts.len() != 4 {
return; // bypass invalid event
}
let group = parts[2].to_owned();
let name = parts[3].to_owned();
tauri::async_runtime::spawn(async move {
match ProxiesGuard::global().select_proxy(&group, &name).await {
Ok(_) => {
debug!("select proxy success: {} {}", group, name);
}
Err(e) => {
warn!("select proxy failed, {} {}, cause: {:?}", group, name, e);
// TODO: add a error dialog or notification
}
}
});

let wrapper = move || -> anyhow::Result<()> {
let group = String::from_utf8(base64_standard.decode(parts[2])?)?;
let name = String::from_utf8(base64_standard.decode(parts[3])?)?;
tauri::async_runtime::block_on(async move {
ProxiesGuard::global()
.select_proxy(&group, &name)
.await
.with_context(|| format!("select proxy failed, {} {}, cause: ", group, name))?;

debug!("select proxy success: {} {}", group, name);
Ok::<(), anyhow::Error>(())
})?;
Ok(())
};

if let Err(e) = wrapper() {
// TODO: add a error dialog or notification
error!("on_system_tray_event failed: {:?}", e);
}
}
25 changes: 15 additions & 10 deletions backend/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
config::Config,
utils::{init, resolve},
};
use anyhow::Context;
use tauri::{api, Manager, SystemTray};

rust_i18n::i18n!("../../locales");
Expand Down Expand Up @@ -48,17 +49,16 @@ fn main() -> std::io::Result<()> {
// Should be in first place in order prevent single instance check block everything
tauri_plugin_deep_link::prepare("moe.elaina.clash.nyanpasu");

#[cfg(not(feature = "verge-dev"))]
let instance_id = "clash-nyanpasu";
#[cfg(feature = "verge-dev")]
let instance_id = "clash-nyanpasu-dev";

// 单例检测
let instance = single_instance::SingleInstance::new(instance_id).unwrap();
if !instance.is_single() {
println!("app exists");
return Ok(());
}
let single_instance_result: anyhow::Result<()> =
single_instance::SingleInstance::new(utils::dirs::APP_NAME)
.context("failed to create single instance")
.map(|instance| {
if !instance.is_single() {
println!("app exists");
std::process::exit(0);
}
});

// Use system locale as default
let locale = {
Expand All @@ -80,6 +80,11 @@ fn main() -> std::io::Result<()> {
let verge = { Config::verge().latest().language.clone().unwrap() };
rust_i18n::set_locale(verge.as_str());

// show a dialog to print the single instance error
if let Err(e) = single_instance_result {
utils::dialog::panic_dialog(&format!("{:?}", e));
}

#[allow(unused_mut)]
let mut builder = tauri::Builder::default()
.system_tray(SystemTray::new())
Expand Down
22 changes: 12 additions & 10 deletions backend/tauri/src/utils/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use tauri::{
};

#[cfg(not(feature = "verge-dev"))]
static OLD_APP_DIR: &str = "clash-verge";
const PREVIOUS_APP_NAME: &str = "clash-verge";
#[cfg(feature = "verge-dev")]
static OLD_APP_DIR: &str = "clash-verge-dev";
const PREVIOUS_APP_NAME: &str = "clash-verge-dev";
#[cfg(not(feature = "verge-dev"))]
static APP_DIR: &str = "clash-nyanpasu";
pub const APP_NAME: &str = "clash-nyanpasu";
#[cfg(feature = "verge-dev")]
static APP_DIR: &str = "clash-nyanpasu-dev";
pub const APP_NAME: &str = "clash-nyanpasu-dev";

static CLASH_CONFIG: &str = "config.yaml";
static VERGE_CONFIG: &str = "verge.yaml";
Expand Down Expand Up @@ -64,22 +64,24 @@ pub fn old_app_home_dir() -> Result<PathBuf> {
Ok(home_dir()
.ok_or(anyhow::anyhow!("failed to check old app home dir"))?
.join(".config")
.join(OLD_APP_DIR))
.join(PREVIOUS_APP_NAME))
} else {
let app_exe = current_exe()?;
let app_exe = dunce::canonicalize(app_exe)?;
let app_dir = app_exe
.parent()
.ok_or(anyhow::anyhow!("failed to check the old portable app dir"))?;
Ok(PathBuf::from(app_dir).join(".config").join(OLD_APP_DIR))
Ok(PathBuf::from(app_dir)
.join(".config")
.join(PREVIOUS_APP_NAME))
}
}

#[cfg(not(target_os = "windows"))]
Ok(home_dir()
.ok_or(anyhow::anyhow!("failed to get the app home dir"))?
.join(".config")
.join(OLD_APP_DIR))
.join(PREVIOUS_APP_NAME))
}

/// get the verge app home dir
Expand All @@ -92,22 +94,22 @@ pub fn app_home_dir() -> Result<PathBuf> {
Ok(home_dir()
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
.join(".config")
.join(APP_DIR))
.join(APP_NAME))
} else {
let app_exe = current_exe()?;
let app_exe = dunce::canonicalize(app_exe)?;
let app_dir = app_exe
.parent()
.ok_or(anyhow::anyhow!("failed to get the portable app dir"))?;
Ok(PathBuf::from(app_dir).join(".config").join(APP_DIR))
Ok(PathBuf::from(app_dir).join(".config").join(APP_NAME))
}
}

#[cfg(not(target_os = "windows"))]
Ok(home_dir()
.ok_or(anyhow::anyhow!("failed to get the app home dir"))?
.join(".config")
.join(APP_DIR))
.join(APP_NAME))
}

/// get the resources dir
Expand Down
2 changes: 1 addition & 1 deletion locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
},
"dialog": {
"panic": "请将此问题汇报到 Github 问题追踪器",
"migrate": "检测到旧版本配置文件\\n是否迁移到新版本?\\n警告: 此操作会覆盖掉现有配置文件"
"migrate": "检测到旧版本配置文件\n是否迁移到新版本?\n警告: 此操作会覆盖掉现有配置文件"
}
}
4 changes: 2 additions & 2 deletions manifest/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 1,
"latest": {
"mihomo": "v1.18.1",
"mihomo_alpha": "alpha-e582941",
"mihomo_alpha": "alpha-f0bc685",
"clash_rs": "v0.1.14",
"clash_premium": "2023-09-05-gdcc8d87"
},
Expand Down Expand Up @@ -36,5 +36,5 @@
"darwin-x64": "clash-darwin-amd64-n{}.gz"
}
},
"updated_at": "2024-02-26T22:25:41.397Z"
"updated_at": "2024-02-27T22:25:45.188Z"
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@dnd-kit/core": "6.1.0",
"@dnd-kit/sortable": "8.0.0",
"@dnd-kit/utilities": "3.2.2",
"@emotion/react": "11.11.3",
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.0",
"@juggle/resize-observer": "3.4.0",
"@mui/icons-material": "5.15.11",
Expand Down Expand Up @@ -96,13 +96,13 @@
},
"devDependencies": {
"@actions/github": "6.0.0",
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "18.6.2",
"@commitlint/cli": "19.0.1",
"@commitlint/config-conventional": "19.0.0",
"@tauri-apps/cli": "1.5.10",
"@types/fs-extra": "11.0.4",
"@types/js-cookie": "3.0.6",
"@types/lodash-es": "4.17.12",
"@types/react": "18.2.59",
"@types/react": "18.2.60",
"@types/react-dom": "18.2.19",
"@types/react-transition-group": "4.4.10",
"@typescript-eslint/eslint-plugin": "7.1.0",
Expand Down
Loading

0 comments on commit 18f44a8

Please sign in to comment.