mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-09 11:52:08 +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")
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user