fix: init icloud sync (#239)

This commit is contained in:
lollipopkit
2023-12-21 14:14:29 +08:00
parent e686387d88
commit 14260fa180

View File

@@ -183,15 +183,26 @@ abstract final class ICloud {
} }
static Future<void> sync() async { static Future<void> sync() async {
var dlSuccess = false;
try { try {
final result = await download(relativePath: Paths.bakName); final result = await download(relativePath: Paths.bakName);
if (result != null) { if (result != null) {
_logger.warning('Download backup failed: $result'); throw result;
return;
} }
dlSuccess = true;
} catch (e, s) { } catch (e, s) {
_logger.warning('Download backup failed', e, s); _logger.warning('Download backup failed', e, s);
} }
if (!dlSuccess) {
await Backup.backup();
final uploadResult = await upload(relativePath: Paths.bakName);
if (uploadResult != null) {
_logger.warning('Upload backup failed: $uploadResult');
} else {
_logger.info('Upload backup success');
}
return;
}
final dlFile = await File(await Paths.bak).readAsString(); final dlFile = await File(await Paths.bak).readAsString();
final dlBak = await compute(Backup.fromJsonString, dlFile); final dlBak = await compute(Backup.fromJsonString, dlFile);
final restore = await dlBak.restore(); final restore = await dlBak.restore();