mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
#157 opt.: icloud sync
This commit is contained in:
@@ -13,7 +13,7 @@ final _logger = Logger('iCloud');
|
||||
class ICloud {
|
||||
static const _containerId = 'iCloud.tech.lolli.serverbox';
|
||||
|
||||
const ICloud();
|
||||
const ICloud._();
|
||||
|
||||
/// Upload file to iCloud
|
||||
///
|
||||
@@ -148,7 +148,6 @@ class ICloud {
|
||||
errs.add(err);
|
||||
}
|
||||
}
|
||||
_logger.info('Errs: $errs');
|
||||
|
||||
return errs.isEmpty ? null : errs;
|
||||
} catch (e, s) {
|
||||
|
||||
@@ -43,11 +43,11 @@ void showSnackBarWithAction(
|
||||
));
|
||||
}
|
||||
|
||||
void showRestartSnackbar(BuildContext context, S s) {
|
||||
void showRestartSnackbar(BuildContext context, {String? btn, String? msg}) {
|
||||
showSnackBarWithAction(
|
||||
context,
|
||||
'${s.success}\n${s.needRestart}',
|
||||
s.restart,
|
||||
msg ?? 'Need restart to take effect',
|
||||
btn ?? 'Restart',
|
||||
() => rebuildAll(context),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 539;
|
||||
static const int build = 542;
|
||||
static const String engine = "3.13.2";
|
||||
static const String buildAt = "2023-09-08 20:40:50.892853";
|
||||
static const int modifications = 6;
|
||||
static const String buildAt = "2023-09-11 22:08:36.399180";
|
||||
static const int modifications = 23;
|
||||
static const int script = 14;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"homeWidgetUrlConfig": "Home-Widget-Link konfigurieren",
|
||||
"host": "Host",
|
||||
"httpFailedWithCode": "Anfrage fehlgeschlagen, Statuscode: {code}",
|
||||
"icloudSynced": "iCloud wird synchronisiert und einige Einstellungen erfordern möglicherweise einen Neustart der App, um wirksam zu werden.",
|
||||
"image": "Image",
|
||||
"imagesList": "Images",
|
||||
"import": "Importieren",
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"homeWidgetUrlConfig": "Config home widget url",
|
||||
"host": "Host",
|
||||
"httpFailedWithCode": "request failed, status code: {code}",
|
||||
"icloudSynced": "iCloud wird synchronisiert und einige Einstellungen erfordern möglicherweise einen Neustart der App, um wirksam zu werden.",
|
||||
"image": "Image",
|
||||
"imagesList": "Images list",
|
||||
"import": "Import",
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"homeWidgetUrlConfig": "Konfigurasi URL Widget Rumah",
|
||||
"host": "Host",
|
||||
"httpFailedWithCode": "Permintaan gagal, kode status: {code}",
|
||||
"icloudSynced": "iCloud disinkronkan dan beberapa pengaturan mungkin memerlukan pengaktifan ulang aplikasi agar dapat diterapkan.",
|
||||
"image": "Gambar",
|
||||
"imagesList": "Daftar gambar",
|
||||
"import": "Impor",
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"homeWidgetUrlConfig": "桌面部件链接配置",
|
||||
"host": "主机",
|
||||
"httpFailedWithCode": "请求失败, 状态码: {code}",
|
||||
"icloudSynced": "iCloud已同步,某些设置可能需要重启才能生效。",
|
||||
"image": "镜像",
|
||||
"imagesList": "镜像列表",
|
||||
"import": "导入",
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"homeWidgetUrlConfig": "桌面部件鏈接配置",
|
||||
"host": "主機",
|
||||
"httpFailedWithCode": "請求失敗, 狀態碼: {code}",
|
||||
"icloudSynced": "iCloud已同步,某些設置可能需要重啟才能生效。",
|
||||
"image": "鏡像",
|
||||
"imagesList": "鏡像列表",
|
||||
"import": "導入",
|
||||
|
||||
@@ -7,11 +7,10 @@ import 'package:logging/logging.dart';
|
||||
import 'package:macos_window_utils/window_manipulator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:toolbox/core/utils/icloud.dart';
|
||||
import 'package:toolbox/data/res/path.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'core/analysis.dart';
|
||||
import 'core/utils/icloud.dart';
|
||||
import 'core/utils/platform.dart';
|
||||
import 'core/utils/ui.dart';
|
||||
import 'data/model/app/net_view.dart';
|
||||
@@ -29,6 +28,7 @@ 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,9 +96,7 @@ Future<void> initApp() async {
|
||||
loadFontFile(settings.fontPath.fetch());
|
||||
primaryColor = Color(settings.primaryColor.fetch());
|
||||
|
||||
if (isIOS || isMacOS) {
|
||||
if (settings.icloudSync.fetch()) _syncApple();
|
||||
}
|
||||
if (settings.icloudSync.fetch()) _syncApple();
|
||||
|
||||
if (isAndroid) {
|
||||
// Only start service when [bgRun] is true.
|
||||
@@ -152,11 +150,14 @@ Future<void> _initMacOSWindow() async {
|
||||
await CustomAppBar.updateTitlebarHeight();
|
||||
}
|
||||
|
||||
Future<void> _syncApple() async {
|
||||
// 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/', ''));
|
||||
ICloud.sync(relativePaths: paths);
|
||||
await ICloud.sync(relativePaths: paths);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class BackupPage extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
restore(backup);
|
||||
context.pop();
|
||||
showRestartSnackbar(context, s);
|
||||
showRestartSnackbar(context, btn: s.restart, msg: s.needRestart);
|
||||
},
|
||||
child: Text(s.ok),
|
||||
),
|
||||
|
||||
@@ -368,7 +368,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_setting.primaryColor.put(_selectedColorValue.value);
|
||||
primaryColor = color;
|
||||
context.pop();
|
||||
showRestartSnackbar(context, _s);
|
||||
showRestartSnackbar(context, btn: _s.restart, msg: _s.needRestart);
|
||||
}
|
||||
|
||||
// Widget _buildLaunchPage() {
|
||||
@@ -560,7 +560,11 @@ class _SettingPageState extends State<SettingPage> {
|
||||
onPressed: () {
|
||||
_setting.fontPath.delete();
|
||||
context.pop();
|
||||
showRestartSnackbar(context, _s);
|
||||
showRestartSnackbar(
|
||||
context,
|
||||
btn: _s.restart,
|
||||
msg: _s.needRestart,
|
||||
);
|
||||
},
|
||||
child: Text(_s.clear),
|
||||
)
|
||||
@@ -584,7 +588,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
}
|
||||
|
||||
context.pop();
|
||||
showRestartSnackbar(context, _s);
|
||||
showRestartSnackbar(context, btn: _s.restart, msg: _s.needRestart);
|
||||
return;
|
||||
}
|
||||
showSnackBar(context, Text(_s.failed));
|
||||
@@ -671,7 +675,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
onSelected: (String idx) {
|
||||
_localeCode.value = idx;
|
||||
_setting.locale.put(idx);
|
||||
showRestartSnackbar(context, _s);
|
||||
showRestartSnackbar(context, btn: _s.restart, msg: _s.needRestart);
|
||||
},
|
||||
child: Text(
|
||||
_s.languageName,
|
||||
@@ -762,7 +766,11 @@ class _SettingPageState extends State<SettingPage> {
|
||||
trailing: buildSwitch(
|
||||
context,
|
||||
_setting.fullScreen,
|
||||
func: (_) => showRestartSnackbar(context, _s),
|
||||
func: (_) => showRestartSnackbar(
|
||||
context,
|
||||
btn: _s.restart,
|
||||
msg: _s.needRestart,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user