Skip to content

Commit b876a84

Browse files
committed
feat: self-heal mihomo local proxy listeners
1 parent de82fef commit b876a84

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

plugins/pages/proxy-center/src/components/proxy-header.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export function ProxyHeader({
109109
{t('header.modeLocal', { defaultValue: '本地代理' })}
110110
</button>
111111
</div>
112+
<div className="hidden items-center rounded-md border border-amber-500/25 bg-amber-500/10 px-2.5 py-1 text-[11px] font-medium text-amber-700 md:flex dark:text-amber-400">
113+
{t('header.experimentalHint', { defaultValue: '实验性功能' })}
114+
</div>
112115
</div>
113116
<div className="ml-auto flex items-center gap-2">
114117
<button

plugins/services/store/src/stores/mihomo-runtime/mihomo-runtime-store.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ export const useMihomoRuntimeStore = create<MihomoRuntimeState>((set, get) => ({
101101
status = null;
102102
}
103103

104+
if (status?.attached) {
105+
try {
106+
await invoke<boolean>('ensure_mihomo_local_proxy_listeners');
107+
} catch {
108+
// Keep the runtime status refresh lightweight; listener self-heal failure
109+
// should not block the main Mihomo status update cycle.
110+
}
111+
}
112+
104113
set({
105114
running: true,
106115
attached: status?.attached ?? false,

src-tauri/src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub fn register_handles() -> impl Fn(Invoke<tauri::Wry>) -> bool + Send + Sync +
121121
mihomo::get_mihomo_node_selection,
122122
mihomo::apply_mihomo_node_selection,
123123
mihomo::get_local_mihomo_proxies,
124+
mihomo::ensure_mihomo_local_proxy_listeners,
124125
mihomo::update_local_mihomo_proxy,
125126
// Store commands
126127
store::get_store_key,

src-tauri/src/commands/mihomo.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ pub async fn get_local_mihomo_proxies(
7070
AppContext::get().mihomo_manager.get_local_proxies(&app).await
7171
}
7272

73+
#[tauri::command]
74+
pub async fn ensure_mihomo_local_proxy_listeners(app: tauri::AppHandle) -> Result<bool, String> {
75+
AppContext::get()
76+
.mihomo_manager
77+
.ensure_local_proxy_listeners(&app)
78+
.await
79+
}
80+
7381
#[tauri::command]
7482
pub async fn update_local_mihomo_proxy(
7583
app: tauri::AppHandle,

src-tauri/src/services/mihomo/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,25 @@ impl MihomoManager {
242242
persist_local_proxies(app, &proxies)?;
243243
Ok(updated_proxy)
244244
}
245+
246+
pub async fn ensure_local_proxy_listeners(
247+
&self,
248+
app: &tauri::AppHandle,
249+
) -> Result<bool, String> {
250+
let config = require_connection_config(app)?;
251+
let proxies = load_local_proxies(app)
252+
.into_iter()
253+
.filter(|proxy| proxy.controller == config.controller)
254+
.collect::<Vec<_>>();
255+
256+
if proxies.is_empty() {
257+
return Ok(false);
258+
}
259+
260+
let client = MihomoClient::new(&config).map_err(|error| error.to_string())?;
261+
sync_local_listeners(&client, &config.config_path, &proxies).await?;
262+
Ok(true)
263+
}
245264
}
246265

247266
async fn build_overview(

0 commit comments

Comments
 (0)