From 5251a85a0e35673c5ec2f72735aebd160974a826 Mon Sep 17 00:00:00 2001 From: Mischa Date: Tue, 11 Mar 2025 15:41:05 +0100 Subject: [PATCH 1/3] MXTS-0000: update notifications --- build.gradle.kts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 53687ae..033414e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,12 +2,12 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType plugins { id("java") - id("org.jetbrains.kotlin.jvm") version "1.9.25" - id("org.jetbrains.intellij.platform") version "2.2.1" + id("org.jetbrains.kotlin.jvm") version "2.1.10" + id("org.jetbrains.intellij.platform") version "2.3.0" } group = "com.maxxton" -version = "1.0.2" +version = "1.0.3" repositories { mavenCentral() @@ -18,8 +18,6 @@ repositories { } dependencies { - implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:6.8.0.202311291450-r") - intellijPlatform { val version = providers.gradleProperty("platformVersion") create(IntelliJPlatformType.IntellijIdeaCommunity, version) @@ -35,8 +33,11 @@ tasks { sourceCompatibility = "21" targetCompatibility = "21" } + withType { - kotlinOptions.jvmTarget = "21" + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21) + } } patchPluginXml { From e39bf8157508312e1b39819d1637c6f3ead64184 Mon Sep 17 00:00:00 2001 From: Mischa Date: Tue, 11 Mar 2025 16:52:04 +0100 Subject: [PATCH 2/3] MXTS-0000: fix update notifications from showing up too many times and decrease popup time of up-to-date notification --- .../com/maxxton/mold/CodeStyleSyncActivity.kt | 92 ++++++++++++------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt index 1c04d32..9250c28 100644 --- a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt +++ b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt @@ -15,22 +15,30 @@ import java.nio.file.Files import java.nio.file.Path import java.util.stream.Collectors import kotlin.io.path.* +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds + +private const val upToDateNotificationDuration = 1500 class CodeStyleSyncActivity : ProjectActivity { + override suspend fun execute(project: Project) { + println("Syncing code style...") + try { - syncCodeStyle() + syncCodeStyle(project) + println("Code style sync complete") } catch (e: Exception) { printlnError("Failed to sync code style: $e") } } - private fun syncCodeStyle() { + private fun syncCodeStyle(project: Project) { val config = ApplicationManager.getApplication().getService(CodeStyleConfig::class.java) if (config.state.repoUrl.isBlank()) { showNotification( - "Repository URL is not configured. Please set it in Settings | Tools | Mold.", + "Repository URL is not configured. Please set it in Settings -> Tools -> Mold.", NotificationType.ERROR ) return @@ -39,7 +47,6 @@ class CodeStyleSyncActivity : ProjectActivity { val tempDir = Files.createTempDirectory("maxxton-codestyle") try { - // Use config.state.repoUrl instead of hardcoded value val process = ProcessBuilder() .command("git", "clone", "--depth", "1", config.state.repoUrl.trim(), tempDir.toString()) .start() @@ -53,48 +60,60 @@ class CodeStyleSyncActivity : ProjectActivity { throw IllegalStateException("Git clone failed") } - // Get IntelliJ config directory - val configDir = getConfigDir() ?: throw IllegalStateException("Could not find IntelliJ config directory") + updateConfigFiles(tempDir) + } finally { + tempDir.toFile().deleteRecursively() + } + } - // Setup directories - val codestyleDir = configDir.resolve("codestyles").apply { createDirectories() } - val inspectionsDir = configDir.resolve("inspection").apply { createDirectories() } - val optionsDir = configDir.resolve("options").apply { createDirectories() } + private fun updateConfigFiles(tempDir: Path) { + // Get IntelliJ config directory + val configDir = getConfigDir() ?: throw IllegalStateException("Could not find IntelliJ config directory") - // Copy files - var hasChanged = copyIfDifferent( - tempDir.resolve("intellij/MaxxtonCodeStyle.xml"), - codestyleDir.resolve("MaxxtonCodeStyle.xml") - ) + // Setup directories + val codestyleDir = configDir.resolve("codestyles").apply { createDirectories() } + val inspectionsDir = configDir.resolve("inspection").apply { createDirectories() } + val optionsDir = configDir.resolve("options").apply { createDirectories() } - hasChanged = hasChanged || copyIfDifferent( - tempDir.resolve("intellij/MaxxtonInspections.xml"), - inspectionsDir.resolve("MaxxtonInspections.xml") - ) + // Copy files + val changes = mutableListOf() - if (hasChanged) { - showNotification("Updating IDE settings...") - updateCodeStyleSchemes(optionsDir) - updateInspections(optionsDir) - showRestartNotification() - } else { - showNotification("IDE settings are up to date!") - } - } finally { - tempDir.toFile().deleteRecursively() + if (copyIfDifferent(tempDir.resolve("intellij/MaxxtonCodeStyle.xml"), codestyleDir.resolve("MaxxtonCodeStyle.xml"))) { + changes.add("MaxxtonCodeStyle.xml") + } + + if (copyIfDifferent(tempDir.resolve("intellij/MaxxtonInspections.xml"), inspectionsDir.resolve("MaxxtonInspections.xml"))) { + changes.add("MaxxtonInspections.xml") + } + + if (changes.isNotEmpty()) { + updateCodeStyleSchemes(optionsDir) + updateInspections(optionsDir) + showRestartNotification(changes) + } else { + showNotification("IDE Config is up-to-date!", NotificationType.INFORMATION, upToDateNotificationDuration.milliseconds) } } - private fun showNotification(content: String, type: NotificationType = NotificationType.INFORMATION) { + private fun showNotification(content: String, type: NotificationType = NotificationType.INFORMATION, duration: Duration = Duration.ZERO) { ApplicationManager.getApplication().invokeLater { val notification = NotificationGroupManager.getInstance() .getNotificationGroup("Mold") .createNotification(content, type) + notification.notify(null) + + // auto-expire the notification when a duration is specified + if (duration.inWholeMilliseconds > 0) { + ApplicationManager.getApplication().executeOnPooledThread { + Thread.sleep(duration.inWholeMilliseconds) + notification.expire() + } + } } } - private fun showRestartNotification() { + private fun showRestartNotification(changes: List) { ApplicationManager.getApplication().invokeLater { val notification = NotificationGroupManager.getInstance() .getNotificationGroup("Mold") @@ -111,6 +130,15 @@ class CodeStyleSyncActivity : ProjectActivity { } }) + if (changes.isNotEmpty()) { + notification.addAction(object : NotificationAction("View changes") { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + notification.expire() + showNotification("Updated files: ${changes.joinToString(", ")}") + } + }) + } + notification.notify(null) } } @@ -181,4 +209,4 @@ class CodeStyleSyncActivity : ProjectActivity { """.trimIndent() editorFile.writeText(content) } -} \ No newline at end of file +} From f1693cdec5316e7a5e3337d43ee994a6e39b6b4d Mon Sep 17 00:00:00 2001 From: Mischa Date: Wed, 12 Mar 2025 09:45:41 +0100 Subject: [PATCH 3/3] MXTS-0000: remove redundant parameter --- src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt index 9250c28..a166814 100644 --- a/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt +++ b/src/main/kotlin/com/maxxton/mold/CodeStyleSyncActivity.kt @@ -26,14 +26,14 @@ class CodeStyleSyncActivity : ProjectActivity { println("Syncing code style...") try { - syncCodeStyle(project) + syncCodeStyle() println("Code style sync complete") } catch (e: Exception) { printlnError("Failed to sync code style: $e") } } - private fun syncCodeStyle(project: Project) { + private fun syncCodeStyle() { val config = ApplicationManager.getApplication().getService(CodeStyleConfig::class.java) if (config.state.repoUrl.isBlank()) {