mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
new: manual icloud sync
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:logging/logging.dart';
|
||||
import '../../data/model/app/error.dart';
|
||||
import '../../data/model/app/json.dart';
|
||||
import '../../data/res/path.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
final _logger = Logger('iCloud');
|
||||
|
||||
@@ -173,3 +174,14 @@ class ICloud {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> syncApple() async {
|
||||
if (!isIOS && !isMacOS) return;
|
||||
final docPath = await docDir;
|
||||
final dir = Directory(docPath);
|
||||
final files = await dir.list().toList();
|
||||
// filter out non-hive(db) files
|
||||
files.removeWhere((e) => !e.path.endsWith('.hive'));
|
||||
final paths = files.map((e) => e.path.replaceFirst('$docPath/', ''));
|
||||
await ICloud.sync(relativePaths: paths);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ const participants = <GhId>{
|
||||
'yuchen1204',
|
||||
'xgzxmytx',
|
||||
'wind057',
|
||||
'a1564471347',
|
||||
};
|
||||
|
||||
const jsonEncoder = JsonEncoder.withIndent(' ');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const backendUrl = 'https://res.lolli.tech';
|
||||
const baseResUrl = '$backendUrl/serverbox';
|
||||
const baseResUrl = 'https://res.lolli.tech/serverbox';
|
||||
const myGithub = 'https://github.com/lollipopkit';
|
||||
const appHelpUrl = '$myGithub/flutter_server_box#-help';
|
||||
const appWikiUrl = '$myGithub/flutter_server_box/wiki';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
@@ -28,7 +27,6 @@ import 'data/provider/snippet.dart';
|
||||
import 'data/provider/virtual_keyboard.dart';
|
||||
import 'data/res/color.dart';
|
||||
import 'data/res/misc.dart';
|
||||
import 'data/res/path.dart';
|
||||
import 'data/store/setting.dart';
|
||||
import 'locator.dart';
|
||||
import 'view/widget/custom_appbar.dart';
|
||||
@@ -96,7 +94,8 @@ Future<void> initApp() async {
|
||||
loadFontFile(settings.fontPath.fetch());
|
||||
primaryColor = Color(settings.primaryColor.fetch());
|
||||
|
||||
if (settings.icloudSync.fetch()) _syncApple();
|
||||
// Don't call it via `await`, it will block the main thread.
|
||||
if (settings.icloudSync.fetch()) syncApple();
|
||||
|
||||
if (isAndroid) {
|
||||
// Only start service when [bgRun] is true.
|
||||
@@ -149,15 +148,3 @@ Future<void> _initMacOSWindow() async {
|
||||
WindowManipulator.hideTitle();
|
||||
await CustomAppBar.updateTitlebarHeight();
|
||||
}
|
||||
|
||||
// Don't call it via `await`, it will block the main thread.
|
||||
void _syncApple() async {
|
||||
if (!isIOS && !isMacOS) return;
|
||||
final docPath = await docDir;
|
||||
final dir = Directory(docPath);
|
||||
final files = await dir.list().toList();
|
||||
// filter out non-hive(db) files
|
||||
files.removeWhere((e) => !e.path.endsWith('.hive'));
|
||||
final paths = files.map((e) => e.path.replaceFirst('$docPath/', ''));
|
||||
await ICloud.sync(relativePaths: paths);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/context.dart';
|
||||
import 'package:toolbox/core/utils/backup.dart';
|
||||
import 'package:toolbox/core/utils/icloud.dart';
|
||||
import 'package:toolbox/core/utils/platform.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
@@ -36,7 +37,7 @@ class BackupPage extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (isMacOS || isIOS) _buildIcloudSync(context),
|
||||
if (isMacOS || isIOS) _buildIcloudSync(context, s),
|
||||
height13,
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(37),
|
||||
@@ -93,7 +94,7 @@ class BackupPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIcloudSync(BuildContext context) {
|
||||
Widget _buildIcloudSync(BuildContext context, S s) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -102,6 +103,15 @@ class BackupPage extends StatelessWidget {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
width13,
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
showLoadingDialog(context);
|
||||
await syncApple();
|
||||
context.pop();
|
||||
showRestartSnackbar(context, btn: s.restart, msg: s.icloudSynced);
|
||||
},
|
||||
icon: const Icon(Icons.sync)),
|
||||
width13,
|
||||
buildSwitch(context, _setting.icloudSync)
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user