mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Improve backup functionality and error handling
- (Windows) Fix not selecting the right backup file in explorer - Fix progress indicator not stopping on WebDAV failure #188 #364
This commit is contained in:
@@ -65,14 +65,18 @@ class BackupPage extends StatelessWidget {
|
|||||||
trailing: const Icon(Icons.save),
|
trailing: const Icon(Icons.save),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final path = await Backup.backup();
|
final path = await Backup.backup();
|
||||||
|
debugPrint("Backup path: $path");
|
||||||
|
|
||||||
/// Issue #188
|
/// Issue #188
|
||||||
final _ = switch (Pfs.type) {
|
switch (Pfs.type) {
|
||||||
Pfs.windows =>
|
case Pfs.windows:
|
||||||
await Process.run('explorer', ['/select,', path]),
|
final backslashPath = path.replaceAll('/', '\\');
|
||||||
Pfs.linux => await Process.run('xdg-open', [path]),
|
await Process.run('explorer', ['/select,$backslashPath']);
|
||||||
_ => await Pfs.sharePath(path),
|
case Pfs.linux:
|
||||||
};
|
await Process.run('xdg-open', [path]);
|
||||||
|
default:
|
||||||
|
await Pfs.sharePath(path);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@@ -263,64 +267,79 @@ class BackupPage extends StatelessWidget {
|
|||||||
|
|
||||||
Future<void> _onTapWebdavDl(BuildContext context) async {
|
Future<void> _onTapWebdavDl(BuildContext context) async {
|
||||||
webdavLoading.value = true;
|
webdavLoading.value = true;
|
||||||
final files = await Webdav.list();
|
try {
|
||||||
if (files.isEmpty) {
|
final files = await Webdav.list();
|
||||||
context.showSnackBar(l10n.dirEmpty);
|
if (files.isEmpty) {
|
||||||
webdavLoading.value = false;
|
context.showSnackBar(l10n.dirEmpty);
|
||||||
return;
|
webdavLoading.value = false;
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final fileName = await context.showRoundDialog<String>(
|
final fileName = await context.showRoundDialog<String>(
|
||||||
title: l10n.restore,
|
title: l10n.restore,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 300,
|
height: 300,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: files.length,
|
itemCount: files.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final file = files[index];
|
final file = files[index];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(file),
|
title: Text(file),
|
||||||
onTap: () => context.pop(file),
|
onTap: () => context.pop(file),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
actions: [
|
||||||
actions: [
|
TextButton(
|
||||||
TextButton(
|
onPressed: () => context.pop(),
|
||||||
onPressed: () => context.pop(),
|
child: Text(l10n.cancel),
|
||||||
child: Text(l10n.cancel),
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
);
|
if (fileName == null) {
|
||||||
if (fileName == null) {
|
webdavLoading.value = false;
|
||||||
webdavLoading.value = false;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final result = await Webdav.download(relativePath: fileName);
|
final result = await Webdav.download(relativePath: fileName);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
Loggers.app.warning('Download webdav backup failed: $result');
|
Loggers.app.warning('Download webdav backup failed: $result');
|
||||||
|
webdavLoading.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final dlFile = await File('${Paths.doc}/$fileName').readAsString();
|
||||||
|
final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile);
|
||||||
|
await dlBak.restore(force: true);
|
||||||
|
webdavLoading.value = false;
|
||||||
|
} catch (e) {
|
||||||
|
context.showSnackBar(e.toString());
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
webdavLoading.value = false;
|
webdavLoading.value = false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
final dlFile = await File('${Paths.doc}/$fileName').readAsString();
|
|
||||||
final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile);
|
|
||||||
await dlBak.restore(force: true);
|
|
||||||
webdavLoading.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onTapWebdavUp(BuildContext context) async {
|
Future<void> _onTapWebdavUp(BuildContext context) async {
|
||||||
webdavLoading.value = true;
|
try {
|
||||||
final bakName = '${DateTime.now().ymdhms()}-${Paths.bakName}';
|
webdavLoading.value = true;
|
||||||
await Backup.backup(bakName);
|
final bakName =
|
||||||
final uploadResult = await Webdav.upload(relativePath: bakName);
|
'${DateTime.now().ymdhms(ymdSep: "-", hmsSep: "-", sep: "-")}-${Paths.bakName}';
|
||||||
if (uploadResult != null) {
|
await Backup.backup(bakName);
|
||||||
Loggers.app.warning('Upload webdav backup failed: $uploadResult');
|
final uploadResult = await Webdav.upload(relativePath: bakName);
|
||||||
} else {
|
if (uploadResult != null) {
|
||||||
Loggers.app.info('Upload webdav backup success');
|
Loggers.app.warning('Upload webdav backup failed: $uploadResult');
|
||||||
|
context.showSnackBar(uploadResult.toString());
|
||||||
|
} else {
|
||||||
|
Loggers.app.info('Upload webdav backup success');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
context.showSnackBar(e.toString());
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
webdavLoading.value = false;
|
||||||
}
|
}
|
||||||
webdavLoading.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onTapWebdavSetting(BuildContext context) async {
|
Future<void> _onTapWebdavSetting(BuildContext context) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user