refactor(app): drop Dart wrappers whose native handlers no longer exist
#17 removed the `setSessionExpiry` and `isVpnRuntimeAlive` MethodChannel handlers from MainActivity, and #18 removed their last callers. The Dart wrappers stayed behind. Both swallow their errors, so a future caller would not fail loudly — it would get a silent no-op from `setSessionExpiry` and a permanent `processAlive: false` from `runtimeState()`, which previously read as "the tunnel is dead". Deleting them keeps that trap out of the codebase. `VpnRuntimeState` goes with them; runtime liveness now arrives through the native status stream, which is generation-scoped. The battery-optimisation methods are untouched and still used by background_reliability.dart. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019HT2x2JvJNg7XNsJubfHFf
This commit is contained in:
1 parent
061bd41920
commit
bd41a3c693
1 file changed
-49
@@ -41,53 +41,4 @@ abstract final class PowerSettings {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the VPN runtime is genuinely alive.
|
||||
///
|
||||
/// The Xray service runs in a separate process, so nothing it stores in
|
||||
/// statics is visible to us. This asks the OS instead: is our service process
|
||||
/// running, and (for TUN) is there an active VPN transport?
|
||||
static Future<VpnRuntimeState> runtimeState() async {
|
||||
if (kIsWeb) return const VpnRuntimeState(processAlive: false, vpnTransport: false);
|
||||
try {
|
||||
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||
'isVpnRuntimeAlive',
|
||||
);
|
||||
return VpnRuntimeState(
|
||||
processAlive: result?['processAlive'] == true,
|
||||
vpnTransport: result?['vpnTransport'] == true,
|
||||
);
|
||||
} catch (_) {
|
||||
return const VpnRuntimeState(processAlive: false, vpnTransport: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Pushes the absolute session-expiry timestamp (epoch ms) to the VPN
|
||||
/// service so it can tear the tunnel down even when the UI process is gone.
|
||||
static Future<void> setSessionExpiry(int expiresAtMs) async {
|
||||
if (kIsWeb) return;
|
||||
try {
|
||||
await _channel.invokeMethod<void>('setSessionExpiry', {
|
||||
'expiresAtMs': expiresAtMs,
|
||||
});
|
||||
} catch (_) {
|
||||
// Best-effort. The daemon also keeps its last persisted expiry.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class VpnRuntimeState {
|
||||
final bool processAlive;
|
||||
final bool vpnTransport;
|
||||
|
||||
const VpnRuntimeState({
|
||||
required this.processAlive,
|
||||
required this.vpnTransport,
|
||||
});
|
||||
|
||||
/// TUN needs both a live service and a real VPN interface. Proxy mode has no
|
||||
/// VPN interface at all, so the service process is the whole signal.
|
||||
bool aliveFor({required bool tunMode}) =>
|
||||
processAlive && (!tunMode || vpnTransport);
|
||||
}
|
||||
Reference in new issue
Block a user