mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-19 13:54:45 +08:00
Add console launch options
This commit is contained in:
parent
f60ad8f45e
commit
335dff170d
@ -33,6 +33,7 @@ import net.mamoe.mirai.console.logging.LoggerController
|
||||
import net.mamoe.mirai.console.plugin.Plugin
|
||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader
|
||||
import net.mamoe.mirai.console.plugin.loader.PluginLoader
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInput
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.utils.BotConfiguration
|
||||
@ -330,6 +331,25 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
public val backendAccess: BackendAccess
|
||||
get() = backendAccessInstance
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ConsoleLaunchOptions
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Console 启动参数, 修改参数会改变默认行为
|
||||
* @since 2.10.0-RC
|
||||
*/
|
||||
@ConsoleExperimentalApi
|
||||
public class ConsoleLaunchOptions {
|
||||
@JvmField
|
||||
public var crashWhenPluginLoadFailed: Boolean = false
|
||||
}
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
public val consoleLaunchOptions: ConsoleLaunchOptions
|
||||
get() = ConsoleLaunchOptions()
|
||||
|
||||
public companion object {
|
||||
private val backendAccessInstance = object : BackendAccess {
|
||||
override val globalComponentStorage: ComponentStorage get() = GlobalComponentStorage
|
||||
@ -339,6 +359,10 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
@Volatile
|
||||
internal var instance: MiraiConsoleImplementation? = null
|
||||
internal val instanceInitialized: Boolean get() = instance != null
|
||||
|
||||
@JvmSynthetic
|
||||
internal var options: ConsoleLaunchOptions = ConsoleLaunchOptions()
|
||||
|
||||
private val initLock = ReentrantLock()
|
||||
|
||||
/**
|
||||
@ -362,6 +386,7 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
"Run MiraiConsole.cancel to kill old instance before starting another instance."
|
||||
)
|
||||
}
|
||||
options = this.consoleLaunchOptions
|
||||
this@Companion.instance = this
|
||||
kotlin.runCatching {
|
||||
MiraiConsoleImplementationBridge.doStart()
|
||||
|
@ -81,6 +81,8 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
|
||||
override val mainLogger: MiraiLogger by lazy { createLogger("main") }
|
||||
|
||||
override val consoleLaunchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions get() = MiraiConsoleImplementation.options
|
||||
|
||||
init {
|
||||
// TODO: Replace to standard api
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
@ -13,9 +13,9 @@ import kotlinx.atomicfu.AtomicLong
|
||||
import kotlinx.atomicfu.locks.withLock
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.data.runCatchingLog
|
||||
import net.mamoe.mirai.console.extension.PluginComponentStorage
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.data.mkdir
|
||||
import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage
|
||||
import net.mamoe.mirai.console.permission.Permission
|
||||
@ -93,7 +93,10 @@ internal abstract class JvmPluginInternal(
|
||||
cancel(CancellationException("plugin disabled"))
|
||||
},
|
||||
onFailure = {
|
||||
cancel(CancellationException("Exception while enabling plugin", it))
|
||||
cancel(CancellationException("Exception while disabling plugin", it))
|
||||
if (MiraiConsoleImplementation.options.crashWhenPluginLoadFailed) {
|
||||
throw it
|
||||
}
|
||||
}
|
||||
)
|
||||
isEnabled = false
|
||||
@ -120,6 +123,9 @@ internal abstract class JvmPluginInternal(
|
||||
onFailure = {
|
||||
cancel(CancellationException("Exception while enabling plugin", it))
|
||||
logger.error(it)
|
||||
if (MiraiConsoleImplementation.options.crashWhenPluginLoadFailed) {
|
||||
throw it
|
||||
}
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
package net.mamoe.mirai.console.terminal
|
||||
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||
@Target(
|
||||
@ -27,6 +29,9 @@ annotation class ConsoleTerminalExperimentalApi
|
||||
|
||||
@ConsoleTerminalExperimentalApi
|
||||
object ConsoleTerminalSettings {
|
||||
@JvmField
|
||||
var launchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions = MiraiConsoleImplementation.ConsoleLaunchOptions()
|
||||
|
||||
@JvmField
|
||||
var setupAnsi: Boolean = System.getProperty("os.name")
|
||||
.lowercase()
|
||||
|
@ -100,6 +100,9 @@ open class MiraiConsoleImplementationTerminal
|
||||
require(isDirectory) { "rootDir $absolutePath is not a directory" }
|
||||
}
|
||||
}
|
||||
|
||||
override val consoleLaunchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions
|
||||
get() = ConsoleTerminalSettings.launchOptions
|
||||
}
|
||||
|
||||
val lineReader: LineReader by lazy {
|
||||
|
Loading…
Reference in New Issue
Block a user