opt.: show loading dialog

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-07-22 23:33:21 +08:00
parent 7a359588db
commit 41ec46f1d3
8 changed files with 86 additions and 80 deletions

View File

@@ -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<bool>(
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) {

View File

@@ -145,10 +145,10 @@ class _EditorPageState extends State<EditorPage> {
// 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;
}

View File

@@ -430,10 +430,9 @@ final class _PvePageState extends State<PvePage> {
],
);
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 {

View File

@@ -114,13 +114,8 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
final result = await AppRoutes.kvEditor(data: urls).go(context);
if (result == null || result is! Map<String, String>) 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});
});
}
}

View File

@@ -279,7 +279,7 @@ class _SftpPageState extends State<SftpPage> 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<SftpPage> with AfterLayoutMixin {
},
onErr: (e, s) {
context.showErrDialog(e: e, s: s, operation: l10n.permission);
return false;
},
);
}
@@ -463,7 +464,8 @@ class _SftpPageState extends State<SftpPage> 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<bool>(context);
if (result != null && result) {
@@ -554,24 +556,23 @@ class _SftpPageState extends State<SftpPage> 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<SftpPage> 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<SftpPage> 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<SftpPage> 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<SftpPage> 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<SftpPage> with AfterLayoutMixin {
}
/// Only return true if the path is changed
Future<bool> _listDir() async {
Future<bool?> _listDir() async {
return context.showLoadingDialog(
fn: () async {
_status.client ??= await _client?.sftp();

View File

@@ -245,7 +245,7 @@ Future<void> _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<void> _onPkg(BuildContext context, ServerPrivateInfo spi) async {
},
barrierDismiss: true,
);
if (suc != true) return;
final listCmd = pkg.listUpdate;
if (listCmd == null) {
@@ -266,9 +267,14 @@ Future<void> _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) {

View File

@@ -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"

View File

@@ -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: