Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notifications about new versions of plugins #207

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package com.vk.admstorm

import com.intellij.ide.BrowserUtil
import com.intellij.ide.plugins.InstalledPluginsState
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.fileTypes.ex.FileTypeChooser
import com.intellij.openapi.fileTypes.impl.AbstractFileType
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.util.registry.Registry
import com.vk.admstorm.diagnostic.AdmStormLoggerFactory
import com.vk.admstorm.highlight.CppTypeHighlightPatcher
import com.vk.admstorm.notifications.AdmNotification
import com.vk.admstorm.services.SentryService
import com.vk.admstorm.settings.AdmStormSettingsState
import com.vk.admstorm.ssh.SshConnectionService
import com.vk.admstorm.startup.ChangeSshBackendStartup
import com.vk.admstorm.startup.PluginsUpdateStartup
import com.vk.admstorm.utils.MyUtils.measureTime
import com.vk.admstorm.utils.ServerNameProvider
import com.vk.admstorm.utils.extensions.pluginEnabled

class AdmStormStartupActivity : ProjectActivity {
Expand All @@ -43,7 +39,7 @@ class AdmStormStartupActivity : ProjectActivity {
}

ChangeSshBackendStartup.changeConfigurationProcess(project)
checkUpdates(project)
PluginsUpdateStartup.checkUpdates(project)

measureTime(LOG, "patch cpp highlight") {
val cppType = FileTypeChooser.getKnownFileTypeOrAssociate(".c") as AbstractFileType
Expand All @@ -68,27 +64,4 @@ class AdmStormStartupActivity : ProjectActivity {

Logger.setFactory(AdmStormLoggerFactory(sentry, defaultLoggerFactory))
}

private fun checkUpdates(project: Project) {
val hasNewerVersion = InstalledPluginsState.getInstance().hasNewerVersion(AdmService.PLUGIN_ID)
if (!hasNewerVersion) {
return
}

AdmNotification("New version of the plugin is available")
.withActions(
AdmNotification.Action("Update") { _, _ ->
invokeLater {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Plugins")
}
}
)
.withActions(
AdmNotification.Action("What's new") { _, _ ->
val url = "https://vkcom.github.io/admstorm/whatsnew.html?server_name=${ServerNameProvider.name()}"
BrowserUtil.browse(url)
}
)
.show(project)
}
}
55 changes: 55 additions & 0 deletions src/main/kotlin/com/vk/admstorm/startup/PluginsUpdateStartup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.vk.admstorm.startup

import com.intellij.ide.BrowserUtil
import com.intellij.ide.plugins.InstalledPluginsState
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import com.vk.admstorm.AdmService
import com.vk.admstorm.notifications.AdmNotification
import com.intellij.openapi.application.invokeLater
import com.vk.admstorm.utils.ServerNameProvider

object PluginsUpdateStartup {
private val KPHPSTORM_PLUGIN_ID = PluginId.getId("com.vk.kphpstorm")
private val MODULITE_PLUGIN_ID = PluginId.getId("com.vk.modulite")
private val ADMSTORM_PLUGIN_ID = AdmService.PLUGIN_ID

private val PLUGINS = mapOf(
ADMSTORM_PLUGIN_ID to "https://vkcom.github.io/admstorm/whatsnew.html?server_name=${ServerNameProvider.name()}",
KPHPSTORM_PLUGIN_ID to null,
MODULITE_PLUGIN_ID to null,
)

private fun hasNewVersion(pluginId: PluginId): Boolean {
return InstalledPluginsState.getInstance().hasNewerVersion(pluginId)
}

fun checkUpdates(project: Project) {
for ((pluginID, changelogURL) in PLUGINS) {
if (!hasNewVersion(pluginID)) {
return
}

val updateNotification = AdmNotification("New version of the plugin is available")
.withActions(
AdmNotification.Action("Update") { _, _ ->
invokeLater {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Plugins")
}
}
)

if (changelogURL == null) {
updateNotification.show()
return
}

updateNotification.withActions(
AdmNotification.Action("What's new") { _, _ ->
BrowserUtil.browse(changelogURL)
}
).show(project)
}
}
}
Loading