mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 16:30:52 +08:00
build: Update Cargo Depends
This commit is contained in:
@@ -4,7 +4,6 @@ use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tauri::{AppHandle, GlobalShortcutManager};
|
||||
use wry::application::accelerator::Accelerator;
|
||||
|
||||
pub struct Hotkey {
|
||||
current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置
|
||||
@@ -35,7 +34,7 @@ impl Hotkey {
|
||||
|
||||
match (key, func) {
|
||||
(Some(key), Some(func)) => {
|
||||
log_err!(Self::check_key(key).and_then(|_| self.register(key, func)));
|
||||
log_err!(self.register(key, func));
|
||||
}
|
||||
_ => {
|
||||
let key = key.unwrap_or("None");
|
||||
@@ -50,16 +49,6 @@ impl Hotkey {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 检查一个键是否合法
|
||||
fn check_key(hotkey: &str) -> Result<()> {
|
||||
// fix #287
|
||||
// tauri的这几个方法全部有Result expect,会panic,先检测一遍避免挂了
|
||||
if hotkey.parse::<Accelerator>().is_err() {
|
||||
bail!("invalid hotkey `{hotkey}`");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_manager(&self) -> Result<impl GlobalShortcutManager> {
|
||||
let app_handle = self.app_handle.lock();
|
||||
if app_handle.is_none() {
|
||||
@@ -109,11 +98,6 @@ impl Hotkey {
|
||||
|
||||
let (del, add) = Self::get_diff(old_map, new_map);
|
||||
|
||||
// 先检查一遍所有新的热键是不是可以用的
|
||||
for (hotkey, _) in add.iter() {
|
||||
Self::check_key(hotkey)?;
|
||||
}
|
||||
|
||||
del.iter().for_each(|key| {
|
||||
let _ = self.unregister(key);
|
||||
});
|
||||
|
||||
@@ -204,11 +204,11 @@ impl Tray {
|
||||
"open_window" => resolve::create_window(app_handle),
|
||||
"system_proxy" => feat::toggle_system_proxy(),
|
||||
"tun_mode" => feat::toggle_tun_mode(),
|
||||
"copy_env_sh" => feat::copy_clash_env("sh"),
|
||||
"copy_env_sh" => feat::copy_clash_env(app_handle, "sh"),
|
||||
#[cfg(target_os = "windows")]
|
||||
"copy_env_cmd" => feat::copy_clash_env("cmd"),
|
||||
"copy_env_cmd" => feat::copy_clash_env(app_handle, "cmd"),
|
||||
#[cfg(target_os = "windows")]
|
||||
"copy_env_ps" => feat::copy_clash_env("ps"),
|
||||
"copy_env_ps" => feat::copy_clash_env(app_handle, "ps"),
|
||||
"open_app_dir" => crate::log_err!(cmds::open_app_dir()),
|
||||
"open_core_dir" => crate::log_err!(cmds::open_core_dir()),
|
||||
"open_logs_dir" => crate::log_err!(cmds::open_logs_dir()),
|
||||
|
||||
@@ -3,7 +3,7 @@ use anyhow::Result;
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
pub fn use_script(script: String, config: Mapping) -> Result<(Mapping, Vec<(String, String)>)> {
|
||||
use rquickjs::{Context, Func, Runtime};
|
||||
use rquickjs::{function::Func, Context, Runtime};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
let runtime = Runtime::new().unwrap();
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::log_err;
|
||||
use crate::utils::resolve;
|
||||
use anyhow::{bail, Result};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use wry::application::clipboard::Clipboard;
|
||||
use tauri::{AppHandle, ClipboardManager};
|
||||
|
||||
// 打开面板
|
||||
pub fn open_dashboard() {
|
||||
@@ -337,7 +337,7 @@ async fn update_core_config() -> Result<()> {
|
||||
}
|
||||
|
||||
/// copy env variable
|
||||
pub fn copy_clash_env(option: &str) {
|
||||
pub fn copy_clash_env(app_handle: &AppHandle, option: &str) {
|
||||
let port = { Config::verge().latest().verge_mixed_port.unwrap_or(7890) };
|
||||
let http_proxy = format!("http://127.0.0.1:{}", port);
|
||||
let socks5_proxy = format!("socks5://127.0.0.1:{}", port);
|
||||
@@ -346,13 +346,12 @@ pub fn copy_clash_env(option: &str) {
|
||||
format!("export https_proxy={http_proxy} http_proxy={http_proxy} all_proxy={socks5_proxy}");
|
||||
let cmd: String = format!("set http_proxy={http_proxy} \n set https_proxy={http_proxy}");
|
||||
let ps: String = format!("$env:HTTP_PROXY=\"{http_proxy}\"; $env:HTTPS_PROXY=\"{http_proxy}\"");
|
||||
|
||||
let mut cliboard = Clipboard::new();
|
||||
let mut cliboard = app_handle.clipboard_manager();
|
||||
|
||||
match option {
|
||||
"sh" => cliboard.write_text(sh),
|
||||
"cmd" => cliboard.write_text(cmd),
|
||||
"ps" => cliboard.write_text(ps),
|
||||
"sh" => cliboard.write_text(sh).unwrap_or_default(),
|
||||
"cmd" => cliboard.write_text(cmd).unwrap_or_default(),
|
||||
"ps" => cliboard.write_text(ps).unwrap_or_default(),
|
||||
_ => log::error!(target: "app", "copy_clash_env: Invalid option! {option}"),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user