-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how creator finalizers are run
Should help with some weird deadlocks in future IDE versions
- Loading branch information
Showing
3 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Minecraft Development for IntelliJ | ||
* | ||
* https://mcdev.io/ | ||
* | ||
* Copyright (C) 2024 minecraft-dev | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, version 3.0 only. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.demonwav.mcdev.creator.custom | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.diagnostic.thisLogger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.util.application | ||
|
||
@Service | ||
class TemplateService { | ||
|
||
private val pendingActions: MutableMap<String, suspend () -> Unit> = mutableMapOf() | ||
|
||
fun registerFinalizerAction(project: Project, action: suspend () -> Unit) { | ||
if (pendingActions.containsKey(project.name)) { | ||
thisLogger().error("More than one finalizer action registered for project $project") | ||
return | ||
} | ||
|
||
pendingActions[project.locationHash] = action | ||
} | ||
|
||
suspend fun executeFinalizer(project: Project) { | ||
pendingActions.remove(project.locationHash)?.invoke() | ||
} | ||
|
||
companion object { | ||
|
||
val instance: TemplateService | ||
get() = application.service() | ||
} | ||
} | ||
|
||
class TemplateProjectFinalizerActivity : ProjectActivity { | ||
|
||
override suspend fun execute(project: Project) { | ||
TemplateService.instance.executeFinalizer(project) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters