Skip to content

Commit de82fef

Browse files
committed
feat: support local mihomo proxy bindings
1 parent dfbc228 commit de82fef

30 files changed

Lines changed: 2079 additions & 1392 deletions

File tree

plugins/layouts/app-layout/src/components/app-sidebar.tsx

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { FreeQuotaUsage } from './free-quota-usage';
3030
import { getGeneralSettings, useMihomoRuntimeStore } from '../../../../services/store/src';
3131
import { ClashIcon } from '../../../../pages/proxy-center/src/mihomo/clash-icon';
3232
import { MihomoConnectDialog } from '../../../../pages/proxy-center/src/mihomo/mihomo-connect-dialog';
33-
import { getMihomoStatus } from '../../../../pages/proxy-center/src/mihomo/api';
3433

3534
interface NavItemData {
3635
label: string;
@@ -572,23 +571,10 @@ export const AppSidebar: React.FC = () => {
572571
const [isAnimating, setIsAnimating] = useState(false);
573572
const [settingsLoaded, setSettingsLoaded] = useState(false);
574573
const [mihomoDialogOpen, setMihomoDialogOpen] = useState(false);
575-
const [mihomoAttached, setMihomoAttached] = useState(false);
576574
const mihomoRunning = useMihomoRuntimeStore((state) => state.running);
575+
const mihomoAttached = useMihomoRuntimeStore((state) => state.attached);
577576
const mihomoCheckedAt = useMihomoRuntimeStore((state) => state.checkedAt);
578577

579-
const refreshMihomoAttached = useRef(async (cancelledRef?: { current: boolean }) => {
580-
try {
581-
const status = await getMihomoStatus();
582-
if (!cancelledRef?.current) {
583-
setMihomoAttached(status.attached);
584-
}
585-
} catch {
586-
if (!cancelledRef?.current) {
587-
setMihomoAttached(false);
588-
}
589-
}
590-
});
591-
592578
useEffect(() => {
593579
let cancelled = false;
594580

@@ -610,30 +596,21 @@ export const AppSidebar: React.FC = () => {
610596
};
611597
}, []);
612598

613-
useEffect(() => {
614-
const cancelledRef = { current: false };
615-
599+
const handleOpenMihomo = async () => {
616600
if (!mihomoRunning) {
617-
setMihomoAttached(false);
618-
return () => {
619-
cancelledRef.current = true;
620-
};
601+
navigate('/proxy?mode=local');
602+
return;
621603
}
622604

623-
void refreshMihomoAttached.current(cancelledRef);
605+
await useMihomoRuntimeStore.getState().refresh();
606+
const { running, attached } = useMihomoRuntimeStore.getState();
624607

625-
return () => {
626-
cancelledRef.current = true;
627-
};
628-
}, [location.pathname, mihomoRunning]);
629-
630-
const handleOpenMihomo = () => {
631-
if (!mihomoRunning) {
608+
if (!running) {
632609
navigate('/proxy?mode=local');
633610
return;
634611
}
635612

636-
if (mihomoAttached) {
613+
if (attached) {
637614
navigate('/proxy/mihomo');
638615
return;
639616
}
@@ -731,7 +708,7 @@ export const AppSidebar: React.FC = () => {
731708
open={mihomoDialogOpen}
732709
onOpenChange={setMihomoDialogOpen}
733710
onConnected={() => {
734-
setMihomoAttached(true);
711+
void useMihomoRuntimeStore.getState().refresh();
735712
navigate('/proxy/mihomo');
736713
}}
737714
/>

plugins/pages/create-window/src/components/create-window-content.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -421,22 +421,26 @@ export function CreateWindowContent({
421421
}}
422422
id="network-location"
423423
>
424-
<NetworkLocationForm
425-
basicSettings={windowConfig.basicSettings}
426-
advancedSettings={windowConfig.advancedFingerprintSettings}
427-
proxyUuids={windowConfig.windowInfo.proxyUuids}
428-
createCount={isEditMode ? undefined : createCount}
429-
onBasicSettingsChange={(value) => handleConfigUpdate('basicSettings', value)}
430-
onAdvancedSettingsChange={(value) =>
431-
handleConfigUpdate('advancedFingerprintSettings', value)
432-
}
433-
onProxyUuidsChange={(value) =>
434-
handleConfigUpdate('windowInfo', {
435-
...windowConfig.windowInfo,
436-
proxyUuids: value,
437-
})
438-
}
439-
/>
424+
<NetworkLocationForm
425+
basicSettings={windowConfig.basicSettings}
426+
advancedSettings={windowConfig.advancedFingerprintSettings}
427+
proxySourceMode={windowConfig.windowInfo.proxySourceMode}
428+
proxyUuids={windowConfig.windowInfo.proxyUuids}
429+
localProxyNodeNames={windowConfig.windowInfo.localProxyNodeNames}
430+
createCount={isEditMode ? 1 : createCount}
431+
onBasicSettingsChange={(value) => handleConfigUpdate('basicSettings', value)}
432+
onAdvancedSettingsChange={(value) =>
433+
handleConfigUpdate('advancedFingerprintSettings', value)
434+
}
435+
onProxySelectionChange={(value) =>
436+
handleConfigUpdate('windowInfo', {
437+
...windowConfig.windowInfo,
438+
proxySourceMode: value.mode,
439+
proxyUuids: value.remoteProxyUuids,
440+
localProxyNodeNames: value.localProxyNodeNames,
441+
})
442+
}
443+
/>
440444
</div>
441445

442446
{/* 指纹伪装 */}

0 commit comments

Comments
 (0)