Skip to content

Commit

Permalink
created PluginsHealthCard
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Jan 25, 2024
1 parent 9a44e7d commit cce4372
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
42 changes: 1 addition & 41 deletions src/main/kotlin/com/vk/admstorm/AdmStormStartupActivity.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
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.extensions.PluginId
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.utils.MyUtils.measureTime
import com.vk.admstorm.utils.ServerNameProvider
import com.vk.admstorm.utils.extensions.pluginEnabled

class AdmStormStartupActivity : ProjectActivity {
Expand Down Expand Up @@ -52,8 +46,7 @@ class AdmStormStartupActivity : ProjectActivity {
AdmStartupService.getInstance(project).afterConnectionTasks()
}
}

checkUpdates(project)
PluginsHealthCard(project).checkUpdates()

// Это необходимо чтобы для бенчмарков показывались все пункты в списке
// который открывается при клике на иконку рядом с классом или методом.
Expand All @@ -67,37 +60,4 @@ class AdmStormStartupActivity : ProjectActivity {

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

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

private fun checkUpdates(project: Project) {
val hasAdmNewerVersion = hasNewVersion(AdmService.ADM_PLUGIN_ID)
val hasKphpStormNewVersion = hasNewVersion(AdmService.KPHPSTORM_PLUGIN_ID)
val hasModuliteNewVersion = hasNewVersion(AdmService.MODULITE_PLUGIN_ID)

if (!(hasAdmNewerVersion || hasModuliteNewVersion || hasKphpStormNewVersion)) {
return
}

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

if (hasAdmNewerVersion) {
updateNotification = updateNotification.withActions(
AdmNotification.Action("What's new") { _, _ ->
val url = "https://vkcom.github.io/admstorm/whatsnew.html?server_name=${ServerNameProvider.name()}"
BrowserUtil.browse(url)
}
)
}
updateNotification.show(project)
}
}
49 changes: 49 additions & 0 deletions src/main/kotlin/com/vk/admstorm/PluginsHealthCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.extensions.PluginId
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import com.vk.admstorm.notifications.AdmNotification
import com.vk.admstorm.utils.ServerNameProvider

data class PluginsHealthCard(val project: Project) {
private val admId = AdmService.ADM_PLUGIN_ID
private val kphpId = AdmService.KPHPSTORM_PLUGIN_ID
private val moduliteId = AdmService.MODULITE_PLUGIN_ID

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

fun checkUpdates() {
val hasAdmNewerVersion = hasNewVersion(admId)
val hasKphpStormNewVersion = hasNewVersion(kphpId)
val hasModuliteNewVersion = hasNewVersion(moduliteId)

if (!(hasAdmNewerVersion || hasModuliteNewVersion || hasKphpStormNewVersion)) {
return
}

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

if (hasAdmNewerVersion) {
updateNotification = updateNotification.withActions(
AdmNotification.Action("What's new") { _, _ ->
val url = "https://vkcom.github.io/admstorm/whatsnew.html?server_name=${ServerNameProvider.name()}"
BrowserUtil.browse(url)
}
)
}
updateNotification.show(project)
}
}

0 comments on commit cce4372

Please sign in to comment.