Remove migration code
This commit is contained in:
parent
4819578816
commit
cf385dec8a
3 changed files with 17 additions and 75 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<void> 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<bool> 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<void> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<void> 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<void> _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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue