diff --git a/lib/logic/power_settings.dart b/lib/logic/power_settings.dart index cee5934..c4ea368 100644 --- a/lib/logic/power_settings.dart +++ b/lib/logic/power_settings.dart @@ -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 runtimeState() async { - if (kIsWeb) return const VpnRuntimeState(processAlive: false, vpnTransport: false); - try { - final result = await _channel.invokeMapMethod( - '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 setSessionExpiry(int expiresAtMs) async { - if (kIsWeb) return; - try { - await _channel.invokeMethod('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); }