新后台任务
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user