mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
fix: init icloud sync (#239)
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user