Skip to content

Commit 3bdbaaf

Browse files
committed
Try to fix write-unsafe context with old API instead of coroutine
Fixes: MCDEV-3Q
1 parent db39fda commit 3bdbaaf

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

src/main/kotlin/creator/custom/CustomPlatformStep.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CustomPlatformStep(
6767
val creatorUiScope = TemplateService.instance.scope("MinecraftDev Creator UI")
6868
val templateRepos = MinecraftSettings.instance.creatorTemplateRepos
6969

70-
val templateRepoProperty = propertyGraph.property<MinecraftSettings.TemplateRepo>(
70+
val templateRepoProperty = propertyGraph.property(
7171
templateRepos.firstOrNull() ?: MinecraftSettings.TemplateRepo.makeBuiltinRepo()
7272
)
7373
var templateRepo by templateRepoProperty
@@ -79,19 +79,19 @@ class CustomPlatformStep(
7979
lateinit var availableGroupsSegmentedButton: SegmentedButton<String>
8080
lateinit var availableTemplatesSegmentedButton: SegmentedButton<LoadedTemplate>
8181

82-
val selectedGroupProperty = propertyGraph.property<String>("")
82+
val selectedGroupProperty = propertyGraph.property("")
8383
var selectedGroup by selectedGroupProperty
8484
val selectedTemplateProperty = propertyGraph.property<LoadedTemplate>(EmptyLoadedTemplate)
8585
var selectedTemplate by selectedTemplateProperty
8686

87-
val templateProvidersLoadingProperty = propertyGraph.property<Boolean>(true)
87+
val templateProvidersLoadingProperty = propertyGraph.property(true)
8888
val templateProvidersTextProperty = propertyGraph.property("")
8989
val templateProvidersText2Property = propertyGraph.property("")
9090
lateinit var templateProvidersProcessIcon: Cell<AsyncProcessIcon>
9191

92-
val templateLoadingProperty = propertyGraph.property<Boolean>(false)
93-
val templateLoadingTextProperty = propertyGraph.property<String>("")
94-
val templateLoadingText2Property = propertyGraph.property<String>("")
92+
val templateLoadingProperty = propertyGraph.property(false)
93+
val templateLoadingTextProperty = propertyGraph.property("")
94+
val templateLoadingText2Property = propertyGraph.property("")
9595
lateinit var templatePropertiesProcessIcon: Cell<AsyncProcessIcon>
9696
lateinit var noTemplatesAvailable: Cell<JLabel>
9797
var templateLoadingJob: Job? = null

src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ open class RemoteTemplateProvider : TemplateProvider {
144144
return doLoadTemplates(context, repo, remoteRepo.innerPath)
145145
}
146146

147-
protected suspend fun doLoadTemplates(
147+
protected fun doLoadTemplates(
148148
context: WizardContext,
149149
repo: MinecraftSettings.TemplateRepo,
150150
rawInnerPath: String
@@ -267,7 +267,7 @@ open class RemoteTemplateProvider : TemplateProvider {
267267
index: Int,
268268
isSelected: Boolean,
269269
cellHasFocus: Boolean
270-
): Component? {
270+
): Component {
271271
text = value?.displayname?.let(MCDevBundle::invoke) ?: value?.name?.capitalize().toString()
272272
return this
273273
}

src/main/kotlin/creator/custom/providers/TemplateProvider.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ import com.intellij.util.KeyedLazyInstance
4646
import com.intellij.util.xmlb.annotations.Attribute
4747
import java.util.ResourceBundle
4848
import javax.swing.JComponent
49-
import kotlinx.coroutines.Dispatchers
50-
import kotlinx.coroutines.runBlocking
5149

5250
/**
5351
* Extensions responsible for creating a [TemplateDescriptor] based on whatever data it is provided in its configuration
@@ -75,13 +73,12 @@ interface TemplateProvider {
7573

7674
fun getAllKeys() = EP_NAME.extensionList.mapNotNull { it.key }
7775

78-
suspend fun findTemplates(
76+
fun findTemplates(
7977
modalityState: ModalityState,
8078
repoRoot: VirtualFile,
8179
templates: MutableList<VfsLoadedTemplate> = mutableListOf(),
82-
bundle: ResourceBundle? = null
80+
bundle: ResourceBundle? = loadMessagesBundle(modalityState, repoRoot)
8381
): List<VfsLoadedTemplate> {
84-
val bundle = bundle ?: loadMessagesBundle(modalityState, repoRoot)
8582
val templatesToLoad = mutableListOf<VirtualFile>()
8683
val visitor = object : VirtualFileVisitor<Unit>() {
8784
override fun visitFile(file: VirtualFile): Boolean {
@@ -117,7 +114,7 @@ interface TemplateProvider {
117114
return templates
118115
}
119116

120-
suspend fun loadMessagesBundle(modalityState: ModalityState, repoRoot: VirtualFile): ResourceBundle? = try {
117+
fun loadMessagesBundle(modalityState: ModalityState, repoRoot: VirtualFile): ResourceBundle? = try {
121118
val locale = DynamicBundle.getLocale()
122119
// Simplified bundle resolution, but covers all the most common cases
123120
val baseBundle = doLoadMessageBundle(
@@ -144,7 +141,7 @@ interface TemplateProvider {
144141
null
145142
}
146143

147-
private suspend fun doLoadMessageBundle(
144+
private fun doLoadMessageBundle(
148145
file: VirtualFile?,
149146
modalityState: ModalityState,
150147
parent: ResourceBundle?
@@ -167,7 +164,7 @@ interface TemplateProvider {
167164
return parent
168165
}
169166

170-
suspend fun createVfsLoadedTemplate(
167+
fun createVfsLoadedTemplate(
171168
modalityState: ModalityState,
172169
templateRoot: VirtualFile,
173170
descriptorFile: VirtualFile,
@@ -194,7 +191,7 @@ interface TemplateProvider {
194191
descriptor.translateOrNull("platform.${labelKey.lowercase()}.label") ?: descriptor.translate(labelKey)
195192

196193
if (descriptor.inherit != null) {
197-
val parent = templateRoot.findFileByRelativePath(descriptor.inherit!!)
194+
val parent = templateRoot.findFileByRelativePath(descriptor.inherit)
198195
if (parent != null) {
199196
parent.refresh(false, false)
200197
val parentDescriptor = Gson().fromJson<TemplateDescriptor>(parent.readText())
@@ -231,5 +228,5 @@ class TemplateProviderBean : BaseKeyedLazyInstance<TemplateProvider>(), KeyedLaz
231228

232229
override fun getKey(): String = name
233230

234-
override fun getImplementationClassName(): String? = implementation
231+
override fun getImplementationClassName(): String = implementation
235232
}

src/main/kotlin/util/files.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package com.demonwav.mcdev.util
2222

2323
import com.intellij.openapi.application.ApplicationManager
2424
import com.intellij.openapi.application.ModalityState
25-
import com.intellij.openapi.application.writeAction
2625
import com.intellij.openapi.vfs.LocalFileSystem
2726
import com.intellij.openapi.vfs.VfsUtilCore
2827
import com.intellij.openapi.vfs.VirtualFile
@@ -79,15 +78,15 @@ val VirtualFile.mcDomainAndPath: Pair<String, String>?
7978
operator fun Manifest.get(attribute: String): String? = mainAttributes.getValue(attribute)
8079
operator fun Manifest.get(attribute: Attributes.Name): String? = mainAttributes.getValue(attribute)
8180

82-
suspend fun VirtualFile.refreshSync(modalityState: ModalityState): VirtualFile? {
81+
fun VirtualFile.refreshSync(modalityState: ModalityState): VirtualFile? {
8382
fun refresh() {
8483
RefreshQueue.getInstance().refresh(false, this.isDirectory, null, modalityState, this)
8584
}
8685

8786
if (ApplicationManager.getApplication().isWriteAccessAllowed) {
8887
refresh()
8988
} else {
90-
writeAction {
89+
runWriteTask {
9190
refresh()
9291
}
9392
}

0 commit comments

Comments
 (0)