From 6ef3c02a13d97186ad51f7e8faa8efb4ea406636 Mon Sep 17 00:00:00 2001 From: Antecer Date: Sun, 7 Apr 2024 00:01:08 +0800 Subject: [PATCH] =?UTF-8?q?web=E6=9C=8D=E5=8A=A1=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A0=8F=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/WebService.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 446693307..f2512145c 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -60,6 +60,7 @@ class WebService : BaseService() { } private var httpServer: HttpServer? = null private var webSocketServer: WebSocketServer? = null + private var notificationList = mutableListOf(appCtx.getString(R.string.service_starting)) private var notificationContent = appCtx.getString(R.string.service_starting) private val networkChangedListener by lazy { NetworkChangedListener(this) @@ -77,14 +78,14 @@ class WebService : BaseService() { networkChangedListener.register() networkChangedListener.onNetworkChanged = { val addressList = NetworkUtils.getLocalIPAddress() + notificationList.clear() if (addressList.any()) { - val hostList = addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) } - hostAddress = hostList.first() - notificationContent = hostList.joinToString(separator = "\n") + notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }) + hostAddress = notificationList.first() startForegroundNotification() } else { hostAddress = getString(R.string.network_connection_unavailable) - notificationContent = hostAddress + notificationList.add(hostAddress) startForegroundNotification() } postEvent(EventBus.WEB_SERVICE, hostAddress) @@ -139,9 +140,9 @@ class WebService : BaseService() { try { httpServer?.start() webSocketServer?.start(1000 * 30) // 通信超时设置 - val hostList = addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) } - hostAddress = hostList.first() - notificationContent = hostList.joinToString(separator = "\n") + notificationList.clear() + notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }) + hostAddress = notificationList.first() isRun = true postEvent(EventBus.WEB_SERVICE, hostAddress) startForegroundNotification() @@ -172,7 +173,7 @@ class WebService : BaseService() { .setSmallIcon(R.drawable.ic_web_service_noti) .setOngoing(true) .setContentTitle(getString(R.string.web_service)) - .setContentText(notificationContent) + .setContentText(notificationList.joinToString("\n")) .setContentIntent( servicePendingIntent("copyHostAddress") )