fix bugs
This commit is contained in:
@@ -13,6 +13,24 @@ export interface WalletItem {
|
||||
const DEFAULT_DOMAIN = 'aa.pfgame.org';
|
||||
const STORAGE_KEY = 'server_domain';
|
||||
const HTTPS_KEY = 'server_https';
|
||||
const TOKEN_AUTO_REBIND_KEY = 'token_auto_rebind_enabled';
|
||||
const TOKEN_AUTO_REBIND_SCAN_MS_KEY = 'token_auto_rebind_scan_ms';
|
||||
const TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY = 'token_auto_rebind_cooldown_ms';
|
||||
const TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY = 'token_auto_rebind_fail_cooldown_ms';
|
||||
const TOKEN_AUTO_REBIND_DEBUG_KEY = 'token_auto_rebind_debug';
|
||||
|
||||
/** 扫 list 间隔 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_SCAN_MS = 1 * 60 * 1000;
|
||||
/** 重绑成功后冷却 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_COOLDOWN_MS = 1 * 60 * 1000;
|
||||
/** 重绑失败后冷却 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS = 1 * 60 * 1000;
|
||||
|
||||
let _tokenAutoRebindEnabled = false;
|
||||
let _tokenAutoRebindDebug = false;
|
||||
let _tokenAutoRebindScanMs = DEFAULT_TOKEN_AUTO_REBIND_SCAN_MS;
|
||||
let _tokenAutoRebindCooldownMs = DEFAULT_TOKEN_AUTO_REBIND_COOLDOWN_MS;
|
||||
let _tokenAutoRebindFailCooldownMs = DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS;
|
||||
|
||||
let _domain = DEFAULT_DOMAIN;
|
||||
let _useHttps = true;
|
||||
@@ -22,10 +40,74 @@ export async function loadServerDomain(): Promise<string> {
|
||||
if (saved) _domain = saved;
|
||||
const https = await AsyncStorage.getItem(HTTPS_KEY);
|
||||
if (https !== null) _useHttps = https === 'true';
|
||||
const autoRebind = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_KEY);
|
||||
_tokenAutoRebindEnabled = autoRebind === 'true';
|
||||
const scanMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_SCAN_MS_KEY);
|
||||
const cooldownMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY);
|
||||
if (scanMs) {
|
||||
const n = parseInt(scanMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindScanMs = n;
|
||||
}
|
||||
if (cooldownMs) {
|
||||
const n = parseInt(cooldownMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindCooldownMs = n;
|
||||
}
|
||||
const failCooldownMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY);
|
||||
if (failCooldownMs) {
|
||||
const n = parseInt(failCooldownMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindFailCooldownMs = n;
|
||||
}
|
||||
const debug = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_DEBUG_KEY);
|
||||
_tokenAutoRebindDebug = debug === 'true';
|
||||
console.log('loadServerDomain', _domain, 'https:', _useHttps);
|
||||
return _domain;
|
||||
}
|
||||
|
||||
export function getTokenAutoRebindOptions(): {
|
||||
scanIntervalMs: number;
|
||||
cooldownMs: number;
|
||||
failCooldownMs: number;
|
||||
debugLog: boolean;
|
||||
} {
|
||||
return {
|
||||
scanIntervalMs: _tokenAutoRebindScanMs,
|
||||
cooldownMs: _tokenAutoRebindCooldownMs,
|
||||
failCooldownMs: _tokenAutoRebindFailCooldownMs,
|
||||
debugLog: _tokenAutoRebindDebug,
|
||||
};
|
||||
}
|
||||
|
||||
export function getTokenAutoRebindDebug(): boolean {
|
||||
return _tokenAutoRebindDebug;
|
||||
}
|
||||
|
||||
export async function saveTokenAutoRebindDebug(enabled: boolean): Promise<void> {
|
||||
_tokenAutoRebindDebug = enabled;
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_DEBUG_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export async function saveTokenAutoRebindOptions(
|
||||
scanIntervalMs: number,
|
||||
cooldownMs: number,
|
||||
failCooldownMs: number = DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS,
|
||||
): Promise<void> {
|
||||
_tokenAutoRebindScanMs = scanIntervalMs;
|
||||
_tokenAutoRebindCooldownMs = cooldownMs;
|
||||
_tokenAutoRebindFailCooldownMs = failCooldownMs;
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_SCAN_MS_KEY, String(scanIntervalMs));
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY, String(cooldownMs));
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY, String(failCooldownMs));
|
||||
}
|
||||
|
||||
export function getTokenAutoRebindEnabled(): boolean {
|
||||
return _tokenAutoRebindEnabled;
|
||||
}
|
||||
|
||||
export async function saveTokenAutoRebindEnabled(enabled: boolean): Promise<void> {
|
||||
_tokenAutoRebindEnabled = enabled;
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export async function saveServerDomain(domain: string, useHttps: boolean): Promise<void> {
|
||||
_domain = domain;
|
||||
_useHttps = useHttps;
|
||||
|
||||
Reference in New Issue
Block a user