mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 10:14:42 +08:00
[console] Process signals later if console not yet initialized; Ignore window resized signal
This commit is contained in:
parent
1f8524fb04
commit
48143d7b3c
@ -198,6 +198,26 @@ private fun initSignalHandler(): (String) -> Unit {
|
||||
val shutdownMonitorLock = AtomicBoolean(false)
|
||||
val lastSignalTimestamp = AtomicLong(0)
|
||||
return handler@{ signalName ->
|
||||
if (signalName == "WINCH") {
|
||||
// Windows CMD.exe resized
|
||||
return@handler
|
||||
}
|
||||
runCatching {
|
||||
MiraiConsole.mainLogger
|
||||
}.onFailure { // mirai-console not yet initialized
|
||||
System.err.println("[TERMINAL] [WARNING] Received signal $signalName")
|
||||
System.err.println("[TERMINAL] [WARNING] This signal will be processed later because mirai-console not yet initialized.")
|
||||
|
||||
// Try later
|
||||
if (signalName in shutdownSignals) {
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
GlobalScope.launch {
|
||||
delay(500L)
|
||||
signalHandler(signalName)
|
||||
}
|
||||
}
|
||||
return@handler
|
||||
}
|
||||
// JLine may process other signals
|
||||
MiraiConsole.mainLogger.verbose { "Received signal $signalName" }
|
||||
if (signalName !in shutdownSignals) return@handler
|
||||
|
Loading…
Reference in New Issue
Block a user