Skip to content

Commit 064b6c1

Browse files
committed
refactor(settings): implement Service annotation and refactor ZonedDateTimeConverter
Implement the Service annotation at the class level to ensure proper registration and management of the settings state service. Additionally, refactor the ZonedDateTimeConverter to be a top-level class for better organization and readability.
1 parent 3daabed commit 064b6c1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cc.unitmesh.devti.settings
22

33
import com.intellij.openapi.application.ApplicationManager
44
import com.intellij.openapi.components.PersistentStateComponent
5+
import com.intellij.openapi.components.Service
56
import com.intellij.openapi.components.State
67
import com.intellij.openapi.components.Storage
78
import com.intellij.util.xmlb.Converter
@@ -10,6 +11,7 @@ import com.intellij.util.xmlb.annotations.OptionTag
1011
import java.time.ZonedDateTime
1112
import java.time.format.DateTimeFormatter
1213

14+
@Service(Service.Level.APP)
1315
@State(name = "cc.unitmesh.devti.settings.DevtiSettingsState", storages = [Storage("DevtiSettings.xml")])
1416
class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
1517
var gitType = DEFAULT_GIT_TYPE
@@ -69,19 +71,16 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
6971
val maxTokenLength: Int get() = getInstance().fetchMaxTokenLength()
7072
val language: String get() = getInstance().fetchLocalLanguage()
7173

72-
var lastCheckTime: ZonedDateTime? = getInstance().lastCheck
73-
7474
fun getInstance(): AutoDevSettingsState {
7575
return ApplicationManager.getApplication().getService(AutoDevSettingsState::class.java).state
7676
}
77+
}
78+
}
7779

78-
class ZonedDateTimeConverter : Converter<ZonedDateTime>() {
79-
override fun toString(value: ZonedDateTime): String? = value.format(DateTimeFormatter.ISO_ZONED_DATE_TIME)
80+
class ZonedDateTimeConverter : Converter<ZonedDateTime>() {
81+
override fun toString(value: ZonedDateTime): String? = value.format(DateTimeFormatter.ISO_ZONED_DATE_TIME)
8082

81-
override fun fromString(value: String): ZonedDateTime? {
82-
return ZonedDateTime.parse(value, DateTimeFormatter.ISO_ZONED_DATE_TIME)
83-
}
84-
}
83+
override fun fromString(value: String): ZonedDateTime? {
84+
return ZonedDateTime.parse(value, DateTimeFormatter.ISO_ZONED_DATE_TIME)
8585
}
86-
8786
}

0 commit comments

Comments
 (0)