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

This commit is contained in:
HapeLee
2026-06-06 01:28:20 +08:00
parent e6dcc7229f
commit 1021e1086f
2 changed files with 5 additions and 3 deletions
@@ -169,7 +169,9 @@ class WebService : BaseService() {
postEvent(EventBus.WEB_SERVICE, hostAddress) postEvent(EventBus.WEB_SERVICE, hostAddress)
FlowEventBus.post(EventBus.WEB_SERVICE, hostAddress) FlowEventBus.post(EventBus.WEB_SERVICE, hostAddress)
startForegroundNotification() startForegroundNotification()
} catch (e: IOException) { } catch (e: Exception) {
ktorServer?.stop()
ktorServer = null
toastOnUi(e.localizedMessage ?: "") toastOnUi(e.localizedMessage ?: "")
e.printOnDebug() e.printOnDebug()
stopSelf() stopSelf()
@@ -165,8 +165,8 @@ class KtorServer(private val port: Int) {
} }
fun stop() { fun stop() {
server?.stop(1000, 1000) server?.stop(0, 0)
wsServer?.stop(1000, 1000) wsServer?.stop(0, 0)
} }
private suspend fun PipelineContext<Unit, ApplicationCall>.handlePost( private suspend fun PipelineContext<Unit, ApplicationCall>.handlePost(