Skip to content

Commit

Permalink
opt.: detect sync conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Dec 4, 2023
1 parent 38cdef9 commit 22901bb
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 23 deletions.
12 changes: 12 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ abstract class S {
/// **'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.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -1574,6 +1580,12 @@ abstract class S {
/// **'No paired Apple Watch'**
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.
///
/// In en, this message translates to:
Expand Down
6 changes: 6 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SDe extends S {
@override
String get auto => 'System folgen';

@override
String get autoBackupConflict => 'Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.';

@override
String get autoCheckUpdate => 'Aktualisierung automatisch prüfen';

Expand Down Expand Up @@ -782,6 +785,9 @@ class SDe extends S {
@override
String get watchNotPaired => 'Keine gekoppelte Apple Watch';

@override
String get webdavSettingEmpty => 'Webdav-Einstellungen sind leer';

@override
String get whenOpenApp => 'Beim Öffnen der App';

Expand Down
6 changes: 6 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SEn extends S {
@override
String get auto => 'Auto';

@override
String get autoBackupConflict => 'Only one automatic backup can be turned on at the same time.';

@override
String get autoCheckUpdate => 'Auto check update';

Expand Down Expand Up @@ -782,6 +785,9 @@ class SEn extends S {
@override
String get watchNotPaired => 'No paired Apple Watch';

@override
String get webdavSettingEmpty => 'Webdav setting is empty';

@override
String get whenOpenApp => 'When opening the app';

Expand Down
6 changes: 6 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SId extends S {
@override
String get auto => 'Auto';

@override
String get autoBackupConflict => 'Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.';

@override
String get autoCheckUpdate => 'Periksa pembaruan otomatis';

Expand Down Expand Up @@ -782,6 +785,9 @@ class SId extends S {
@override
String get watchNotPaired => 'Tidak ada Apple Watch yang dipasangkan';

@override
String get webdavSettingEmpty => 'Pengaturan webdav kosong';

@override
String get whenOpenApp => 'Saat membuka aplikasi';

Expand Down
12 changes: 12 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SZh extends S {
@override
String get auto => '自动';

@override
String get autoBackupConflict => '只能同时开启一个自动备份';

@override
String get autoCheckUpdate => '自动检查更新';

Expand Down Expand Up @@ -782,6 +785,9 @@ class SZh extends S {
@override
String get watchNotPaired => '没有已配对的 Apple Watch';

@override
String get webdavSettingEmpty => 'Webdav 设置项为空';

@override
String get whenOpenApp => '当打开 App 时';

Expand Down Expand Up @@ -840,6 +846,9 @@ class SZhTw extends SZh {
@override
String get auto => '自動';

@override
String get autoBackupConflict => '只能同時開啓壹個自動備份';

@override
String get autoCheckUpdate => '自動檢查更新';

Expand Down Expand Up @@ -1574,6 +1583,9 @@ class SZhTw extends SZh {
@override
String get watchNotPaired => '沒有已配對的 Apple Watch';

@override
String get webdavSettingEmpty => 'Webdav 設置項爲空';

@override
String get whenOpenApp => '當打開 App 時';

Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"attention": "Achtung",
"authRequired": "Autorisierung erforderlich",
"auto": "System folgen",
"autoBackupConflict": "Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.",
"autoCheckUpdate": "Aktualisierung automatisch prüfen",
"autoConnect": "Automatisch verbinden",
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
Expand Down Expand Up @@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Aktuelles Verzeichnis in SFTP öffnen.",
"waitConnection": "Bitte warte, bis die Verbindung hergestellt wurde.",
"watchNotPaired": "Keine gekoppelte Apple Watch",
"webdavSettingEmpty": "Webdav-Einstellungen sind leer",
"whenOpenApp": "Beim Öffnen der App",
"willTakEeffectImmediately": "Wird sofort angewendet",
"write": "Schreiben"
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"attention": "Attention",
"authRequired": "Auth required",
"auto": "Auto",
"autoBackupConflict": "Only one automatic backup can be turned on at the same time.",
"autoCheckUpdate": "Auto check update",
"autoConnect": "Auto connect",
"autoUpdateHomeWidget": "Auto update home widget",
Expand Down Expand Up @@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Open current directory in SFTP.",
"waitConnection": "Please wait for the connection to be established.",
"watchNotPaired": "No paired Apple Watch",
"webdavSettingEmpty": "Webdav setting is empty",
"whenOpenApp": "When opening the app",
"willTakEeffectImmediately": "Will take effect immediately",
"write": "Write"
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"attention": "Perhatian",
"authRequired": "Auth diperlukan",
"auto": "Auto",
"autoBackupConflict": "Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.",
"autoCheckUpdate": "Periksa pembaruan otomatis",
"autoConnect": "Hubungkan otomatis",
"autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis",
Expand Down Expand Up @@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "Buka direktori saat ini di SFTP.",
"waitConnection": "Harap tunggu koneksi akan dibuat.",
"watchNotPaired": "Tidak ada Apple Watch yang dipasangkan",
"webdavSettingEmpty": "Pengaturan webdav kosong",
"whenOpenApp": "Saat membuka aplikasi",
"willTakEeffectImmediately": "Akan segera berlaku",
"write": "Tulis"
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"attention": "注意",
"authRequired": "需要认证",
"auto": "自动",
"autoBackupConflict": "只能同时开启一个自动备份",
"autoCheckUpdate": "自动检查更新",
"autoConnect": "自动连接",
"autoUpdateHomeWidget": "自动更新桌面小部件",
Expand Down Expand Up @@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "在 SFTP 中打开当前路径。",
"waitConnection": "请等待连接建立",
"watchNotPaired": "没有已配对的 Apple Watch",
"webdavSettingEmpty": "Webdav 设置项为空",
"whenOpenApp": "当打开 App 时",
"willTakEeffectImmediately": "更改将会立即生效",
"write": "写"
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"attention": "注意",
"authRequired": "需要認證",
"auto": "自動",
"autoBackupConflict": "只能同時開啓壹個自動備份",
"autoCheckUpdate": "自動檢查更新",
"autoConnect": "自動連接",
"autoUpdateHomeWidget": "自動更新桌面小部件",
Expand Down Expand Up @@ -246,6 +247,7 @@
"virtKeyHelpSFTP": "在 SFTP 中打開當前路徑。",
"waitConnection": "請等待連接建立",
"watchNotPaired": "沒有已配對的 Apple Watch",
"webdavSettingEmpty": "Webdav 設置項爲空",
"whenOpenApp": "當打開 App 時",
"willTakEeffectImmediately": "更改將會立即生效",
"write": "写"
Expand Down
52 changes: 35 additions & 17 deletions lib/view/page/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ class BackupPage extends StatelessWidget {
title: Text(l10n.auto),
trailing: StoreSwitch(
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) {
icloudLoading.value = true;
await ICloud.sync();
Expand Down Expand Up @@ -273,24 +280,20 @@ class BackupPage extends StatelessWidget {
},
child: Text(l10n.ok),
),
TextButton(
onPressed: () async {
final result = await Webdav.test(
urlCtrl.text,
userCtrl.text,
pwdCtrl.text,
);
if (result == null) {
context.showSnackBar(l10n.success);
} else {
context.showSnackBar(result);
}
},
child: Text(l10n.test),
),
],
);
if (result == true) {
final result = await Webdav.test(
urlCtrl.text,
userCtrl.text,
pwdCtrl.text,
);
if (result == null) {
context.showSnackBar(l10n.success);
} else {
context.showSnackBar(result);
return;
}
Webdav.changeClient(
urlCtrl.text,
userCtrl.text,
Expand All @@ -306,7 +309,22 @@ class BackupPage extends StatelessWidget {
title: Text(l10n.auto),
trailing: StoreSwitch(
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) {
webdavLoading.value = true;
await Webdav.sync();
Expand Down
4 changes: 2 additions & 2 deletions lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class _SettingPageState extends State<SettingPage> {
title: Text(l10n.followSystem),
trailing: StoreSwitch(
prop: _setting.useSystemPrimaryColor,
func: (_) => setState(() {}),
callback: (_) => setState(() {}),
),
)
];
Expand Down Expand Up @@ -747,7 +747,7 @@ class _SettingPageState extends State<SettingPage> {
title: Text(l10n.fullScreen),
trailing: StoreSwitch(
prop: _setting.fullScreen,
func: (_) => RebuildNodes.app.rebuild(),
callback: (_) => RebuildNodes.app.rebuild(),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/view/page/setting/platform_pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PlatformPublicSettings {
trailing: can == true
? StoreSwitch(
prop: Stores.setting.useBioAuth,
func: (val) async {
callback: (val) async {
if (val) {
Stores.setting.useBioAuth.put(false);
return;
Expand Down
17 changes: 14 additions & 3 deletions lib/view/widget/store_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import '../../core/persistant_store.dart';

class StoreSwitch extends StatelessWidget {
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
Widget build(BuildContext context) {
Expand All @@ -16,7 +26,8 @@ class StoreSwitch extends StatelessWidget {
return Switch(
value: value,
onChanged: (value) {
func?.call(value);
if (validator != null && validator?.call(value) != true) return;
callback?.call(value);
prop.put(value);
},
);
Expand Down

0 comments on commit 22901bb

Please sign in to comment.