新后台任务

This commit is contained in:
2026-06-09 20:42:30 +08:00
parent 143b8f3b24
commit 9c6c8a5c38
4 changed files with 18 additions and 208 deletions

View File

@@ -257,8 +257,19 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
: undefined,
});
async ensureBatteryOptimizationIgnored() {
if (Platform.OS !== 'android') return;
try {
const mod = NativeModules.ProxyServiceModule;
if (!mod) return;
const ignored = await mod.isBatteryOptimizationIgnored();
if (!ignored) await mod.requestIgnoreBatteryOptimization();
} catch (_) {}
}
async startProxyClient() {
try {
await this.ensureBatteryOptimizationIgnored();
this.clientId = DeviceInfo.getUniqueIdSync();
const userId = Api.instance.getUserId();
this.setState({ proxyStatus: 'connecting' });
@@ -268,12 +279,17 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
);
proxyBackgroundService.setTokenAutoRebindEnabled(this.state.tokenAutoRebind);
await proxyBackgroundService.start({
wsUrl: Api.WS_URL, clientId: this.clientId || '', userId,
debug: true, heartbeatInterval: 10000, reconnectInterval: 5000, reconnectMaxAttempts: Infinity,
wsUrl: Api.WS_URL,
clientId: this.clientId || '',
userId,
heartbeatInterval: 10000,
reconnectInterval: 5000,
reconnectMaxAttempts: Infinity,
onConnected: () => this.setState({ proxyStatus: 'connected' }),
onDisconnected: () => this.setState({ proxyStatus: 'disconnected' }),
onError: (error: string) => this.setState({ proxyStatus: 'error', proxyError: error }),
});
} catch (error) {
console.error('[Proxy] init failed:', error);
}