#157 opt.: icloud sync

This commit is contained in:
lollipopkit
2023-09-11 22:39:44 +08:00
parent 82b0abaab3
commit 6e4aa8e56e
22 changed files with 119 additions and 41 deletions

View File

@@ -614,6 +614,12 @@ abstract class S {
/// **'request failed, status code: {code}'**
String httpFailedWithCode(Object code);
/// No description provided for @icloudSynced.
///
/// In en, this message translates to:
/// **'iCloud wird synchronisiert und einige Einstellungen erfordern möglicherweise einen Neustart der App, um wirksam zu werden.'**
String get icloudSynced;
/// No description provided for @image.
///
/// In en, this message translates to:

View File

@@ -278,6 +278,9 @@ class SDe extends S {
return 'Anfrage fehlgeschlagen, Statuscode: $code';
}
@override
String get icloudSynced => 'iCloud wird synchronisiert und einige Einstellungen erfordern möglicherweise einen Neustart der App, um wirksam zu werden.';
@override
String get image => 'Image';

View File

@@ -278,6 +278,9 @@ class SEn extends S {
return 'request failed, status code: $code';
}
@override
String get icloudSynced => 'iCloud wird synchronisiert und einige Einstellungen erfordern möglicherweise einen Neustart der App, um wirksam zu werden.';
@override
String get image => 'Image';

View File

@@ -278,6 +278,9 @@ class SId extends S {
return 'Permintaan gagal, kode status: $code';
}
@override
String get icloudSynced => 'iCloud disinkronkan dan beberapa pengaturan mungkin memerlukan pengaktifan ulang aplikasi agar dapat diterapkan.';
@override
String get image => 'Gambar';

View File

@@ -278,6 +278,9 @@ class SZh extends S {
return '请求失败, 状态码: $code';
}
@override
String get icloudSynced => 'iCloud已同步某些设置可能需要重启才能生效。';
@override
String get image => '镜像';
@@ -1013,6 +1016,9 @@ class SZhTw extends SZh {
return '請求失敗, 狀態碼: $code';
}
@override
String get icloudSynced => 'iCloud已同步某些設置可能需要重啟才能生效。';
@override
String get image => '鏡像';

View File

@@ -6,6 +6,8 @@ PODS:
- Flutter (1.0.0)
- flutter_native_splash (0.0.1):
- Flutter
- icloud_storage (0.0.1):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
@@ -26,6 +28,7 @@ DEPENDENCIES:
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- Flutter (from `Flutter`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- icloud_storage (from `.symlinks/plugins/icloud_storage/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- plain_notification_token (from `.symlinks/plugins/plain_notification_token/ios`)
- r_upgrade (from `.symlinks/plugins/r_upgrade/ios`)
@@ -42,6 +45,8 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_native_splash:
:path: ".symlinks/plugins/flutter_native_splash/ios"
icloud_storage:
:path: ".symlinks/plugins/icloud_storage/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
plain_notification_token:
@@ -60,6 +65,7 @@ SPEC CHECKSUMS:
file_picker: 1d63c4949e05e386da864365f8c13e1e64787675
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
icloud_storage: d9ac7a33ced81df08ba7ea1bf3099cc0ee58f60a
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
plain_notification_token: b36467dc91939a7b6754267c701bbaca14996ee1
r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114

View File

@@ -472,7 +472,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -480,7 +480,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -604,7 +604,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/RunnerDebug.entitlements;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -612,7 +612,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -630,7 +630,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -638,7 +638,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -659,7 +659,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -672,7 +672,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
@@ -698,7 +698,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -711,7 +711,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -734,7 +734,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -747,7 +747,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -4,5 +4,17 @@
<dict>
<key>aps-environment</key>
<string>production</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
</dict>
</plist>

View File

@@ -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) {

View File

@@ -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),
);
}

View File

@@ -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;
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -86,6 +86,7 @@
"homeWidgetUrlConfig": "桌面部件链接配置",
"host": "主机",
"httpFailedWithCode": "请求失败, 状态码: {code}",
"icloudSynced": "iCloud已同步某些设置可能需要重启才能生效。",
"image": "镜像",
"imagesList": "镜像列表",
"import": "导入",

View File

@@ -86,6 +86,7 @@
"homeWidgetUrlConfig": "桌面部件鏈接配置",
"host": "主機",
"httpFailedWithCode": "請求失敗, 狀態碼: {code}",
"icloudSynced": "iCloud已同步某些設置可能需要重啟才能生效。",
"image": "鏡像",
"imagesList": "鏡像列表",
"import": "導入",

View File

@@ -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);
}

View File

@@ -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),
),

View File

@@ -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,
),
),
);
}

View File

@@ -476,9 +476,9 @@
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -491,9 +491,9 @@
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -506,9 +506,9 @@
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 539;
CURRENT_PROJECT_VERSION = 542;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.539;
MARKETING_VERSION = 1.0.542;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;

View File

@@ -2,13 +2,25 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>

View File

@@ -2,9 +2,23 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.tech.lolli.serverbox</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>