new: support msg push

This commit is contained in:
lollipopkit
2023-03-12 16:06:51 +08:00
parent 35b5d1ccb5
commit 4c4153ef98
12 changed files with 113 additions and 25 deletions

View File

@@ -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<bool> shareFiles(BuildContext context, List<String> filePaths) async {
@@ -31,3 +32,16 @@ Future<String?> pickOneFile() async {
final result = await FilePicker.platform.pickFiles(type: FileType.any);
return result?.files.single.path;
}
Future<String?> 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();
}

View File

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

View File

@@ -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} 提交问题",

View File

@@ -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<SettingPage> {
late double _maxRetryCount;
late double _updateInterval;
String? _pushToken;
@override
void didChangeDependencies() {
super.didChangeDependencies();
@@ -70,6 +73,7 @@ class _SettingPageState extends State<SettingPage> {
// Server
_buildTitle(_s.server),
_buildServer(),
const SizedBox(height: 37),
],
),
);
@@ -81,7 +85,6 @@ class _SettingPageState extends State<SettingPage> {
child: Center(
child: Text(
text,
style: textSize13,
),
),
);
@@ -90,10 +93,11 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildApp() {
return Column(
children: [
_buildNightMode(),
_buildThemeMode(),
_buildAppColorPreview(),
_buildLaunchPage(),
_buildCheckUpdate(),
_buildPushToken(),
].map((e) => RoundRectCard(e)).toList(),
);
}
@@ -113,11 +117,10 @@ class _SettingPageState extends State<SettingPage> {
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<SettingPage> {
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<SettingPage> {
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<SettingPage> {
_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<SettingPage> {
),
title: Text(
_s.appPrimaryColor,
style: textSize13,
),
children: [_buildAppColorPicker(), _buildColorPickerConfirmBtn()],
);
@@ -245,13 +242,11 @@ class _SettingPageState extends State<SettingPage> {
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<SettingPage> {
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<SettingPage> {
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<SettingPage> {
contentPadding: EdgeInsets.zero,
title: Text(
e.name,
style: textSize13,
),
trailing: _buildTermThemeRadio(e),
),
@@ -333,12 +324,10 @@ class _SettingPageState extends State<SettingPage> {
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<SettingPage> {
_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<SettingPage> {
);
}
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<SettingPage> {
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<String?>(
future: getToken(),
builder: (context, snapshot) {
if (snapshot.hasData) {
_pushToken = snapshot.data;
}
return Text(
_pushToken ?? 'Getting Token...',
style: grey,
overflow: TextOverflow.ellipsis,
maxLines: 1,
);
},
),
);
}
}