mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-16 07:52:06 +08:00
fix(clipboard): propagate proxy environment copy failures
This commit is contained in:
@@ -18,8 +18,7 @@ use tokio::fs;
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn copy_clash_env() -> CmdResult {
|
||||
feat::copy_clash_env().await;
|
||||
Ok(())
|
||||
feat::copy_clash_env().await.stringify_err()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -948,7 +948,15 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
logging!(error, Type::Tray, "Failed to close all connections from tray: {err}");
|
||||
}
|
||||
}
|
||||
MenuIds::COPY_ENV => feat::copy_clash_env().await,
|
||||
MenuIds::COPY_ENV => {
|
||||
if let Err(err) = feat::copy_clash_env().await {
|
||||
logging!(
|
||||
error,
|
||||
Type::Tray,
|
||||
"Failed to copy proxy environment variables from tray: {err:#}"
|
||||
);
|
||||
}
|
||||
}
|
||||
MenuIds::CONF_DIR => {
|
||||
let _ = cmd::open_app_dir().await;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
window_manager::WindowManager,
|
||||
},
|
||||
};
|
||||
use anyhow::Context as _;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use std::env;
|
||||
use tauri_plugin_clipboard_manager::ClipboardExt as _;
|
||||
@@ -95,7 +96,7 @@ pub async fn toggle_tun_mode(not_save_file: Option<bool>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn copy_clash_env() {
|
||||
pub async fn copy_clash_env() -> anyhow::Result<()> {
|
||||
let env_ip = env::var("CLASH_VERGE_REV_IP").ok();
|
||||
let verge_cfg = Config::verge().await.latest_arc();
|
||||
let ip = env_ip
|
||||
@@ -133,12 +134,11 @@ pub async fn copy_clash_env() {
|
||||
}
|
||||
"fish" => format!("set -x http_proxy {http_proxy}; set -x https_proxy {http_proxy}"),
|
||||
_ => {
|
||||
logging!(error, Type::ProxyMode, "copy_clash_env: Invalid env type! {env_type}");
|
||||
return;
|
||||
anyhow::bail!("Invalid environment variable format: {env_type}");
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(err) = clipboard.write_text(&export_text) {
|
||||
logging!(error, Type::ProxyMode, "Failed to write to clipboard: {err}");
|
||||
}
|
||||
clipboard
|
||||
.write_text(export_text)
|
||||
.context("Failed to write proxy environment variables to clipboard")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user