Browse Source

fix: WebService 启动崩溃与关闭卡顿

HapeLee 5 months ago
parent
commit
1021e1086f

+ 3 - 1
app/src/main/java/io/legado/app/service/WebService.kt

@@ -169,7 +169,9 @@ class WebService : BaseService() {
                 postEvent(EventBus.WEB_SERVICE, hostAddress)
                 FlowEventBus.post(EventBus.WEB_SERVICE, hostAddress)
                 startForegroundNotification()
-            } catch (e: IOException) {
+            } catch (e: Exception) {
+                ktorServer?.stop()
+                ktorServer = null
                 toastOnUi(e.localizedMessage ?: "")
                 e.printOnDebug()
                 stopSelf()

+ 2 - 2
app/src/main/java/io/legado/app/web/KtorServer.kt

@@ -165,8 +165,8 @@ class KtorServer(private val port: Int) {
     }
 
     fun stop() {
-        server?.stop(1000, 1000)
-        wsServer?.stop(1000, 1000)
+        server?.stop(0, 0)
+        wsServer?.stop(0, 0)
     }
 
     private suspend fun PipelineContext<Unit, ApplicationCall>.handlePost(