From aed5a63a199888b19c143bd337c9c4c5d2499276 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Mon, 8 Apr 2024 20:13:00 +0800 Subject: [PATCH] opt.: only req noti perm on Android --- README.md | 4 +- README_zh.md | 4 +- lib/app.dart | 2 +- lib/core/route.dart | 2 +- lib/core/utils/platform/perm.dart | 2 +- lib/data/model/app/shell_func.dart | 2 +- lib/view/page/home/appbar.dart | 28 +++++++++ lib/view/page/{ => home}/home.dart | 90 ++++++++++----------------- lib/view/widget/server_func_btns.dart | 3 +- 9 files changed, 72 insertions(+), 65 deletions(-) create mode 100644 lib/view/page/home/appbar.dart rename lib/view/page/{ => home}/home.dart (87%) diff --git a/README.md b/README.md index 65d50f2a..ff5c8f44 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Especially thanks to dartss ## ⬇️ Download Platform | Support | Sign --- | --- | --- -[iOS](https://apps.apple.com/app/id1586449703) / [Android](https://res.lolli.tech/serverbox/latest.apk) / [macOS](https://apps.apple.com/app/id1586449703) | Full | My own certificate -[Linux](https://res.lolli.tech/serverbox/latest.AppImage) / [Windows](https://res.lolli.tech/serverbox/latest.win.zip) | Not tested | Flutter default certificate +[iOS](https://apps.apple.com/app/id1586449703) / [Android](https://cdn.lolli.tech/serverbox/latest.apk) / [macOS](https://apps.apple.com/app/id1586449703) | Full | My own certificate +[Linux](https://cdn.lolli.tech/serverbox/latest.AppImage) / [Windows](https://cdn.lolli.tech/serverbox/latest.win.zip) | Not tested | Flutter default certificate ## 🆘 Help diff --git a/README_zh.md b/README_zh.md index 18517946..fafe82dc 100644 --- a/README_zh.md +++ b/README_zh.md @@ -58,8 +58,8 @@ ## ⬇️ 下载 平台 | 支持 | 签名 :-: | :-: | :-: -[iOS](https://apps.apple.com/app/id1586449703) / [Android](https://res.lolli.tech/serverbox/latest.apk) / [macOS](https://apps.apple.com/app/id1586449703) | 完整 | 个人可信签名 -[Linux](https://res.lolli.tech/serverbox/latest.AppImage) / [Windows](https://res.lolli.tech/serverbox/latest.win.zip) | 未测试 | Flutter 默认签名 +[iOS](https://apps.apple.com/app/id1586449703) / [Android](https://cdn.lolli.tech/serverbox/latest.apk) / [macOS](https://apps.apple.com/app/id1586449703) | 完整 | 个人可信签名 +[Linux](https://cdn.lolli.tech/serverbox/latest.AppImage) / [Windows](https://cdn.lolli.tech/serverbox/latest.win.zip) | 未测试 | Flutter 默认签名 ## 🆘 帮助 diff --git a/lib/app.dart b/lib/app.dart index b2107a98..897b9220 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -9,7 +9,7 @@ import 'package:toolbox/data/res/build_data.dart'; import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/rebuild.dart'; import 'package:toolbox/data/res/store.dart'; -import 'package:toolbox/view/page/home.dart'; +import 'package:toolbox/view/page/home/home.dart'; class MyApp extends StatelessWidget { const MyApp({super.key}); diff --git a/lib/core/route.dart b/lib/core/route.dart index 299ce989..c727e7ad 100644 --- a/lib/core/route.dart +++ b/lib/core/route.dart @@ -4,7 +4,7 @@ import 'package:toolbox/data/model/server/private_key_info.dart'; import 'package:toolbox/data/model/server/server_private_info.dart'; import 'package:toolbox/view/page/backup.dart'; import 'package:toolbox/view/page/container.dart'; -import 'package:toolbox/view/page/home.dart'; +import 'package:toolbox/view/page/home/home.dart'; import 'package:toolbox/view/page/iperf.dart'; import 'package:toolbox/view/page/ping.dart'; import 'package:toolbox/view/page/private_key/edit.dart'; diff --git a/lib/core/utils/platform/perm.dart b/lib/core/utils/platform/perm.dart index 3504c2e9..3bf56a43 100644 --- a/lib/core/utils/platform/perm.dart +++ b/lib/core/utils/platform/perm.dart @@ -10,4 +10,4 @@ abstract final class PermUtils { return result.isGranted; } } -} \ No newline at end of file +} diff --git a/lib/data/model/app/shell_func.dart b/lib/data/model/app/shell_func.dart index 697e2f63..4a4237e4 100644 --- a/lib/data/model/app/shell_func.dart +++ b/lib/data/model/app/shell_func.dart @@ -269,4 +269,4 @@ extension StatusCmdTypeX on StatusCmdType { StatusCmdType.battery => l10n.battery, final val => val.name, }; -} \ No newline at end of file +} diff --git a/lib/view/page/home/appbar.dart b/lib/view/page/home/appbar.dart new file mode 100644 index 00000000..a541e704 --- /dev/null +++ b/lib/view/page/home/appbar.dart @@ -0,0 +1,28 @@ +part of 'home.dart'; + +final class _AppBar extends CustomAppBar { + final ValueNotifier selectIndex; + + const _AppBar({ + required this.selectIndex, + super.title, + super.actions, + super.centerTitle, + }); + + @override + Widget build(BuildContext context) { + return ValueListenableBuilder( + valueListenable: selectIndex, + builder: (_, idx, __) { + if (idx == AppTab.ssh.index) { + return SizedBox( + height: CustomAppBar.barHeight ?? + 0 + MediaQuery.of(context).padding.top, + ); + } + return super.build(context); + }, + ); + } +} diff --git a/lib/view/page/home.dart b/lib/view/page/home/home.dart similarity index 87% rename from lib/view/page/home.dart rename to lib/view/page/home/home.dart index 5f2324cb..ed47bdc1 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home/home.dart @@ -11,26 +11,28 @@ import 'package:toolbox/core/extension/context/common.dart'; import 'package:toolbox/core/extension/context/dialog.dart'; import 'package:toolbox/core/extension/context/locale.dart'; import 'package:toolbox/core/persistant_store.dart'; +import 'package:toolbox/core/route.dart'; import 'package:toolbox/core/update.dart'; import 'package:toolbox/core/utils/platform/auth.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/core/utils/platform/perm.dart'; +import 'package:toolbox/core/utils/ui.dart'; +import 'package:toolbox/data/model/app/github_id.dart'; +import 'package:toolbox/data/model/app/tab.dart'; +import 'package:toolbox/data/res/build_data.dart'; import 'package:toolbox/data/res/github_id.dart'; import 'package:toolbox/data/res/logger.dart'; +import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/data/res/store.dart'; +import 'package:toolbox/data/res/ui.dart'; +import 'package:toolbox/data/res/url.dart'; +import 'package:toolbox/view/widget/appbar.dart'; +import 'package:toolbox/view/widget/cardx.dart'; import 'package:toolbox/view/widget/markdown.dart'; -import '../../core/route.dart'; -import '../../core/utils/ui.dart'; -import '../../data/model/app/github_id.dart'; -import '../../data/model/app/tab.dart'; -import '../../data/res/build_data.dart'; -import '../../data/res/misc.dart'; -import '../../data/res/ui.dart'; -import '../../data/res/url.dart'; -import '../widget/appbar.dart'; -import '../widget/cardx.dart'; + +part 'appbar.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -318,25 +320,7 @@ ${GithubIds.participants.map((e) => '[$e](${e.url})').join(' ')} // Auth required for first launch BioAuth.go(); - PermUtils.request(Permission.notification).then((suc) { - if (!suc) { - final noNotiPerm = Stores.setting.noNotiPerm; - if (noNotiPerm.fetch()) return; - context.showRoundDialog( - title: Text(l10n.error), - child: Text(l10n.noNotiPerm), - actions: [ - TextButton( - onPressed: () { - noNotiPerm.put(true); - context.pop(); - }, - child: Text(l10n.ok), - ), - ], - ); - } - }); + _reqNotiPerm(); if (Stores.setting.autoCheckAppUpdate.fetch()) { doUpdate(context); @@ -347,6 +331,27 @@ ${GithubIds.participants.map((e) => '[$e](${e.url})').join(' ')} await Pros.server.refresh(); } + Future _reqNotiPerm() async { + final suc = await PermUtils.request(Permission.notification); + if (!suc) { + final noNotiPerm = Stores.setting.noNotiPerm; + if (noNotiPerm.fetch()) return; + context.showRoundDialog( + title: Text(l10n.error), + child: Text(l10n.noNotiPerm), + actions: [ + TextButton( + onPressed: () { + noNotiPerm.put(true); + context.pop(); + }, + child: Text(l10n.ok), + ), + ], + ); + } + } + Future _onLongPressSetting() async { final map = Stores.setting.box.toJson(includeInternal: false); final keys = map.keys; @@ -378,30 +383,3 @@ ${GithubIds.participants.map((e) => '[$e](${e.url})').join(' ')} } } } - -final class _AppBar extends CustomAppBar { - final ValueNotifier selectIndex; - - const _AppBar({ - required this.selectIndex, - super.title, - super.actions, - super.centerTitle, - }); - - @override - Widget build(BuildContext context) { - return ValueListenableBuilder( - valueListenable: selectIndex, - builder: (_, idx, __) { - if (idx == AppTab.ssh.index) { - return SizedBox( - height: CustomAppBar.barHeight ?? - 0 + MediaQuery.of(context).padding.top, - ); - } - return super.build(context); - }, - ); - } -} diff --git a/lib/view/widget/server_func_btns.dart b/lib/view/widget/server_func_btns.dart index bab8d298..5ace957b 100644 --- a/lib/view/widget/server_func_btns.dart +++ b/lib/view/widget/server_func_btns.dart @@ -280,7 +280,8 @@ Future _onPkg(BuildContext context, ServerPrivateInfo spi) async { final gotoUpgrade = await context.showRoundDialog( title: Text(l10n.attention), child: SingleChildScrollView( - child: Text('${l10n.pkgUpgradeTip}\n${l10n.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'), + child: Text( + '${l10n.pkgUpgradeTip}\n${l10n.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'), ), actions: [ CountDownBtn(