Skip to content

Commit 5bcd6ba

Browse files
committed
Refactor service retrieval to use ApplicationManager for improved consistency
1 parent b803c9d commit 5bcd6ba

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/main/kotlin/com/github/cnrture/quickprojectwizard/recipes/ComposeProjectRecipe.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import com.github.cnrture.quickprojectwizard.gradle.getGradleKts
3737
import com.github.cnrture.quickprojectwizard.gradle.getProjectGradleKts
3838
import com.github.cnrture.quickprojectwizard.toolwindow.data.SettingsService
3939
import com.github.cnrture.quickprojectwizard.util.NotificationUtil
40-
import com.intellij.openapi.components.ServiceManager.getService
40+
import com.intellij.openapi.application.ApplicationManager
41+
import com.intellij.openapi.components.service
4142
import java.io.File
4243

4344
fun RecipeExecutor.composeProjectRecipe(
@@ -59,7 +60,7 @@ fun RecipeExecutor.composeProjectRecipe(
5960
) {
6061
val packagePath = escapeKotlinIdentifier(packageName)
6162

62-
val settings = getService(SettingsService::class.java)
63+
val settings = ApplicationManager.getApplication().service<SettingsService>()
6364
settings.loadState(
6465
settings.state.copy(
6566
isHiltEnable = isHiltEnable,

src/main/kotlin/com/github/cnrture/quickprojectwizard/recipes/XMLProjectRecipe.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import com.github.cnrture.quickprojectwizard.toolwindow.data.SettingsService
2626
import com.github.cnrture.quickprojectwizard.util.NotificationUtil
2727
import com.github.cnrture.quickprojectwizard.xmlarch.common.emptyCollectExtension
2828
import com.github.cnrture.quickprojectwizard.xmlarch.ui.*
29-
import com.intellij.openapi.components.ServiceManager.getService
29+
import com.intellij.openapi.application.ApplicationManager
30+
import com.intellij.openapi.components.service
3031
import java.io.File
3132

3233
fun RecipeExecutor.xmlProjectRecipe(
@@ -48,7 +49,7 @@ fun RecipeExecutor.xmlProjectRecipe(
4849
) {
4950
val packagePath = escapeKotlinIdentifier(packageName)
5051

51-
val settings = getService(SettingsService::class.java)
52+
val settings = ApplicationManager.getApplication().service<SettingsService>()
5253
settings.loadState(
5354
settings.state.copy(
5455
isHiltEnable = isHiltEnable,

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/data/SettingsService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.intellij.openapi.components.Storage
99
name = "QuickProjectWizardSettings",
1010
storages = [Storage("quickProjectWizard.xml")]
1111
)
12-
@Service(Service.Level.PROJECT)
12+
@Service(Service.Level.APP)
1313
class SettingsService : PersistentStateComponent<SettingsState> {
1414
private var myState = SettingsState()
1515

@@ -18,4 +18,4 @@ class SettingsService : PersistentStateComponent<SettingsState> {
1818
override fun loadState(state: SettingsState) {
1919
myState = state
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)