forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version check to IntelliJ Extension (metalbear-co#384)
- Loading branch information
1 parent
8cbf1bd
commit ecc8d86
Showing
6 changed files
with
72 additions
and
3 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
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
62 changes: 62 additions & 0 deletions
62
intellij-ext/src/main/kotlin/com/metalbear/mirrord/VersionCheck.kt
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,62 @@ | ||
package com.metalbear.mirrord | ||
|
||
import com.github.zafarkhaja.semver.Version | ||
import com.intellij.ide.plugins.PluginManagerConfigurable | ||
import com.intellij.ide.plugins.PluginManagerCore | ||
import com.intellij.ide.util.PropertiesComponent | ||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationAction | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.extensions.PluginId | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManagerListener | ||
import java.net.URL | ||
|
||
|
||
class VersionCheck : ProjectManagerListener { | ||
private val pluginId = PluginId.getId("com.metalbear.mirrord") | ||
private val version: String? = PluginManagerCore.getPlugin(pluginId)?.version | ||
private val versionCheckEndpoint: String = | ||
"https://version.mirrord.dev/get-latest-version?source=3&version=$version" | ||
private var versionCheckDisabled | ||
get() = PropertiesComponent.getInstance().getBoolean("versionCheckDisabled", false) | ||
set(value) { | ||
PropertiesComponent.getInstance().setValue("versionCheckDisabled", value) | ||
} | ||
|
||
override fun projectOpened(project: Project) { | ||
if (!versionCheckDisabled) { | ||
checkVersion(project) | ||
} | ||
super.projectOpened(project) | ||
} | ||
|
||
private fun checkVersion(project: Project) { | ||
val remoteVersion = Version.valueOf(URL(versionCheckEndpoint).readText()) | ||
val localVersion = Version.valueOf(version) | ||
if (localVersion.lessThan(remoteVersion)) { | ||
MirrordEnabler.notifier( | ||
"Your version of mirrord is outdated, you should update.", | ||
NotificationType.INFORMATION | ||
) | ||
.addAction(object : NotificationAction("Update") { | ||
override fun actionPerformed(e: AnActionEvent, notification: Notification) { | ||
try { | ||
PluginManagerConfigurable.showPluginConfigurable(project, listOf(pluginId)) | ||
} catch (e: Exception) { | ||
notification.expire() | ||
} | ||
notification.expire() | ||
} | ||
}) | ||
.addAction(object : NotificationAction("Don't show again") { | ||
override fun actionPerformed(e: AnActionEvent, notification: Notification) { | ||
versionCheckDisabled = true | ||
notification.expire() | ||
} | ||
}).notify(project) | ||
} | ||
return | ||
} | ||
} |
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