From dd63c37354320f989e06883c679b4a78b921cc91 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Tue, 1 Nov 2022 08:43:52 +0100 Subject: [PATCH] Remove post-update notification --- .../izhangzhihao/rainbow/brackets/Notify.kt | 48 --------- .../brackets/RainbowUpdateNotifyActivity.kt | 97 ------------------- .../brackets/settings/RainbowSettings.kt | 4 +- src/main/resources/META-INF/plugin.xml | 2 - 4 files changed, 1 insertion(+), 150 deletions(-) delete mode 100644 src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/Notify.kt delete mode 100644 src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/RainbowUpdateNotifyActivity.kt diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/Notify.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/Notify.kt deleted file mode 100644 index 71be787..0000000 --- a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/Notify.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.izhangzhihao.rainbow.brackets - -import com.intellij.notification.* -import com.intellij.notification.impl.NotificationsManagerImpl -import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.popup.Balloon -import com.intellij.openapi.wm.WindowManager -import com.intellij.ui.BalloonLayoutData -import com.intellij.ui.awt.RelativePoint -import java.awt.Point - -class ApplicationServicePlaceholder : Disposable { - override fun dispose() = Unit - - companion object { - val INSTANCE: ApplicationServicePlaceholder = ApplicationManager.getApplication().getService(ApplicationServicePlaceholder::class.java) - } -} - -fun createNotification(title: String, content: String, type: NotificationType, - listener: NotificationListener): Notification { - return NotificationGroupManager.getInstance().getNotificationGroup("Rainbow Brackets Notification Group") - .createNotification(title, content, type).setListener(listener) -} - -fun showFullNotification(project: Project, notification: Notification) { - val frame = WindowManager.getInstance().getIdeFrame(project) - if (frame == null) { - notification.notify(project) - return - } - val bounds = frame.component.bounds - val target = RelativePoint(frame.component, Point(bounds.x + bounds.width, 20)) - - try { - val balloon = NotificationsManagerImpl.createBalloon(frame, - notification, - true, // showCallout - true, // hideOnClickOutside - BalloonLayoutData.fullContent(), - ApplicationServicePlaceholder.INSTANCE) - balloon.show(target, Balloon.Position.atLeft) - } catch (e: Exception) { - notification.notify(project) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/RainbowUpdateNotifyActivity.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/RainbowUpdateNotifyActivity.kt deleted file mode 100644 index 572b089..0000000 --- a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/RainbowUpdateNotifyActivity.kt +++ /dev/null @@ -1,97 +0,0 @@ -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.PluginManagerCore -import com.intellij.ide.plugins.PluginManagerCore.isPluginInstalled -import com.intellij.ide.startup.StartupActionScriptManager -import com.intellij.ide.startup.StartupActionScriptManager.DeleteCommand -import com.intellij.notification.NotificationListener.UrlOpeningListener -import com.intellij.notification.NotificationType -import com.intellij.openapi.extensions.PluginId -import com.intellij.openapi.project.Project -import com.intellij.openapi.startup.StartupActivity - - -class RainbowUpdateNotifyActivity : StartupActivity { - - override fun runActivity(project: Project) { - removeIfInstalled() - val settings = RainbowSettings.instance - if (getPlugin()?.version != settings.version) { - settings.version = getPlugin()!!.version - if (settings.showNotificationOnUpdate) { - showUpdate(project) - } - } - } - - private fun removeIfInstalled() { - val pluginId = PluginId.getId("com.github.jadepeng.rainbowfart") - val isInstalled = isPluginInstalled(pluginId) - if (isInstalled) { - val pluginDescriptor = PluginManagerCore.getPlugin(pluginId) - if (pluginDescriptor != null) { - //disablePlugin(pluginId) - StartupActionScriptManager.addActionCommand(DeleteCommand(pluginDescriptor.pluginPath)) - } - } - } - - companion object { - const val pluginId = "izhangzhihao.rainbow.brackets" - - - private val updateContent: String by lazy { - //language=HTML - """ - <br/> - 🌈Thank you for downloading <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets">Rainbow Brackets</a></b>!<br> - 🎉Sponsored by <a href="https://codestream.com/?utm_source=jbmarket&utm_medium=banner&utm_campaign=jbrainbowbrackets">CodeStream</a>.<br> - 👍If you find this plugin helpful, <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets#support-us">please support us!</a>.</b><br> - <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets#support-us">Donate</a></b> by <b><a href="https://opencollective.com/intellij-rainbow-brackets">OpenCollective</a></b> Or AliPay/WeChatPay to <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets#sponsors">become a sponsor</a>!.</b><br> - 📝Check out <b><a href="https://izhangzhihao.github.io/rainbow-brackets-document/">the document</a></b> for all features of this plugin.<br> - 🐛If you run into any problem, <b><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets/issues">feel free to raise an issue</a>.</b><br> - 🆕See <b><a href="${changelog()}">changelog</a></b> for more details about this update.<br> - 👉Want to customize your own color scheme of Rainbow Brackets? Edit it under - <b>Settings > Editor > Color Scheme > Rainbow Brackets</b><br> - 👉Tired of the bundled colors? Try out the new color generator! - <b>Settings > Other Settings > Rainbow Brackets > Use color generator</b><br> - 👉Other additional features under - <b>Settings > Other Settings > Rainbow Brackets</b><br/> - Enjoy your colorful code🌈. - """ - } - - private fun changelog(): String { - val plugin = getPlugin() - return if (plugin == null) { - """https://github.com/izhangzhihao/intellij-rainbow-brackets/releases""" - } else { - """https://github.com/izhangzhihao/intellij-rainbow-brackets/releases/tag/${plugin.version}""" - } - - } - - fun getPlugin(): IdeaPluginDescriptor? = PluginManagerCore.getPlugin(PluginId.getId(pluginId)) - - private fun updateMsg(): String { - val plugin = getPlugin() - return if (plugin == null) { - "Rainbow Brackets installed." - } else { - "Rainbow Brackets updated to ${plugin.version}" - } - } - - private fun showUpdate(project: Project) { - val notification = createNotification( - updateMsg(), - updateContent, - NotificationType.INFORMATION, - UrlOpeningListener(false) - ) - showFullNotification(project, notification) - } - } -} diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/settings/RainbowSettings.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/settings/RainbowSettings.kt index 86c3c60..5db05af 100644 --- a/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/settings/RainbowSettings.kt +++ b/src/main/kotlin/com/github/izhangzhihao/rainbow/brackets/settings/RainbowSettings.kt @@ -21,7 +21,6 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> { var isShowRainbowIndentGuides = true var isDoNOTRainbowifyBracketsWithoutContent = false var isDoNOTRainbowifyTheFirstLevel = false - var version = "Unknown" var isRainbowifyHTMLInsideJS = true var isRainbowifyKotlinLabel = true var isRainbowifyKotlinFunctionLiteralBracesAndArrow = true @@ -36,7 +35,6 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> { var disableRainbowIndentsInZenMode = true var useColorGenerator = false var customColorGeneratorOption: String? = null - var showNotificationOnUpdate = true var rainbowifyTagNameInXML = false var doNOTRainbowifyTemplateString = false var doNOTRainbowifyBigFiles = true @@ -60,4 +58,4 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> { val instance: RainbowSettings get() = ApplicationManager.getApplication().getService(RainbowSettings::class.java) } -} \ No newline at end of file +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 25f9aaa..3e62e74 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -772,10 +772,8 @@ <additionalTextAttributes scheme="Default" file="colorSchemes/rainbow-color-default.xml"/> <additionalTextAttributes scheme="Darcula" file="colorSchemes/rainbow-color-default-darcula.xml"/> - <postStartupActivity implementation="com.github.izhangzhihao.rainbow.brackets.RainbowUpdateNotifyActivity"/> <!--<errorHandler implementation="com.github.izhangzhihao.rainbow.brackets.util.GitHubErrorReporter"/>--> <highlightingPassFactory implementation="com.github.izhangzhihao.rainbow.brackets.indents.RainbowIndentsPassFactory"/> - <applicationService serviceImplementation="com.github.izhangzhihao.rainbow.brackets.ApplicationServicePlaceholder" id="ApplicationServicePlaceholder"/> <editorNotificationProvider implementation="com.github.izhangzhihao.rainbow.brackets.RainbowifyBanner"/> <notificationGroup id="Rainbow Brackets Notification Group" displayType="STICKY_BALLOON"/> </extensions>