Fix notification
This commit is contained in:
@@ -17,7 +17,6 @@ import io.nekohasekai.libbox.BoxService
|
||||
import io.nekohasekai.libbox.CommandServer
|
||||
import io.nekohasekai.libbox.CommandServerHandler
|
||||
import io.nekohasekai.libbox.Libbox
|
||||
import io.nekohasekai.libbox.PProfServer
|
||||
import io.nekohasekai.libbox.PlatformInterface
|
||||
import io.nekohasekai.libbox.SystemProxyStatus
|
||||
import io.nekohasekai.sfa.Application
|
||||
@@ -89,7 +88,6 @@ class BoxService(
|
||||
private val notification = ServiceNotification(status, service)
|
||||
private var boxService: BoxService? = null
|
||||
private var commandServer: CommandServer? = null
|
||||
private var pprofServer: PProfServer? = null
|
||||
private var receiverRegistered = false
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
|
||||
@@ -44,6 +44,7 @@ class ServiceNotification(
|
||||
|
||||
private val commandClient =
|
||||
CommandClient(GlobalScope, CommandClient.ConnectionType.Status, this)
|
||||
private var receiverRegistered = false
|
||||
|
||||
private val notificationBuilder by lazy {
|
||||
NotificationCompat.Builder(service, notificationChannel).setShowWhen(false).setOngoing(true)
|
||||
@@ -103,6 +104,7 @@ class ServiceNotification(
|
||||
addAction(Intent.ACTION_SCREEN_ON)
|
||||
addAction(Intent.ACTION_SCREEN_OFF)
|
||||
})
|
||||
receiverRegistered = true
|
||||
}
|
||||
|
||||
override fun updateStatus(status: StatusMessage) {
|
||||
@@ -129,6 +131,9 @@ class ServiceNotification(
|
||||
fun close() {
|
||||
commandClient.disconnect()
|
||||
ServiceCompat.stopForeground(service, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
service.unregisterReceiver(this)
|
||||
if (receiverRegistered) {
|
||||
service.unregisterReceiver(this)
|
||||
receiverRegistered = false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user