From 4c4153ef985817e2c049bc3c9311a76a42b4021e Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sun, 12 Mar 2023 16:06:51 +0800 Subject: [PATCH] new: support msg `push` --- .dart_tool/flutter_gen/gen_l10n/l10n.dart | 12 ++++ .dart_tool/flutter_gen/gen_l10n/l10n_en.dart | 6 ++ .dart_tool/flutter_gen/gen_l10n/l10n_zh.dart | 6 ++ ios/Podfile.lock | 6 ++ ios/Runner.xcodeproj/project.pbxproj | 5 ++ ios/Runner/Runner.entitlements | 8 +++ lib/core/utils/misc.dart | 14 ++++ lib/l10n/app_en.arb | 2 + lib/l10n/app_zh.arb | 2 + lib/view/page/setting.dart | 68 +++++++++++++------- pubspec.lock | 8 +++ pubspec.yaml | 1 + 12 files changed, 113 insertions(+), 25 deletions(-) create mode 100644 ios/Runner/Runner.entitlements diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n.dart b/.dart_tool/flutter_gen/gen_l10n/l10n.dart index ccbfd4fe..0318200a 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n.dart @@ -447,6 +447,12 @@ abstract class S { /// **'Found {count} update'** String foundNUpdate(Object count); + /// No description provided for @getPushTokenFailed. + /// + /// In en, this message translates to: + /// **'Can\'t fetch push token'** + String get getPushTokenFailed; + /// No description provided for @go. /// /// In en, this message translates to: @@ -765,6 +771,12 @@ abstract class S { /// **'Private Key'** String get privateKey; + /// No description provided for @pushToken. + /// + /// In en, this message translates to: + /// **'Push token'** + String get pushToken; + /// No description provided for @pwd. /// /// In en, this message translates to: diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart index 379bec4c..b5a18628 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart @@ -197,6 +197,9 @@ class SEn extends S { return 'Found $count update'; } + @override + String get getPushTokenFailed => 'Can\'t fetch push token'; + @override String get go => 'Go'; @@ -362,6 +365,9 @@ class SEn extends S { @override String get privateKey => 'Private Key'; + @override + String get pushToken => 'Push token'; + @override String get pwd => 'Password'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart index e9ef0997..e7e5cd53 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart @@ -197,6 +197,9 @@ class SZh extends S { return '找到 $count 个更新'; } + @override + String get getPushTokenFailed => '未能获取到推送token'; + @override String get go => '开始'; @@ -362,6 +365,9 @@ class SZh extends S { @override String get privateKey => '私钥'; + @override + String get pushToken => '消息推送 Token'; + @override String get pwd => '密码'; diff --git a/ios/Podfile.lock b/ios/Podfile.lock index fb5aed99..f352ff16 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -9,6 +9,8 @@ PODS: - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS + - plain_notification_token (0.0.1): + - Flutter - r_upgrade (0.0.1): - Flutter - share_plus (0.0.1): @@ -22,6 +24,7 @@ DEPENDENCIES: - Flutter (from `Flutter`) - flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`) + - plain_notification_token (from `.symlinks/plugins/plain_notification_token/ios`) - r_upgrade (from `.symlinks/plugins/r_upgrade/ios`) - share_plus (from `.symlinks/plugins/share_plus/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) @@ -37,6 +40,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_native_splash/ios" path_provider_foundation: :path: ".symlinks/plugins/path_provider_foundation/ios" + plain_notification_token: + :path: ".symlinks/plugins/plain_notification_token/ios" r_upgrade: :path: ".symlinks/plugins/r_upgrade/ios" share_plus: @@ -50,6 +55,7 @@ SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 + plain_notification_token: b36467dc91939a7b6754267c701bbaca14996ee1 r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114 share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68 url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index a7b5de9f..bd67b5a6 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9C5314B89F1F73A1900CCAFD /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; A775F241DEE026555178AC01 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + E398BF6A29BDB34500FE4FD5 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -104,6 +105,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + E398BF6A29BDB34500FE4FD5 /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, @@ -356,6 +358,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = 228; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; @@ -486,6 +489,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = 228; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; @@ -510,6 +514,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = 228; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements new file mode 100644 index 00000000..903def2a --- /dev/null +++ b/ios/Runner/Runner.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/lib/core/utils/misc.dart b/lib/core/utils/misc.dart index f7c17133..8fad77ff 100644 --- a/lib/core/utils/misc.dart +++ b/lib/core/utils/misc.dart @@ -4,6 +4,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:plain_notification_token/plain_notification_token.dart'; import 'package:share_plus/share_plus.dart'; Future shareFiles(BuildContext context, List filePaths) async { @@ -31,3 +32,16 @@ Future pickOneFile() async { final result = await FilePicker.platform.pickFiles(type: FileType.any); return result?.files.single.path; } + +Future getToken() async { + final plainNotificationToken = PlainNotificationToken(); + if (Platform.isIOS) { + plainNotificationToken.requestPermission(); + + // If you want to wait until Permission dialog close, + // you need wait changing setting registered. + await plainNotificationToken.onIosSettingsRegistered.first; + } + + return await plainNotificationToken.getToken(); +} diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index e1916c72..b1eb19cb 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -58,6 +58,7 @@ "fileTooLarge": "File '{file}' too large {size}, max {sizeMax}", "files": "Files", "foundNUpdate": "Found {count} update", + "getPushTokenFailed": "Can't fetch push token", "go": "Go", "goto": "Go to", "host": "Host", @@ -111,6 +112,7 @@ "port": "Port", "preview": "Preview", "privateKey": "Private Key", + "pushToken": "Push token", "pwd": "Password", "rename": "Rename", "reportBugsOnGithubIssue": "Please report bugs on {url}", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index c2e160b7..2e037b93 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -58,6 +58,7 @@ "fileTooLarge": "文件 '{file}' 过大 '{size}',超过了 {sizeMax}", "files": "文件", "foundNUpdate": "找到 {count} 个更新", + "getPushTokenFailed": "未能获取到推送token", "go": "开始", "goto": "前往", "host": "主机", @@ -111,6 +112,7 @@ "port": "端口", "preview": "预览", "privateKey": "私钥", + "pushToken": "消息推送 Token", "pwd": "密码", "rename": "重命名", "reportBugsOnGithubIssue": "请到 {url} 提交问题", diff --git a/lib/view/page/setting.dart b/lib/view/page/setting.dart index deb7e173..b42fc213 100644 --- a/lib/view/page/setting.dart +++ b/lib/view/page/setting.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_material_color_picker/flutter_material_color_picker.dart'; import 'package:provider/provider.dart'; +import 'package:toolbox/core/utils/misc.dart'; import '../../data/model/ssh/terminal_color.dart'; import '../../core/update.dart'; @@ -36,6 +37,8 @@ class _SettingPageState extends State { late double _maxRetryCount; late double _updateInterval; + String? _pushToken; + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -70,6 +73,7 @@ class _SettingPageState extends State { // Server _buildTitle(_s.server), _buildServer(), + const SizedBox(height: 37), ], ), ); @@ -81,7 +85,6 @@ class _SettingPageState extends State { child: Center( child: Text( text, - style: textSize13, ), ), ); @@ -90,10 +93,11 @@ class _SettingPageState extends State { Widget _buildApp() { return Column( children: [ - _buildNightMode(), + _buildThemeMode(), _buildAppColorPreview(), _buildLaunchPage(), _buildCheckUpdate(), + _buildPushToken(), ].map((e) => RoundRectCard(e)).toList(), ); } @@ -113,11 +117,10 @@ class _SettingPageState extends State { return ListTile( title: Text( _s.showDistLogo, - style: textSize13, ), subtitle: Text( _s.onServerDetailPage, - style: textSize13Grey, + style: grey, ), trailing: buildSwitch(context, _setting.showDistLogo), ); @@ -140,8 +143,6 @@ class _SettingPageState extends State { trailing: const Icon(Icons.keyboard_arrow_right), title: Text( display, - style: textSize13, - textAlign: TextAlign.start, ), onTap: () => doUpdate(context, force: true), ); @@ -154,16 +155,13 @@ class _SettingPageState extends State { textColor: primaryColor, title: Text( _s.updateServerStatusInterval, - style: textSize13, - textAlign: TextAlign.start, ), subtitle: Text( _s.willTakEeffectImmediately, - style: textSize13Grey, + style: grey, ), trailing: Text( '${_updateInterval.toInt()} ${_s.second}', - style: textSize13, ), children: [ Slider( @@ -190,7 +188,7 @@ class _SettingPageState extends State { _updateInterval == 0.0 ? Text( _s.updateIntervalEqual0, - style: const TextStyle(color: Colors.grey, fontSize: 12), + style: grey, textAlign: TextAlign.center, ) : const SizedBox(), @@ -213,7 +211,6 @@ class _SettingPageState extends State { ), title: Text( _s.appPrimaryColor, - style: textSize13, ), children: [_buildAppColorPicker(), _buildColorPickerConfirmBtn()], ); @@ -245,13 +242,11 @@ class _SettingPageState extends State { textColor: primaryColor, title: Text( _s.launchPage, - style: textSize13, ), trailing: ConstrainedBox( constraints: BoxConstraints(maxWidth: _media.size.width * 0.35), child: Text( tabTitleName(context, _launchPageIdx), - style: textSize13, textAlign: TextAlign.right, ), ), @@ -261,7 +256,6 @@ class _SettingPageState extends State { contentPadding: EdgeInsets.zero, title: Text( tabTitleName(context, tabs.indexOf(e)), - style: textSize13, ), trailing: _buildRadio(tabs.indexOf(e)), ), @@ -289,11 +283,9 @@ class _SettingPageState extends State { childrenPadding: const EdgeInsets.only(left: 17), title: Text( _s.termTheme, - style: textSize13, ), trailing: Text( TerminalColorsPlatform.values[_termThemeIdx].name, - style: textSize13, ), children: _buildTermThemeRadioList(), ); @@ -306,7 +298,6 @@ class _SettingPageState extends State { contentPadding: EdgeInsets.zero, title: Text( e.name, - style: textSize13, ), trailing: _buildTermThemeRadio(e), ), @@ -333,12 +324,10 @@ class _SettingPageState extends State { textColor: primaryColor, title: Text( _s.maxRetryCount, - style: textSize13, textAlign: TextAlign.start, ), trailing: Text( '${_maxRetryCount.toInt()} ${_s.times}', - style: textSize13, ), children: [ Slider( @@ -364,7 +353,7 @@ class _SettingPageState extends State { _maxRetryCount == 0.0 ? Text( _s.maxRetryCountEqual0, - style: const TextStyle(color: Colors.grey, fontSize: 12), + style: grey, textAlign: TextAlign.center, ) : const SizedBox(), @@ -375,17 +364,14 @@ class _SettingPageState extends State { ); } - Widget _buildNightMode() { + Widget _buildThemeMode() { return ExpansionTile( textColor: primaryColor, title: Text( _s.themeMode, - style: textSize13, - textAlign: TextAlign.start, ), trailing: Text( _buildNightModeStr(_nightMode), - style: textSize13, ), children: [ Slider( @@ -419,4 +405,36 @@ class _SettingPageState extends State { return _s.auto; } } + + Widget _buildPushToken() { + return ListTile( + title: Text( + _s.pushToken, + ), + trailing: TextButton( + child: Text(_s.copy), + onPressed: () { + if (_pushToken != null) { + copy(_pushToken!); + } else { + showSnackBar(context, Text(_s.getPushTokenFailed)); + } + }, + ), + subtitle: FutureBuilder( + future: getToken(), + builder: (context, snapshot) { + if (snapshot.hasData) { + _pushToken = snapshot.data; + } + return Text( + _pushToken ?? 'Getting Token...', + style: grey, + overflow: TextOverflow.ellipsis, + maxLines: 1, + ); + }, + ), + ); + } } diff --git a/pubspec.lock b/pubspec.lock index 396c1605..021ca76f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -646,6 +646,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" + plain_notification_token: + dependency: "direct main" + description: + name: plain_notification_token + sha256: "32481c1c6ad76613ed38822ffe819ea5d5534f9e07e8ff1d44aafe069f45ea24" + url: "https://pub.dev" + source: hosted + version: "0.0.4" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index cc5226b0..9a73b8e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ dependencies: xterm: path: ../xterm.dart file_picker: ^5.2.5 + plain_notification_token: ^0.0.4 dev_dependencies: flutter_native_splash: ^2.1.6