summaryrefslogtreecommitdiff
path: root/src/store/configs.ts
diff options
context:
space:
mode:
authorLarvan2 <[email protected]>2026-06-04 21:25:02 +0800
committerLarvan2 <[email protected]>2026-06-04 21:25:02 +0800
commita8f8bb1d6b9925425b5b1121de0ea1c0de1645ed (patch)
tree0ff036d5c79f4315f715231c78f9557419c83bc8 /src/store/configs.ts
parentcc6efa25afc9853771565a5f68d1cc24b3a945b2 (diff)
feat(configs): add signal support and timeout for fetchConfigsHEADmaster
Diffstat (limited to 'src/store/configs.ts')
-rw-r--r--src/store/configs.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/store/configs.ts b/src/store/configs.ts
index df26517..b84471b 100644
--- a/src/store/configs.ts
+++ b/src/store/configs.ts
@@ -17,15 +17,24 @@ export const getConfigs = (s: State) => s.configs.configs;
export const getHaveFetched = (s: State) => s.configs.haveFetchedConfig;
export const getLogLevel = (s: State) => s.configs.configs['log-level'];
+const STARTUP_TIMEOUT_MS = 2000;
+
export function fetchConfigs(apiConfig: ClashAPIConfig) {
return async (dispatch: DispatchFn, getState: GetStateFn) => {
let res: Response;
+ const haveFetched = getHaveFetched(getState());
+ const controller = new AbortController();
+ const timeoutId = haveFetched
+ ? null
+ : setTimeout(() => controller.abort(), STARTUP_TIMEOUT_MS);
try {
- res = await configsAPI.fetchConfigs(apiConfig);
+ res = await configsAPI.fetchConfigs(apiConfig, haveFetched ? undefined : controller.signal);
} catch (err) {
- // TypeError and AbortError
+ // TypeError and AbortError (includes timeout)
dispatch(openModal('apiConfig'));
return;
+ } finally {
+ if (timeoutId !== null) clearTimeout(timeoutId);
}
if (!res.ok) {