fix(clipboard): propagate proxy environment copy failures

This commit is contained in:
Tunglies
2026-10-08 02:12:24 +08:00
parent 5ed291c91f
commit e3dc0b2b5b
4 changed files with 29 additions and 11 deletions
+1 -2
View File
@@ -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]
+9 -1
View File
@@ -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;
}
+6 -6
View File
@@ -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")
}
+13 -2
View File
@@ -9,6 +9,7 @@ import { useVerge } from '@/hooks/use-verge'
import { navigationItems } from '@/pages/_navigation-meta'
import { copyClashEnv } from '@/services/cmds'
import { supportedLanguages } from '@/services/i18n'
import { mutate } from '@/services/mutate'
import { showNotice } from '@/services/notice-service'
import getSystem from '@/utils/get-system'
@@ -74,8 +75,18 @@ const SettingVergeBasic = ({ onError }: Props) => {
}
const onCopyClashEnv = useCallback(async () => {
await copyClashEnv()
showNotice.success('shared.feedback.notifications.common.copySuccess', 1000)
try {
await mutate(copyClashEnv, {
id: 'copy-clash-env',
onFulfilled: () =>
showNotice.success(
'shared.feedback.notifications.common.copySuccess',
1000,
),
})
} catch {
// The shared mutation boundary reports the failure.
}
}, [])
return (