opt.: split webdav & other settings (#569)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-31 21:45:09 +08:00
committed by GitHub
parent 7f0dc656b8
commit edb49ead67
10 changed files with 122 additions and 405 deletions

View File

@@ -18,7 +18,7 @@ const backupFormatVersion = 1;
final _logger = Logger('Backup');
@JsonSerializable()
class Backup {
class Backup extends Mergeable {
// backup format version
final int version;
final String date;
@@ -28,8 +28,9 @@ class Backup {
final Map<String, dynamic> container;
final Map<String, dynamic> history;
final int? lastModTime;
final Map<String, dynamic> settings;
const Backup({
Backup({
required this.version,
required this.date,
required this.spis,
@@ -37,6 +38,7 @@ class Backup {
required this.keys,
required this.container,
required this.history,
required this.settings,
this.lastModTime,
});
@@ -52,7 +54,8 @@ class Backup {
keys = Stores.key.fetch(),
container = Stores.container.box.toJson(),
lastModTime = Stores.lastModTime,
history = Stores.history.box.toJson();
history = Stores.history.box.toJson(),
settings = Stores.setting.box.toJson();
static Future<String> backup([String? name]) async {
final result = _diyEncrypt(json.encode(Backup.loadFromStore().toJson()));
@@ -61,7 +64,8 @@ class Backup {
return path;
}
Future<void> restore({bool force = false}) async {
@override
Future<void> merge({bool force = false}) async {
final curTime = Stores.lastModTime ?? 0;
final bakTime = lastModTime ?? 0;
final shouldRestore = force || curTime < bakTime;
@@ -176,6 +180,26 @@ class Backup {
}
}
// Settings
if (force) {
Stores.setting.box.putAll(settings);
} else {
final nowSettings = Stores.setting.box.keys.toSet();
final bakSettings = settings.keys.toSet();
final newSettings = bakSettings.difference(nowSettings);
final delSettings = nowSettings.difference(bakSettings);
final updateSettings = nowSettings.intersection(bakSettings);
for (final s in newSettings) {
Stores.setting.box.put(s, settings[s]);
}
for (final s in delSettings) {
Stores.setting.box.delete(s);
}
for (final s in updateSettings) {
Stores.setting.box.put(s, settings[s]);
}
}
Provider.reload();
RNodes.app.notify();

View File

@@ -0,0 +1,16 @@
import 'package:fl_lib/fl_lib.dart';
final class NoBackupStore extends PersistentStore {
NoBackupStore._() : super('no_backup');
static final instance = NoBackupStore._();
/// Only valid on iOS and macOS
late final icloudSync = property('icloudSync', false);
/// Webdav sync
late final webdavSync = property('webdavSync', false);
late final webdavUrl = property('webdavUrl', '');
late final webdavUser = property('webdavUser', '');
late final webdavPwd = property('webdavPwd', '');
}

View File

@@ -125,8 +125,6 @@ class SettingStore extends PersistentStore {
/// Whether use system's primary color as the app's primary color
late final useSystemPrimaryColor = property('useSystemPrimaryColor', false);
/// Only valid on iOS and macOS
late final icloudSync = property('icloudSync', false);
/// Only valid on iOS / Android / Windows
late final useBioAuth = property('useBioAuth', false);
@@ -143,12 +141,6 @@ class SettingStore extends PersistentStore {
/// Show tip of suspend
late final showSuspendTip = property('showSuspendTip', true);
/// Webdav sync
late final webdavSync = property('webdavSync', false);
late final webdavUrl = property('webdavUrl', '', updateLastModified: false);
late final webdavUser = property('webdavUser', '', updateLastModified: false);
late final webdavPwd = property('webdavPwd', '', updateLastModified: false);
/// Whether collapse UI items by default
late final collapseUIDefault = property('collapseUIDefault', true);