44 lines
1.3 KiB
Kotlin
44 lines
1.3 KiB
Kotlin
package com.harmness.toolwindow
|
|
|
|
import com.intellij.openapi.components.PersistentStateComponent
|
|
import com.intellij.openapi.components.Service
|
|
import com.intellij.openapi.components.ServiceManager
|
|
import com.intellij.openapi.components.State
|
|
import com.intellij.openapi.components.Storage
|
|
import com.intellij.openapi.diagnostic.Logger
|
|
|
|
/**
|
|
* 插件设置:仅保存「浏览器起始地址」。
|
|
*/
|
|
@State(name = "HarmnessToolwindowSettings", storages = [Storage("harmness-toolwindow.xml")])
|
|
@Service(Service.Level.APP)
|
|
class SettingsState : PersistentStateComponent<SettingsState.State> {
|
|
|
|
data class State(
|
|
var startUrl: String = DEFAULT_URL,
|
|
)
|
|
|
|
private var myState = State()
|
|
private val logger = Logger.getInstance(SettingsState::class.java)
|
|
|
|
override fun getState(): State = myState
|
|
|
|
override fun loadState(state: State) {
|
|
myState = state
|
|
logger.info("Loaded settings: ${state.startUrl}")
|
|
}
|
|
|
|
var startUrl: String
|
|
get() = myState.startUrl.ifBlank { DEFAULT_URL }
|
|
set(value) {
|
|
myState = myState.copy(startUrl = value.trim())
|
|
}
|
|
|
|
companion object {
|
|
// 与 DSH Web GUI 默认端口一致
|
|
const val DEFAULT_URL = "http://127.0.0.1:8899"
|
|
|
|
fun getInstance(): SettingsState =
|
|
ServiceManager.getService(SettingsState::class.java)
|
|
}
|
|
} |