From 9d5d2bb73d05c5e65c66733f68a4c1d505913bc6 Mon Sep 17 00:00:00 2001 From: xmk23333 Date: Thu, 15 Jan 2026 18:06:37 +0800 Subject: [PATCH] fix: add defensive checks for undefined arrays to prevent find/filter errors --- src/main/core/mihomoApi.ts | 4 ++-- src/main/core/profileUpdater.ts | 2 +- src/main/resolve/gistApi.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 3534daf..4c9aeb5 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -105,14 +105,14 @@ export const mihomoGroups = async (): Promise => { if (proxies.proxies[name] && 'all' in proxies.proxies[name] && !proxies.proxies[name].hidden) { const newGroup = proxies.proxies[name] newGroup.testUrl = url - const newAll = newGroup.all.map((name) => proxies.proxies[name]) + const newAll = (newGroup.all || []).map((name) => proxies.proxies[name]) groups.push({ ...newGroup, all: newAll }) } }) if (!groups.find((group) => group.name === 'GLOBAL')) { const newGlobal = proxies.proxies['GLOBAL'] as IMihomoGroup if (!newGlobal.hidden) { - const newAll = newGlobal.all.map((name) => proxies.proxies[name]) + const newAll = (newGlobal.all || []).map((name) => proxies.proxies[name]) groups.push({ ...newGlobal, all: newAll }) } } diff --git a/src/main/core/profileUpdater.ts b/src/main/core/profileUpdater.ts index 511b03c..0b62134 100644 --- a/src/main/core/profileUpdater.ts +++ b/src/main/core/profileUpdater.ts @@ -13,7 +13,7 @@ async function updateProfile(id: string): Promise { } export async function initProfileUpdater(): Promise { - const { items, current } = await getProfileConfig() + const { items = [], current } = await getProfileConfig() const currentItem = await getCurrentProfileItem() for (const item of items.filter((i) => i.id !== current)) { diff --git a/src/main/resolve/gistApi.ts b/src/main/resolve/gistApi.ts index a144e60..cdf8e99 100644 --- a/src/main/resolve/gistApi.ts +++ b/src/main/resolve/gistApi.ts @@ -23,7 +23,7 @@ async function listGists(token: string): Promise { }, responseType: 'json' }) - return res.data as GistInfo[] + return Array.isArray(res.data) ? res.data : [] } async function createGist(token: string, content: string): Promise {