Skip to content

Commit 0bd2a59

Browse files
authored
🐛 fix: resolve server version check issue for desktop app (#11834)
- Fix version check to only run for self-hosted remote server mode - Get remote server URL from electron store for proper origin detection - Remove unnecessary isDesktop parameter from useCheckServerVersion hook
1 parent cfc03dd commit 0bd2a59

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/app/[variants]/(main)/settings/about/features/Version.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
66

77
import { ProductLogo } from '@/components/Branding';
88
import { CHANGELOG_URL, MANUAL_UPGRADE_URL, OFFICIAL_SITE } from '@/const/url';
9-
import { CURRENT_VERSION, isDesktop } from '@/const/version';
9+
import { CURRENT_VERSION } from '@/const/version';
1010
import { useNewVersion } from '@/features/User/UserPanel/useNewVersion';
1111
import { useGlobalStore } from '@/store/global';
1212

@@ -25,7 +25,7 @@ const Version = memo<{ mobile?: boolean }>(({ mobile }) => {
2525
]);
2626
const { t } = useTranslation('common');
2727

28-
useCheckServerVersion(isDesktop);
28+
useCheckServerVersion();
2929

3030
const showServerVersion = serverVersion && serverVersion !== CURRENT_VERSION;
3131

src/layout/GlobalProvider/StoreInitialization.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { memo } from 'react';
55
import { useTranslation } from 'react-i18next';
66
import { createStoreUpdater } from 'zustand-utils';
77

8-
import { isDesktop } from '@/const/version';
98
import { useIsMobile } from '@/hooks/useIsMobile';
109
import { useAgentStore } from '@/store/agent';
1110
import { useAiInfraStore } from '@/store/aiInfra';
@@ -44,7 +43,7 @@ const StoreInitialization = memo(() => {
4443
useInitSystemStatus();
4544

4645
// check server version in desktop app
47-
useCheckServerVersion(isDesktop);
46+
useCheckServerVersion();
4847

4948
// fetch server config
5049
const useFetchServerConfig = useServerConfigStore((s) => s.useInitServerConfig);

src/services/global.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { isDesktop } from '@lobechat/const';
12
import type { PartialDeep } from 'type-fest';
23

34
import type { VersionResponseData } from '@/app/(backend)/api/version/route';
45
import { BusinessGlobalService } from '@/business/client/services/BusinessGlobalService';
56
import { lambdaClient } from '@/libs/trpc/client';
7+
import { getElectronStoreState } from '@/store/electron';
8+
import { electronSyncSelectors } from '@/store/electron/selectors';
69
import { type LobeAgentConfig } from '@/types/agent';
710
import { type GlobalRuntimeConfig } from '@/types/serverConfig';
811

@@ -26,7 +29,26 @@ class GlobalService extends BusinessGlobalService {
2629
* @throws Error for other failures (network errors, 500s, etc.) to allow SWR retry
2730
*/
2831
getServerVersion = async (): Promise<string | null> => {
29-
const res = await fetch(SERVER_VERSION_URL);
32+
const origin = (() => {
33+
if (isDesktop) {
34+
const remoteServerUrl = electronSyncSelectors.remoteServerUrl(getElectronStoreState());
35+
if (!remoteServerUrl) return undefined;
36+
37+
try {
38+
return new URL(remoteServerUrl).origin;
39+
} catch {
40+
// fallback: use as-is; URL construction below will throw if invalid
41+
return remoteServerUrl;
42+
}
43+
}
44+
45+
return undefined;
46+
})();
47+
48+
if (!origin) return null;
49+
50+
const url = new URL(SERVER_VERSION_URL, origin).toString();
51+
const res = await fetch(url);
3052

3153
// Only treat 404 as "server doesn't support version API"
3254
// Other errors (500, network issues) should throw to allow retry

src/store/global/actions/general.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type { StateCreator } from 'zustand/vanilla';
66
import { CURRENT_VERSION, isDesktop } from '@/const/version';
77
import { useOnlyFetchOnceSWR } from '@/libs/swr';
88
import { globalService } from '@/services/global';
9+
import { getElectronStoreState } from '@/store/electron';
10+
import { electronSyncSelectors } from '@/store/electron/selectors';
911
import type { SystemStatus } from '@/store/global/initialState';
1012
import { type LocaleMode } from '@/types/locale';
1113
import { switchLang } from '@/utils/client/switchLang';
@@ -23,7 +25,7 @@ export interface GlobalGeneralAction {
2325
updateResourceManagerColumnWidth: (column: 'name' | 'date' | 'size', width: number) => void;
2426
updateSystemStatus: (status: Partial<SystemStatus>, action?: any) => void;
2527
useCheckLatestVersion: (enabledCheck?: boolean) => SWRResponse<string>;
26-
useCheckServerVersion: (enabledCheck?: boolean) => SWRResponse<string | null>;
28+
useCheckServerVersion: () => SWRResponse<string | null>;
2729
useInitSystemStatus: () => SWRResponse;
2830
}
2931

@@ -161,9 +163,13 @@ export const generalActionSlice: StateCreator<
161163
},
162164
),
163165

164-
useCheckServerVersion: (enabledCheck = true) =>
166+
useCheckServerVersion: () =>
165167
useOnlyFetchOnceSWR(
166-
enabledCheck ? 'checkServerVersion' : null,
168+
isDesktop &&
169+
// only check server version for self-hosted remote server
170+
electronSyncSelectors.storageMode(getElectronStoreState()) !== 'cloud'
171+
? 'checkServerVersion'
172+
: null,
167173
async () => globalService.getServerVersion(),
168174
{
169175
onSuccess: (data: string | null) => {

0 commit comments

Comments
 (0)