diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/ServiceNotification.kt b/app/src/main/java/io/nekohasekai/sfa/bg/ServiceNotification.kt index 52a236f..7a8b0f0 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/ServiceNotification.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/ServiceNotification.kt @@ -95,7 +95,7 @@ class ServiceNotification( } suspend fun start() { - if (Settings.dynamicNotification) { + if (Settings.dynamicNotification && checkPermission()) { commandClient.connect() withContext(Dispatchers.Main) { registerReceiver() diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt index 0cfb338..319157f 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt @@ -221,7 +221,10 @@ class MainActivity : AbstractActivity(), notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) return } + startService0() + } + private fun startService0() { lifecycleScope.launch(Dispatchers.IO) { if (Settings.rebuildServiceMode()) { reconnect() @@ -241,10 +244,10 @@ class MainActivity : AbstractActivity(), private val notificationPermissionLauncher = registerForActivityResult( ActivityResultContracts.RequestPermission() ) { - if (it) { - startService() - } else { + if (Settings.dynamicNotification && !it) { onServiceAlert(Alert.RequestNotificationPermission, null) + } else { + startService0() } } @@ -304,6 +307,8 @@ class MainActivity : AbstractActivity(), } override fun onServiceAlert(type: Alert, message: String?) { + serviceStatus.value = Status.Stopped + when (type) { Alert.RequestLocationPermission -> { return requestLocationPermission() @@ -320,7 +325,8 @@ class MainActivity : AbstractActivity(), } Alert.RequestNotificationPermission -> { - builder.setMessage(getString(R.string.service_error_missing_notification_permission)) + builder.setTitle(R.string.notification_permission_title) + builder.setMessage(R.string.notification_permission_required_description) } Alert.EmptyConfiguration -> { diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 8fe6e38..53f0e16 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -161,4 +161,6 @@ wifi_ssidwifi_bssid 路由规则。为了使它们正常工作,sing-box 在后台使用 位置 权限来获取有关所连接 Wi-Fi 网络的信息。该信息将仅用于路由目的。]]> 后台位置权限。选择始终允许以授予权限。]]> 打开设置 + 通知权限 + sing-box 无法在没有发送通知权限的情况下显示实时网速。请授予权限或禁用实时网速通知后再启动服务。 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 978c460..d8d1db7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -188,6 +188,6 @@ wifi_ssid or wifi_bssid routing rules. To make them work, sing-box uses the location permission in the background to get information about the connected Wi-Fi network. The information will be used for routing purposes only.]]> background location permission is required. Select Allow all the time to grant the permission.]]> Open Settings - - + Notification permission + sing-box is unable to show real-time network speeds without the permission to send notifications. Please grant the permission or disable real-time network speeds notification before starting the service. \ No newline at end of file