From 41ec46f1d31561e5646cf1dc603224a104094b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:33:21 +0800 Subject: [PATCH] opt.: show loading dialog --- lib/view/page/backup.dart | 7 +- lib/view/page/editor.dart | 4 +- lib/view/page/pve.dart | 7 +- lib/view/page/setting/platform/ios.dart | 11 +-- lib/view/page/storage/sftp.dart | 117 ++++++++++++------------ lib/view/widget/server_func_btns.dart | 14 ++- pubspec.lock | 4 +- pubspec.yaml | 2 +- 8 files changed, 86 insertions(+), 80 deletions(-) diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index 46daa910..6c656c39 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -225,6 +225,7 @@ class BackupPage extends StatelessWidget { final backup = await context.showLoadingDialog( fn: () => Computer.shared.start(Backup.fromJsonString, text.trim()), ); + if (backup == null) return; if (backupFormatVersion != backup.version) { context.showSnackBar(l10n.backupVersionNotMatch); return; @@ -367,6 +368,7 @@ class BackupPage extends StatelessWidget { fn: () => Computer.shared.start(Backup.fromJsonString, text.trim()), ); + if (backup == null) return; if (backupFormatVersion != backup.version) { context.showSnackBar(l10n.backupVersionNotMatch); return; @@ -408,6 +410,7 @@ class BackupPage extends StatelessWidget { return list.map((e) => ServerPrivateInfo.fromJson(e)).toList(); }, text.trim()), ); + if (spis == null) return; final sure = await context.showRoundDialog( title: l10n.import, child: Text(l10n.askContinue('${spis.length} ${l10n.server}')), @@ -419,13 +422,15 @@ class BackupPage extends StatelessWidget { ], ); if (sure == true) { - await context.showLoadingDialog( + final suc = await context.showLoadingDialog( fn: () async { for (var spi in spis) { Stores.server.put(spi); } + return true; }, ); + if (suc != true) return; context.showSnackBar(l10n.success); } } catch (e, s) { diff --git a/lib/view/page/editor.dart b/lib/view/page/editor.dart index 0bdd441e..2f5f51e5 100644 --- a/lib/view/page/editor.dart +++ b/lib/view/page/editor.dart @@ -145,10 +145,10 @@ class _EditorPageState extends State { // If path is not null, then it's a file editor // save the text and return true to pop the page if (widget.path != null) { - await context.showLoadingDialog( + final res = await context.showLoadingDialog( fn: () => File(widget.path!).writeAsString(_controller.text), ); - + if (res == null) return; context.pop(true); return; } diff --git a/lib/view/page/pve.dart b/lib/view/page/pve.dart index a02791df..7ab625a4 100644 --- a/lib/view/page/pve.dart +++ b/lib/view/page/pve.dart @@ -430,10 +430,9 @@ final class _PvePageState extends State { ], ); if (sure != true) return; - bool? suc; - await context.showLoadingDialog(fn: () async { - suc = await func(item.node, item.id); - }); + + final suc = + await context.showLoadingDialog(fn: () => func(item.node, item.id)); if (suc == true) { context.showSnackBar(l10n.success); } else { diff --git a/lib/view/page/setting/platform/ios.dart b/lib/view/page/setting/platform/ios.dart index ea581fe5..f1c51e24 100644 --- a/lib/view/page/setting/platform/ios.dart +++ b/lib/view/page/setting/platform/ios.dart @@ -114,13 +114,8 @@ class _IOSSettingsPageState extends State { final result = await AppRoutes.kvEditor(data: urls).go(context); if (result == null || result is! Map) return; - try { - await context.showLoadingDialog(fn: () async { - await wc.updateApplicationContext({'urls': result}); - }); - } catch (e, s) { - context.showErrDialog(e: e, s: s, operation: 'Watch Context'); - Loggers.app.warning('Update watch config failed', e, s); - } + await context.showLoadingDialog(fn: () async { + await wc.updateApplicationContext({'urls': result}); + }); } } diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index f5aa9355..f7215ceb 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -279,7 +279,7 @@ class _SftpPageState extends State with AfterLayoutMixin { } _status.path?.update(p); - final suc = await _listDir(); + final suc = await _listDir() ?? false; if (suc && Stores.setting.recordHistory.fetch()) { Stores.history.sftpGoPath.add(p); } @@ -406,6 +406,7 @@ class _SftpPageState extends State with AfterLayoutMixin { }, onErr: (e, s) { context.showErrDialog(e: e, s: s, operation: l10n.permission); + return false; }, ); } @@ -463,7 +464,8 @@ class _SftpPageState extends State with AfterLayoutMixin { SftpReqType.download, ); Pros.sftp.add(req, completer: completer); - await context.showLoadingDialog(fn: () => completer.future); + final suc = await context.showLoadingDialog(fn: () => completer.future); + if (suc == null) return; final result = await AppRoutes.editor(path: localPath).go(context); if (result != null && result) { @@ -554,24 +556,23 @@ class _SftpPageState extends State with AfterLayoutMixin { TextButton( onPressed: () async { context.pop(); - try { - await context.showLoadingDialog( - fn: () async { - final remotePath = _getRemotePath(file); - if (useRmr) { - await _client!.run('rm -r "$remotePath"'); - } else if (file.attr.isDirectory) { - await _status.client!.rmdir(remotePath); - } else { - await _status.client!.remove(remotePath); - } - }, - onErr: (e, s) {}, - ); - _listDir(); - } catch (e, s) { - context.showErrDialog(e: e, s: s, operation: l10n.delete); - } + + final suc = await context.showLoadingDialog( + fn: () async { + final remotePath = _getRemotePath(file); + if (useRmr) { + await _client!.run('rm -r "$remotePath"'); + } else if (file.attr.isDirectory) { + await _status.client!.rmdir(remotePath); + } else { + await _status.client!.remove(remotePath); + } + return true; + }, + ); + if (suc == null) return; + + _listDir(); }, child: Text(l10n.delete, style: UIs.textRed), ), @@ -597,18 +598,17 @@ class _SftpPageState extends State with AfterLayoutMixin { return; } context.pop(); - try { - await context.showLoadingDialog( - fn: () async { - final dir = '${_status.path!.path}/${textController.text}'; - await _status.client!.mkdir(dir); - }, - onErr: (e, s) {}, - ); - _listDir(); - } catch (e, s) { - context.showErrDialog(e: e, s: s, operation: l10n.createFolder); - } + + final suc = await context.showLoadingDialog( + fn: () async { + final dir = '${_status.path!.path}/${textController.text}'; + await _status.client!.mkdir(dir); + return true; + }, + ); + if (suc == null) return; + + _listDir(); } context.showRoundDialog( @@ -653,18 +653,17 @@ class _SftpPageState extends State with AfterLayoutMixin { return; } context.pop(); - try { - await context.showLoadingDialog( - fn: () async { - final path = '${_status.path!.path}/${textController.text}'; - await _client!.run('touch "$path"'); - }, - onErr: (e, s) {}, - ); - _listDir(); - } catch (e, s) { - context.showErrDialog(e: e, s: s, operation: l10n.createFile); - } + + final suc = await context.showLoadingDialog( + fn: () async { + final path = '${_status.path!.path}/${textController.text}'; + await _client!.run('touch "$path"'); + return true; + }, + ); + if (suc == null) return; + + _listDir(); } context.showRoundDialog( @@ -705,18 +704,17 @@ class _SftpPageState extends State with AfterLayoutMixin { return; } context.pop(); - try { - await context.showLoadingDialog( - fn: () async { - final newName = textController.text; - await _status.client?.rename(file.filename, newName); - }, - onErr: (e, s) {}, - ); - _listDir(); - } catch (e, s) { - context.showErrDialog(e: e, s: s, operation: l10n.rename); - } + + final suc = await context.showLoadingDialog( + fn: () async { + final newName = textController.text; + await _status.client?.rename(file.filename, newName); + return true; + }, + ); + if (suc == null) return; + + _listDir(); } context.showRoundDialog( @@ -756,7 +754,10 @@ class _SftpPageState extends State with AfterLayoutMixin { ); return; } - await context.showLoadingDialog(fn: () async => _client?.run(cmd)); + final suc = await context.showLoadingDialog( + fn: () => _client?.run(cmd) ?? Future.value(false), + ); + if (suc == null) return; _listDir(); } @@ -771,7 +772,7 @@ class _SftpPageState extends State with AfterLayoutMixin { } /// Only return true if the path is changed - Future _listDir() async { + Future _listDir() async { return context.showLoadingDialog( fn: () async { _status.client ??= await _client?.sftp(); diff --git a/lib/view/widget/server_func_btns.dart b/lib/view/widget/server_func_btns.dart index 584e7331..ea01bab9 100644 --- a/lib/view/widget/server_func_btns.dart +++ b/lib/view/widget/server_func_btns.dart @@ -245,7 +245,7 @@ Future _onPkg(BuildContext context, ServerPrivateInfo spi) async { } // Update pkg list - await context.showLoadingDialog( + final suc = await context.showLoadingDialog( fn: () async { final updateCmd = pkg.update; if (updateCmd != null) { @@ -258,6 +258,7 @@ Future _onPkg(BuildContext context, ServerPrivateInfo spi) async { }, barrierDismiss: true, ); + if (suc != true) return; final listCmd = pkg.listUpdate; if (listCmd == null) { @@ -266,9 +267,14 @@ Future _onPkg(BuildContext context, ServerPrivateInfo spi) async { } // Get upgrade list - final result = await context.showLoadingDialog(fn: () async { - return await client.run(listCmd).string; - }); + final result = await context.showLoadingDialog( + fn: () => client.run(listCmd).string, + ); + if (result == null || result.isEmpty) { + context.showSnackBar(l10n.noResult); + return; + } + final list = pkg.updateListRemoveUnused(result.split('\n')); final upgradeable = list.map((e) => UpgradePkgInfo(e, pkg)).toList(); if (upgradeable.isEmpty) { diff --git a/pubspec.lock b/pubspec.lock index 1c132f13..0f4ada5c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -385,8 +385,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.0.79" - resolved-ref: f1bc7dd5ec2af84813b33a9e2149e117dfea3cd0 + ref: "v1.0.80" + resolved-ref: a31e278de69ef964e489687f4e289f18c568c91a url: "https://github.com/lppcg/fl_lib" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 3f3571f0..6b648450 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -61,7 +61,7 @@ dependencies: fl_lib: git: url: https://github.com/lppcg/fl_lib - ref: v1.0.79 + ref: v1.0.80 dependency_overrides: # dartssh2: