mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-24 20:43:33 +08:00
feat: startup lock
This commit is contained in:
parent
545e5bb310
commit
92c16cae2b
@ -58,6 +58,8 @@ import org.jline.terminal.TerminalBuilder
|
||||
import org.jline.terminal.impl.AbstractWindowsTerminal
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.outputStream
|
||||
|
||||
/**
|
||||
* mirai-console-terminal 后端实现
|
||||
@ -131,6 +133,10 @@ open class MiraiConsoleImplementationTerminal
|
||||
get() = ConsoleTerminalSettings.launchOptions
|
||||
|
||||
override fun preStart() {
|
||||
|
||||
val lock = rootPath.resolve("startup.properties")
|
||||
if (lock.exists()) throw RuntimeException("已有其他实例启动,或者上次启动后没有正常关闭 Mirai Console")
|
||||
|
||||
registerSignalHandler()
|
||||
|
||||
JLineInputDaemon.terminal0 = this
|
||||
@ -145,6 +151,16 @@ open class MiraiConsoleImplementationTerminal
|
||||
}
|
||||
}
|
||||
|
||||
override fun postStart() {
|
||||
launch(CoroutineName("Mirai Console Terminal Startup Lock")) {
|
||||
val lock = rootPath.resolve("startup.properties")
|
||||
lock.outputStream().use { output ->
|
||||
System.getProperties().store(output, "startup lock")
|
||||
}
|
||||
lock.toFile().deleteOnExit()
|
||||
}
|
||||
}
|
||||
|
||||
override fun createNewProcessProgress(): ProcessProgress {
|
||||
if (terminal is NoConsole) return super.createNewProcessProgress()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user