mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 03:36:29 +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:
@@ -24,10 +24,34 @@ const useAuthStore = create<AuthState>((set) => ({
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const serverConfig = useSettingsStore.getState().serverConfig;
|
||||
// Wait for server config to be loaded if it's currently loading
|
||||
const settingsState = useSettingsStore.getState();
|
||||
let serverConfig = settingsState.serverConfig;
|
||||
|
||||
// If server config is loading, wait a bit for it to complete
|
||||
if (settingsState.isLoadingServerConfig) {
|
||||
// Wait up to 3 seconds for server config to load
|
||||
const maxWaitTime = 3000;
|
||||
const checkInterval = 100;
|
||||
let waitTime = 0;
|
||||
|
||||
while (waitTime < maxWaitTime) {
|
||||
await new Promise(resolve => setTimeout(resolve, checkInterval));
|
||||
waitTime += checkInterval;
|
||||
const currentState = useSettingsStore.getState();
|
||||
if (!currentState.isLoadingServerConfig) {
|
||||
serverConfig = currentState.serverConfig;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!serverConfig?.StorageType) {
|
||||
Toast.show({ type: "error", text1: "请检查网络或者服务器地址是否可用" });
|
||||
return
|
||||
// Only show error if we're not loading and have tried to fetch the config
|
||||
if (!settingsState.isLoadingServerConfig) {
|
||||
Toast.show({ type: "error", text1: "请检查网络或者服务器地址是否可用" });
|
||||
}
|
||||
return;
|
||||
}
|
||||
const cookies = await Cookies.get(api.baseURL);
|
||||
if (serverConfig && serverConfig.StorageType === "localstorage" && !cookies.auth) {
|
||||
|
||||
Reference in New Issue
Block a user