Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: startup lock #2702

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 后端实现
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down