mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-24 04:04:40 +08:00
fix(init): resolve startup error message timing issue
Fix race condition where 'please check network or server address' error was shown on first startup even when API was properly configured. - Add isLoadingServerConfig state to track server config fetch status - Modify authStore to wait for server config loading before showing errors - Ensure loadSettings completes fully before triggering login checks - Only show network error when config fetch actually fails, not during loading
This commit is contained in:
@@ -15,6 +15,7 @@ interface SettingsState {
|
||||
};
|
||||
isModalVisible: boolean;
|
||||
serverConfig: ServerConfig | null;
|
||||
isLoadingServerConfig: boolean;
|
||||
loadSettings: () => Promise<void>;
|
||||
fetchServerConfig: () => Promise<void>;
|
||||
setApiBaseUrl: (url: string) => void;
|
||||
@@ -33,6 +34,7 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
|
||||
remoteInputEnabled: false,
|
||||
isModalVisible: false,
|
||||
serverConfig: null,
|
||||
isLoadingServerConfig: false,
|
||||
videoSource: {
|
||||
enabledAll: true,
|
||||
sources: {},
|
||||
@@ -48,10 +50,13 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
|
||||
sources: {},
|
||||
},
|
||||
});
|
||||
api.setBaseUrl(settings.apiBaseUrl);
|
||||
await get().fetchServerConfig();
|
||||
if (settings.apiBaseUrl) {
|
||||
api.setBaseUrl(settings.apiBaseUrl);
|
||||
await get().fetchServerConfig();
|
||||
}
|
||||
},
|
||||
fetchServerConfig: async () => {
|
||||
set({ isLoadingServerConfig: true });
|
||||
try {
|
||||
const config = await api.getServerConfig();
|
||||
if (config) {
|
||||
@@ -61,6 +66,8 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
|
||||
} catch (error) {
|
||||
set({ serverConfig: null });
|
||||
console.info("Failed to fetch server config:", error);
|
||||
} finally {
|
||||
set({ isLoadingServerConfig: false });
|
||||
}
|
||||
},
|
||||
setApiBaseUrl: (url) => set({ apiBaseUrl: url }),
|
||||
|
||||
Reference in New Issue
Block a user