1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2025-01-10 13:42:44 +01:00

Show update notification after plugin updated

This commit is contained in:
张志豪 2018-03-18 16:12:59 +08:00
parent e76d999899
commit b33d7b8dfd
5 changed files with 90 additions and 0 deletions
src/main
kotlin/com/github/izhangzhihao/rainbow/brackets
resources/META-INF

View File

@ -0,0 +1,16 @@
package com.github.izhangzhihao.rainbow.brackets
import com.intellij.notification.*
import com.intellij.openapi.project.Project
fun show(project: Project, title: String, content: String,
displayId: String, type: NotificationType,
listener: NotificationListener) {
val group = NotificationGroup(
displayId,
NotificationDisplayType.STICKY_BALLOON,
true
)
val notification = group.createNotification(title, content, type, listener)
Notifications.Bus.notify(notification, project)
}

View File

@ -0,0 +1,27 @@
package com.github.izhangzhihao.rainbow.brackets
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
import com.intellij.ide.plugins.IdeaPluginDescriptor
import com.intellij.ide.plugins.PluginManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ApplicationComponent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.extensions.PluginId
class RainbowComponent : ApplicationComponent {
var updated: Boolean = false
override fun initComponent() {
updated = Companion.getPlugin()?.version != RainbowSettings.instance.version
if (updated) {
RainbowSettings.instance.version = Companion.getPlugin()?.version
}
}
companion object {
val instance: RainbowComponent
get() = ApplicationManager.getApplication().getComponent(RainbowComponent::class.java)
private fun getPlugin(): IdeaPluginDescriptor? = PluginManager.getPlugin(PluginId.getId("izhangzhihao.rainbow.brackets"))
}
}

View File

@ -0,0 +1,40 @@
package com.github.izhangzhihao.rainbow.brackets
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
import com.intellij.notification.*
import com.intellij.openapi.components.AbstractProjectComponent
import com.intellij.openapi.project.Project
class RainbowUpdateComponent(project: Project) : AbstractProjectComponent(project) {
private val applicationComponent = RainbowComponent.instance
override fun projectOpened() {
if (applicationComponent.updated) {
Companion.showUpdate(myProject)
applicationComponent.updated = false
}
}
companion object {
private var channel = "izhangzhihao.rainbow.brackets"
private const val updateContent = """
<br/>
Thank you for downloading <b>Rainbow Brackets</b>!<br>
If you find my plugin helpful, <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets">Please give me a star on github</a></b><br/>
If you find any issue, <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets/issues">Please feel free to raise a issue</a></b><br/>
See <b><a href="http://plugins.jetbrains.com/plugin/10080-rainbow-brackets">Changelog</a></b> for more details.
"""
private fun showUpdate(project: Project) {
show(
project,
"Rainbow Brackets updated to ${RainbowSettings.instance.version}",
Companion.updateContent,
Companion.channel + "_UPDATE",
NotificationType.INFORMATION,
NotificationListener.URL_OPENING_LISTENER
)
}
}
}

View File

@ -19,6 +19,7 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> {
var isEnableRainbowSquareBrackets = true
var isEnableRainbowAngleBrackets = true
var isDoNOTRainbowifyBracketsWithoutContent = false
var version: String? = null
@Nullable
override fun getState() = this

View File

@ -152,10 +152,16 @@
<application-components>
<!-- Add your application components here -->
<component>
<implementation-class>com.github.izhangzhihao.rainbow.brackets.RainbowComponent</implementation-class>
</component>
</application-components>
<project-components>
<!-- Add your project components here -->
<component>
<implementation-class>com.github.izhangzhihao.rainbow.brackets.RainbowUpdateComponent</implementation-class>
</component>
</project-components>
<actions>