opt.: detect sync conflict

This commit is contained in:
lollipopkit
2023-12-04 14:36:32 +08:00
parent 38cdef9458
commit 22901bb856
14 changed files with 104 additions and 23 deletions

View File

@@ -182,6 +182,12 @@ abstract class S {
/// **'Auto'** /// **'Auto'**
String get auto; String get auto;
/// No description provided for @autoBackupConflict.
///
/// In en, this message translates to:
/// **'Only one automatic backup can be turned on at the same time.'**
String get autoBackupConflict;
/// No description provided for @autoCheckUpdate. /// No description provided for @autoCheckUpdate.
/// ///
/// In en, this message translates to: /// In en, this message translates to:
@@ -1574,6 +1580,12 @@ abstract class S {
/// **'No paired Apple Watch'** /// **'No paired Apple Watch'**
String get watchNotPaired; String get watchNotPaired;
/// No description provided for @webdavSettingEmpty.
///
/// In en, this message translates to:
/// **'Webdav setting is empty'**
String get webdavSettingEmpty;
/// No description provided for @whenOpenApp. /// No description provided for @whenOpenApp.
/// ///
/// In en, this message translates to: /// In en, this message translates to:

View File

@@ -48,6 +48,9 @@ class SDe extends S {
@override @override
String get auto => 'System folgen'; String get auto => 'System folgen';
@override
String get autoBackupConflict => 'Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.';
@override @override
String get autoCheckUpdate => 'Aktualisierung automatisch prüfen'; String get autoCheckUpdate => 'Aktualisierung automatisch prüfen';
@@ -782,6 +785,9 @@ class SDe extends S {
@override @override
String get watchNotPaired => 'Keine gekoppelte Apple Watch'; String get watchNotPaired => 'Keine gekoppelte Apple Watch';
@override
String get webdavSettingEmpty => 'Webdav-Einstellungen sind leer';
@override @override
String get whenOpenApp => 'Beim Öffnen der App'; String get whenOpenApp => 'Beim Öffnen der App';

View File

@@ -48,6 +48,9 @@ class SEn extends S {
@override @override
String get auto => 'Auto'; String get auto => 'Auto';
@override
String get autoBackupConflict => 'Only one automatic backup can be turned on at the same time.';
@override @override
String get autoCheckUpdate => 'Auto check update'; String get autoCheckUpdate => 'Auto check update';
@@ -782,6 +785,9 @@ class SEn extends S {
@override @override
String get watchNotPaired => 'No paired Apple Watch'; String get watchNotPaired => 'No paired Apple Watch';
@override
String get webdavSettingEmpty => 'Webdav setting is empty';
@override @override
String get whenOpenApp => 'When opening the app'; String get whenOpenApp => 'When opening the app';

View File

@@ -48,6 +48,9 @@ class SId extends S {
@override @override
String get auto => 'Auto'; String get auto => 'Auto';
@override
String get autoBackupConflict => 'Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.';
@override @override
String get autoCheckUpdate => 'Periksa pembaruan otomatis'; String get autoCheckUpdate => 'Periksa pembaruan otomatis';
@@ -782,6 +785,9 @@ class SId extends S {
@override @override
String get watchNotPaired => 'Tidak ada Apple Watch yang dipasangkan'; String get watchNotPaired => 'Tidak ada Apple Watch yang dipasangkan';
@override
String get webdavSettingEmpty => 'Pengaturan webdav kosong';
@override @override
String get whenOpenApp => 'Saat membuka aplikasi'; String get whenOpenApp => 'Saat membuka aplikasi';

View File

@@ -48,6 +48,9 @@ class SZh extends S {
@override @override
String get auto => '自动'; String get auto => '自动';
@override
String get autoBackupConflict => '只能同时开启一个自动备份';
@override @override
String get autoCheckUpdate => '自动检查更新'; String get autoCheckUpdate => '自动检查更新';
@@ -782,6 +785,9 @@ class SZh extends S {
@override @override
String get watchNotPaired => '没有已配对的 Apple Watch'; String get watchNotPaired => '没有已配对的 Apple Watch';
@override
String get webdavSettingEmpty => 'Webdav 设置项为空';
@override @override
String get whenOpenApp => '当打开 App 时'; String get whenOpenApp => '当打开 App 时';
@@ -840,6 +846,9 @@ class SZhTw extends SZh {
@override @override
String get auto => '自動'; String get auto => '自動';
@override
String get autoBackupConflict => '只能同時開啓壹個自動備份';
@override @override
String get autoCheckUpdate => '自動檢查更新'; String get autoCheckUpdate => '自動檢查更新';
@@ -1574,6 +1583,9 @@ class SZhTw extends SZh {
@override @override
String get watchNotPaired => '沒有已配對的 Apple Watch'; String get watchNotPaired => '沒有已配對的 Apple Watch';
@override
String get webdavSettingEmpty => 'Webdav 設置項爲空';
@override @override
String get whenOpenApp => '當打開 App 時'; String get whenOpenApp => '當打開 App 時';

View File

@@ -14,6 +14,7 @@
"attention": "Achtung", "attention": "Achtung",
"authRequired": "Autorisierung erforderlich", "authRequired": "Autorisierung erforderlich",
"auto": "System folgen", "auto": "System folgen",
"autoBackupConflict": "Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.",
"autoCheckUpdate": "Aktualisierung automatisch prüfen", "autoCheckUpdate": "Aktualisierung automatisch prüfen",
"autoConnect": "Automatisch verbinden", "autoConnect": "Automatisch verbinden",
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren", "autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
@@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Aktuelles Verzeichnis in SFTP öffnen.", "virtKeyHelpSFTP": "Aktuelles Verzeichnis in SFTP öffnen.",
"waitConnection": "Bitte warte, bis die Verbindung hergestellt wurde.", "waitConnection": "Bitte warte, bis die Verbindung hergestellt wurde.",
"watchNotPaired": "Keine gekoppelte Apple Watch", "watchNotPaired": "Keine gekoppelte Apple Watch",
"webdavSettingEmpty": "Webdav-Einstellungen sind leer",
"whenOpenApp": "Beim Öffnen der App", "whenOpenApp": "Beim Öffnen der App",
"willTakEeffectImmediately": "Wird sofort angewendet", "willTakEeffectImmediately": "Wird sofort angewendet",
"write": "Schreiben" "write": "Schreiben"

View File

@@ -14,6 +14,7 @@
"attention": "Attention", "attention": "Attention",
"authRequired": "Auth required", "authRequired": "Auth required",
"auto": "Auto", "auto": "Auto",
"autoBackupConflict": "Only one automatic backup can be turned on at the same time.",
"autoCheckUpdate": "Auto check update", "autoCheckUpdate": "Auto check update",
"autoConnect": "Auto connect", "autoConnect": "Auto connect",
"autoUpdateHomeWidget": "Auto update home widget", "autoUpdateHomeWidget": "Auto update home widget",
@@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Open current directory in SFTP.", "virtKeyHelpSFTP": "Open current directory in SFTP.",
"waitConnection": "Please wait for the connection to be established.", "waitConnection": "Please wait for the connection to be established.",
"watchNotPaired": "No paired Apple Watch", "watchNotPaired": "No paired Apple Watch",
"webdavSettingEmpty": "Webdav setting is empty",
"whenOpenApp": "When opening the app", "whenOpenApp": "When opening the app",
"willTakEeffectImmediately": "Will take effect immediately", "willTakEeffectImmediately": "Will take effect immediately",
"write": "Write" "write": "Write"

View File

@@ -14,6 +14,7 @@
"attention": "Perhatian", "attention": "Perhatian",
"authRequired": "Auth diperlukan", "authRequired": "Auth diperlukan",
"auto": "Auto", "auto": "Auto",
"autoBackupConflict": "Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.",
"autoCheckUpdate": "Periksa pembaruan otomatis", "autoCheckUpdate": "Periksa pembaruan otomatis",
"autoConnect": "Hubungkan otomatis", "autoConnect": "Hubungkan otomatis",
"autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis", "autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis",
@@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Buka direktori saat ini di SFTP.", "virtKeyHelpSFTP": "Buka direktori saat ini di SFTP.",
"waitConnection": "Harap tunggu koneksi akan dibuat.", "waitConnection": "Harap tunggu koneksi akan dibuat.",
"watchNotPaired": "Tidak ada Apple Watch yang dipasangkan", "watchNotPaired": "Tidak ada Apple Watch yang dipasangkan",
"webdavSettingEmpty": "Pengaturan webdav kosong",
"whenOpenApp": "Saat membuka aplikasi", "whenOpenApp": "Saat membuka aplikasi",
"willTakEeffectImmediately": "Akan segera berlaku", "willTakEeffectImmediately": "Akan segera berlaku",
"write": "Tulis" "write": "Tulis"

View File

@@ -14,6 +14,7 @@
"attention": "注意", "attention": "注意",
"authRequired": "需要认证", "authRequired": "需要认证",
"auto": "自动", "auto": "自动",
"autoBackupConflict": "只能同时开启一个自动备份",
"autoCheckUpdate": "自动检查更新", "autoCheckUpdate": "自动检查更新",
"autoConnect": "自动连接", "autoConnect": "自动连接",
"autoUpdateHomeWidget": "自动更新桌面小部件", "autoUpdateHomeWidget": "自动更新桌面小部件",
@@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "在 SFTP 中打开当前路径。", "virtKeyHelpSFTP": "在 SFTP 中打开当前路径。",
"waitConnection": "请等待连接建立", "waitConnection": "请等待连接建立",
"watchNotPaired": "没有已配对的 Apple Watch", "watchNotPaired": "没有已配对的 Apple Watch",
"webdavSettingEmpty": "Webdav 设置项为空",
"whenOpenApp": "当打开 App 时", "whenOpenApp": "当打开 App 时",
"willTakEeffectImmediately": "更改将会立即生效", "willTakEeffectImmediately": "更改将会立即生效",
"write": "写" "write": "写"

View File

@@ -14,6 +14,7 @@
"attention": "注意", "attention": "注意",
"authRequired": "需要認證", "authRequired": "需要認證",
"auto": "自動", "auto": "自動",
"autoBackupConflict": "只能同時開啓壹個自動備份",
"autoCheckUpdate": "自動檢查更新", "autoCheckUpdate": "自動檢查更新",
"autoConnect": "自動連接", "autoConnect": "自動連接",
"autoUpdateHomeWidget": "自動更新桌面小部件", "autoUpdateHomeWidget": "自動更新桌面小部件",
@@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "在 SFTP 中打開當前路徑。", "virtKeyHelpSFTP": "在 SFTP 中打開當前路徑。",
"waitConnection": "請等待連接建立", "waitConnection": "請等待連接建立",
"watchNotPaired": "沒有已配對的 Apple Watch", "watchNotPaired": "沒有已配對的 Apple Watch",
"webdavSettingEmpty": "Webdav 設置項爲空",
"whenOpenApp": "當打開 App 時", "whenOpenApp": "當打開 App 時",
"willTakEeffectImmediately": "更改將會立即生效", "willTakEeffectImmediately": "更改將會立即生效",
"write": "写" "write": "写"

View File

@@ -150,7 +150,14 @@ class BackupPage extends StatelessWidget {
title: Text(l10n.auto), title: Text(l10n.auto),
trailing: StoreSwitch( trailing: StoreSwitch(
prop: Stores.setting.icloudSync, prop: Stores.setting.icloudSync,
func: (val) async { validator: (p0) {
if (p0 && Stores.setting.webdavSync.fetch()) {
context.showSnackBar(l10n.autoBackupConflict);
return false;
}
return true;
},
callback: (val) async {
if (val) { if (val) {
icloudLoading.value = true; icloudLoading.value = true;
await ICloud.sync(); await ICloud.sync();
@@ -273,8 +280,9 @@ class BackupPage extends StatelessWidget {
}, },
child: Text(l10n.ok), child: Text(l10n.ok),
), ),
TextButton( ],
onPressed: () async { );
if (result == true) {
final result = await Webdav.test( final result = await Webdav.test(
urlCtrl.text, urlCtrl.text,
userCtrl.text, userCtrl.text,
@@ -284,13 +292,8 @@ class BackupPage extends StatelessWidget {
context.showSnackBar(l10n.success); context.showSnackBar(l10n.success);
} else { } else {
context.showSnackBar(result); context.showSnackBar(result);
return;
} }
},
child: Text(l10n.test),
),
],
);
if (result == true) {
Webdav.changeClient( Webdav.changeClient(
urlCtrl.text, urlCtrl.text,
userCtrl.text, userCtrl.text,
@@ -306,7 +309,22 @@ class BackupPage extends StatelessWidget {
title: Text(l10n.auto), title: Text(l10n.auto),
trailing: StoreSwitch( trailing: StoreSwitch(
prop: Stores.setting.webdavSync, prop: Stores.setting.webdavSync,
func: (val) async { validator: (p0) {
if (p0) {
if (Stores.setting.webdavUrl.fetch().isEmpty ||
Stores.setting.webdavUser.fetch().isEmpty ||
Stores.setting.webdavPwd.fetch().isEmpty) {
context.showSnackBar(l10n.webdavSettingEmpty);
return false;
}
}
if (Stores.setting.icloudSync.fetch()) {
context.showSnackBar(l10n.autoBackupConflict);
return false;
}
return true;
},
callback: (val) async {
if (val) { if (val) {
webdavLoading.value = true; webdavLoading.value = true;
await Webdav.sync(); await Webdav.sync();

View File

@@ -339,7 +339,7 @@ class _SettingPageState extends State<SettingPage> {
title: Text(l10n.followSystem), title: Text(l10n.followSystem),
trailing: StoreSwitch( trailing: StoreSwitch(
prop: _setting.useSystemPrimaryColor, prop: _setting.useSystemPrimaryColor,
func: (_) => setState(() {}), callback: (_) => setState(() {}),
), ),
) )
]; ];
@@ -747,7 +747,7 @@ class _SettingPageState extends State<SettingPage> {
title: Text(l10n.fullScreen), title: Text(l10n.fullScreen),
trailing: StoreSwitch( trailing: StoreSwitch(
prop: _setting.fullScreen, prop: _setting.fullScreen,
func: (_) => RebuildNodes.app.rebuild(), callback: (_) => RebuildNodes.app.rebuild(),
), ),
); );
} }

View File

@@ -30,7 +30,7 @@ class PlatformPublicSettings {
trailing: can == true trailing: can == true
? StoreSwitch( ? StoreSwitch(
prop: Stores.setting.useBioAuth, prop: Stores.setting.useBioAuth,
func: (val) async { callback: (val) async {
if (val) { if (val) {
Stores.setting.useBioAuth.put(false); Stores.setting.useBioAuth.put(false);
return; return;

View File

@@ -4,9 +4,19 @@ import '../../core/persistant_store.dart';
class StoreSwitch extends StatelessWidget { class StoreSwitch extends StatelessWidget {
final StorePropertyBase<bool> prop; final StorePropertyBase<bool> prop;
final void Function(bool)? func;
const StoreSwitch({super.key, required this.prop, this.func}); /// Exec before make change, after validator.
final void Function(bool)? callback;
/// If return false, the switch will not change.
final bool Function(bool)? validator;
const StoreSwitch({
super.key,
required this.prop,
this.callback,
this.validator,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -16,7 +26,8 @@ class StoreSwitch extends StatelessWidget {
return Switch( return Switch(
value: value, value: value,
onChanged: (value) { onChanged: (value) {
func?.call(value); if (validator != null && validator?.call(value) != true) return;
callback?.call(value);
prop.put(value); prop.put(value);
}, },
); );