Files
ReVoltVPN/lib/logic/connection_settings.dart
T
esefxdz 9ac236a981 feat(app): OS session-expiry enforcement, session persistence, support sync
Enforce session expiry at the OS level (AlarmManager + handler) so the tunnel dies even if the UI process is killed; persist the session so a START_STICKY restart re-establishes it; sync immediately after a support top-up; slow the session beacon 5s/30s -> 60s/60s; drop the Always-on-VPN deep-link and the legacy 'ass' migration. Docs: CHANGELOG 3.3.4, privacy-policy log disclosure, README.
2026-09-02 20:33:33 +03:00

41 lines
1.1 KiB
Dart

import 'package:shared_preferences/shared_preferences.dart';
enum ConnectionMode { tun, proxy }
abstract final class ConnectionSettings {
ConnectionSettings._();
static const String _modeKey = 'connection_mode';
static ConnectionMode _mode = ConnectionMode.tun;
static bool _initialized = false;
static ConnectionMode get mode => _mode;
static Future<void> initialize() async {
if (_initialized) return;
final prefs = await SharedPreferences.getInstance();
final storedMode = prefs.getString(_modeKey);
// Any unrecognized value (including the pre-V3 'auto') is TUN. 'proxy' is
// the only persisted value that selects the SOCKS5 mode.
_mode = storedMode == ConnectionMode.proxy.name
? ConnectionMode.proxy
: ConnectionMode.tun;
if (storedMode != _mode.name) {
await prefs.setString(_modeKey, _mode.name);
}
_initialized = true;
}
static Future<void> setMode(ConnectionMode mode) async {
_mode = mode;
_initialized = true;
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_modeKey, mode.name);
}
}