From 2f96a090c421cbc40be3f2858a54f9a22adba0a8 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Tue, 2 Apr 2024 18:27:06 -0600 Subject: [PATCH] new: auto request noti perm --- lib/core/utils/platform/perm.dart | 13 +++++ lib/data/store/setting.dart | 3 ++ lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_es.arb | 1 + lib/l10n/app_fr.arb | 1 + lib/l10n/app_id.arb | 1 + lib/l10n/app_ja.arb | 1 + lib/l10n/app_pt.arb | 1 + lib/l10n/app_ru.arb | 1 + lib/l10n/app_zh.arb | 1 + lib/l10n/app_zh_tw.arb | 1 + lib/view/page/home.dart | 23 +++++++++ pubspec.lock | 48 +++++++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 17 files changed, 102 insertions(+) create mode 100644 lib/core/utils/platform/perm.dart diff --git a/lib/core/utils/platform/perm.dart b/lib/core/utils/platform/perm.dart new file mode 100644 index 00000000..3504c2e9 --- /dev/null +++ b/lib/core/utils/platform/perm.dart @@ -0,0 +1,13 @@ +import 'package:permission_handler/permission_handler.dart'; + +abstract final class PermUtils { + static Future request(Permission permission) async { + final status = await permission.status; + if (status.isGranted) { + return true; + } else { + final result = await permission.request(); + return result.isGranted; + } + } +} \ No newline at end of file diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 1f5a299e..d3ab802b 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -263,5 +263,8 @@ class SettingStore extends PersistentStore { /// Version of store db late final storeVersion = property('storeVersion', 0); + /// Have notified user for notificaiton permission or not + late final noNotiPerm = property('noNotiPerm', false); + // ------END------ } diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index fe3fcd6f..9d18d78d 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -164,6 +164,7 @@ "newContainer": "Neuer Container", "noClient": "Kein Client", "noInterface": "Kein Interface", + "noNotiPerm": "Keine Benachrichtigungsrechte, möglicherweise keine Fortschrittsanzeige beim Herunterladen von App-Updates.", "noOptions": "Keine Optionen verfügbar", "noResult": "Kein Ergebnis", "noSavedPrivateKey": "Keine gespeicherten Private Keys", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 64b02e1c..91137733 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -164,6 +164,7 @@ "newContainer": "New container", "noClient": "No client", "noInterface": "No interface", + "noNotiPerm": "No notification permissions, possibly no progress indication when downloading app updates.", "noOptions": "No options", "noResult": "No result", "noSavedPrivateKey": "No saved private keys.", diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 848a5395..a07c6e73 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -164,6 +164,7 @@ "newContainer": "Crear contenedor nuevo", "noClient": "No hay conexión SSH", "noInterface": "No hay interfaz disponible", + "noNotiPerm": "Sin permisos de notificación, posiblemente sin indicación de progreso al descargar actualizaciones de la aplicación.", "noOptions": "Sin opciones disponibles", "noResult": "Sin resultados", "noSavedPrivateKey": "No hay llaves privadas guardadas.", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 6ada68a1..122c0790 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -164,6 +164,7 @@ "newContainer": "Nouveau conteneur", "noClient": "Aucun client", "noInterface": "Aucune interface", + "noNotiPerm": "Pas de permissions de notification, il est possible qu'il n'y ait pas de notification de progression lors du téléchargement des mises à jour des applications.", "noOptions": "Aucune option", "noResult": "Aucun résultat", "noSavedPrivateKey": "Aucune clé privée enregistrée.", diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index 310fe383..9e76c684 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -164,6 +164,7 @@ "newContainer": "Wadah baru", "noClient": "Tidak ada klien", "noInterface": "Tidak ada antarmuka", + "noNotiPerm": "Tidak ada izin notifikasi, mungkin tidak ada indikasi kemajuan saat mengunduh pembaruan aplikasi.", "noOptions": "Tidak ada opsi", "noResult": "Tidak ada hasil", "noSavedPrivateKey": "Tidak ada kunci pribadi yang disimpan.", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index ae81dd69..ccb6f9f0 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -164,6 +164,7 @@ "newContainer": "新しいコンテナを作成", "noClient": "SSH接続がありません", "noInterface": "使用可能なインターフェースがありません", + "noNotiPerm": "通知の権限がないため、アプリの更新のダウンロード中に進行状況が表示されない場合があります。", "noOptions": "選択肢がありません", "noResult": "結果なし", "noSavedPrivateKey": "保存されたプライベートキーがありません。", diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index 5a1f8078..4953884e 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -164,6 +164,7 @@ "newContainer": "Novo contêiner", "noClient": "Sem conexão SSH", "noInterface": "Sem interface disponível", + "noNotiPerm": "Sem permissão de notificação, possivelmente sem indicação de progresso ao baixar atualizações de aplicativos.", "noOptions": "Sem opções", "noResult": "Sem resultados", "noSavedPrivateKey": "Nenhuma chave privada salva.", diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index 920708af..4be54b17 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -164,6 +164,7 @@ "newContainer": "создать контейнер", "noClient": "нет SSH соединения", "noInterface": "нет доступных интерфейсов", + "noNotiPerm": "Нет разрешения на уведомления, возможно отсутствие индикации прогресса при загрузке обновлений приложений.", "noOptions": "нет доступных опций", "noResult": "нет результатов", "noSavedPrivateKey": "Нет сохраненных приватных ключей.", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 9efe68fe..5a7ac70a 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -164,6 +164,7 @@ "newContainer": "新建容器", "noClient": "没有SSH连接", "noInterface": "没有可用的接口", + "noNotiPerm": "无通知权限,可能下载App更新时无进度提示。", "noOptions": "无可选项", "noResult": "无结果", "noSavedPrivateKey": "没有已保存的私钥。", diff --git a/lib/l10n/app_zh_tw.arb b/lib/l10n/app_zh_tw.arb index 68a2e58c..5ff002e1 100644 --- a/lib/l10n/app_zh_tw.arb +++ b/lib/l10n/app_zh_tw.arb @@ -164,6 +164,7 @@ "newContainer": "新建容器", "noClient": "沒有SSH連接", "noInterface": "沒有可用的接口", + "noNotiPerm": "無通知權限,可能在下載應用程式更新時沒有進度提示。", "noOptions": "無可選項", "noResult": "無結果", "noSavedPrivateKey": "沒有已保存的私鑰。", diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 6a098c38..5f2324cb 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -4,14 +4,17 @@ import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:get_it/get_it.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:toolbox/core/channel/bg_run.dart'; import 'package:toolbox/core/channel/home_widget.dart'; +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/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/data/res/github_id.dart'; import 'package:toolbox/data/res/logger.dart'; import 'package:toolbox/data/res/provider.dart'; @@ -315,6 +318,26 @@ ${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), + ), + ], + ); + } + }); + if (Stores.setting.autoCheckAppUpdate.fetch()) { doUpdate(context); } diff --git a/pubspec.lock b/pubspec.lock index 67739608..4e669187 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -815,6 +815,54 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" + url: "https://pub.dev" + source: hosted + version: "11.3.1" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + sha256: "1acac6bae58144b442f11e66621c062aead9c99841093c38f5bcdcc24c1c3474" + url: "https://pub.dev" + source: hosted + version: "12.0.5" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + sha256: e9ad66020b89ff1b63908f247c2c6f931c6e62699b756ef8b3c4569350cd8662 + url: "https://pub.dev" + source: hosted + version: "9.4.4" + permission_handler_html: + dependency: transitive + description: + name: permission_handler_html + sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d" + url: "https://pub.dev" + source: hosted + version: "0.1.1" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + sha256: "48d4fcf201a1dad93ee869ab0d4101d084f49136ec82a8a06ed9cfeacab9fd20" + url: "https://pub.dev" + source: hosted + version: "4.2.1" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" + url: "https://pub.dev" + source: hosted + version: "0.2.1" petitparser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6e4b230b..dff5d04e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -73,6 +73,7 @@ dependencies: url: https://github.com/lollipopkit/dart_computer flutter_background_service: ^5.0.5 icons_plus: ^5.0.0 + permission_handler: ^11.3.1 dev_dependencies: flutter_native_splash: ^2.1.6 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index b29d6496..28c6f2d7 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); LocalAuthPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("LocalAuthPlugin")); + PermissionHandlerWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); ScreenRetrieverPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); SharePlusWindowsPluginCApiRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 16e54273..2e41e0f1 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST dynamic_color local_auth_windows + permission_handler_windows screen_retriever share_plus url_launcher_windows