From cf385dec8aff395e43fb26a7c86bb616dc0a2ef1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Feb 2026 07:01:36 -0800 Subject: [PATCH] Remove migration code --- lib/main.dart | 1 - lib/password_service.dart | 13 +++---- lib/preferences.dart | 78 ++++++--------------------------------- 3 files changed, 17 insertions(+), 75 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 12634d8..c622eae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,7 +23,6 @@ void main() async { await Firebase.initializeApp(); FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; await Preferences.init(); - await Preferences.migrate(); await PasswordService.migrate(); await GeolocationService.init(); await PushService.init(); diff --git a/lib/password_service.dart b/lib/password_service.dart index 540882b..e207767 100644 --- a/lib/password_service.dart +++ b/lib/password_service.dart @@ -5,17 +5,16 @@ import 'package:traccar_client/preferences.dart'; class PasswordService { static final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); - static const String _passwordKey = 'password'; static Future migrate() async { - final oldPassword = await _secureStorage.read(key: _passwordKey); + final oldPassword = await _secureStorage.read(key: Preferences.password); if (oldPassword == null) return; - await Preferences.instance.setString(_passwordKey, oldPassword); - await _secureStorage.delete(key: _passwordKey); + await Preferences.instance.setString(Preferences.password, oldPassword); + await _secureStorage.delete(key: Preferences.password); } static Future authenticate(BuildContext context) async { - final storedPassword = Preferences.instance.getString(_passwordKey); + final storedPassword = Preferences.instance.getString(Preferences.password); if (storedPassword == null || storedPassword.isEmpty) return true; final controller = TextEditingController(); bool? result; @@ -58,9 +57,9 @@ class PasswordService { static Future setPassword(String password) async { if (password.isNotEmpty) { - await Preferences.instance.setString(_passwordKey, password); + await Preferences.instance.setString(Preferences.password, password); } else { - await Preferences.instance.remove(_passwordKey); + await Preferences.instance.remove(Preferences.password); } } } diff --git a/lib/preferences.dart b/lib/preferences.dart index 105b355..64eb29d 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -1,4 +1,3 @@ - import 'dart:io'; import 'dart:math'; @@ -21,6 +20,7 @@ class Preferences { static const String buffer = 'buffer'; static const String wakelock = 'wakelock'; static const String stopDetection = 'stop_detection'; + static const String password = 'password'; static const String lastTimestamp = 'lastTimestamp'; static const String lastLatitude = 'lastLatitude'; @@ -40,42 +40,21 @@ class Preferences { cacheOptions: SharedPreferencesWithCacheOptions( allowList: { id, url, accuracy, distance, interval, angle, heartbeat, - fastestInterval, buffer, wakelock, stopDetection, + fastestInterval, buffer, wakelock, stopDetection, password, lastTimestamp, lastLatitude, lastLongitude, lastHeading, - 'device_id_preference', 'server_url_preference', 'accuracy_preference', - 'frequency_preference', 'distance_preference', 'buffer_preference', 'password', }, ), ); - } - - static Future migrate() async { - if (Platform.isAndroid) { - if (instance.get(interval) is String) { - final stringValue = instance.getString(interval); - await instance.setInt(interval, int.tryParse(stringValue ?? '') ?? 300); - } - if (instance.get(distance) is String) { - final stringValue = instance.getString(distance); - final intValue = int.tryParse(stringValue ?? '') ?? 75; - await instance.setInt(distance, intValue > 0 ? intValue : 75); - } - if (instance.get(angle) is String) { - final stringValue = instance.getString(angle); - final intValue = int.tryParse(stringValue ?? '') ?? 0; - await instance.setInt(angle, intValue); - } - } else { - await _migrate(); + if (instance.getString(id) == null) { + await instance.setString(id, (Random().nextInt(90000000) + 10000000).toString()); + await instance.setString(url, 'http://demo.traccar.org:5055'); + await instance.setString(accuracy, 'medium'); + await instance.setInt(interval, 300); + await instance.setInt(distance, 75); + await instance.setBool(buffer, true); + await instance.setBool(stopDetection, true); + await instance.setInt(fastestInterval, 30); } - await instance.setString(id, instance.getString(id) ?? (Random().nextInt(90000000) + 10000000).toString()); - await instance.setString(url, instance.getString(url) ?? 'http://demo.traccar.org:5055'); - await instance.setString(accuracy, instance.getString(accuracy) ?? 'medium'); - await instance.setInt(interval, instance.getInt(interval) ?? 300); - await instance.setInt(distance, instance.getInt(distance) ?? 75); - await instance.setBool(buffer, instance.getBool(buffer) ?? true); - await instance.setBool(stopDetection, instance.getBool(stopDetection) ?? true); - await instance.setInt(fastestInterval, instance.getInt(fastestInterval) ?? 30); } static bg.Config geolocationConfig() { @@ -169,39 +148,4 @@ class Preferences { "_": "&id=${instance.getString(id)}&lat=<%= latitude %>&lon=<%= longitude %>×tamp=<%= timestamp %>&" }'''.split('\n').map((line) => line.trimLeft()).join(); } - - static Future _migrate() async { - final oldId = instance.getString('device_id_preference'); - if (oldId != null) { - instance.setString(id, oldId); - instance.remove('device_id_preference'); - } - final oldUrl = instance.getString('server_url_preference'); - if (oldUrl != null) { - instance.setString(url, oldUrl); - instance.remove('server_url_preference'); - } - final oldAccuracy = instance.getString('accuracy_preference'); - if (oldAccuracy != null) { - instance.setString(accuracy, oldAccuracy); - instance.remove('accuracy_preference'); - } - final oldIntervalString = instance.getString('frequency_preference'); - final oldInterval = oldIntervalString != null ? int.tryParse(oldIntervalString) : null; - if (oldInterval != null) { - instance.setInt(interval, oldInterval); - instance.remove('frequency_preference'); - } - final oldDistanceString = instance.getString('distance_preference'); - final oldDistance = oldDistanceString != null ? int.tryParse(oldDistanceString) : null; - if (oldDistance != null) { - instance.setInt(distance, oldDistance > 0 ? oldDistance : 75); - instance.remove('distance_preference'); - } - final oldBuffer = instance.getBool('buffer_preference'); - if (oldBuffer != null) { - instance.setBool(buffer, oldBuffer); - instance.remove('buffer_preference'); - } - } }