action to invoke a manual update check for the Kotlin plugin

This commit is contained in:
Dmitry Jemerov
2015-11-18 15:26:30 +01:00
parent 7decca9df4
commit 084727c991
3 changed files with 45 additions and 3 deletions
+6
View File
@@ -91,6 +91,12 @@
<add-to-group group-id="KotlinToolsGroup"/>
</action>
<action id="KotlinCheckForUpdates" class="org.jetbrains.kotlin.idea.actions.CheckPluginUpdatesAction"
text="Check for Kotlin plugin updates"
description="Check if a new version of the Kotlin plugin is available and prompt to install it">
<add-to-group group-id="KotlinToolsGroup"/>
</action>
<action id="ShowKotlinBytecode" class="org.jetbrains.kotlin.idea.actions.ShowKotlinBytecodeAction"
text="Show Kotlin Bytecode">
<add-to-group group-id="KotlinToolsGroup"/>
@@ -58,18 +58,18 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
}
}
private fun queueUpdateCheck() {
fun queueUpdateCheck(reportNoUpdates: Boolean = false) {
if (ApplicationManager.getApplication().isUnitTestMode) return
ApplicationManager.getApplication().assertIsDispatchThread()
if (!checkQueued) {
checkQueued = true
alarm.addRequest({ updateCheck() }, updateDelay)
alarm.addRequest({ updateCheck(reportNoUpdates) }, updateDelay)
updateDelay *= 2 // exponential backoff
}
}
private fun updateCheck() {
private fun updateCheck(reportNoUpdates: Boolean) {
try {
var (mainRepoUpdateSuccess, latestVersionInRepository) = getPluginVersionFromMainRepository()
var descriptorToInstall: IdeaPluginDescriptor? = null
@@ -101,6 +101,15 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
notifyPluginUpdateAvailable(latestVersionInRepository!!, descriptorToInstall, hostToInstallFrom)
}
}
else if (reportNoUpdates) {
ApplicationManager.getApplication().invokeLater {
val notification = notificationGroup.createNotification(
"Kotlin",
"You have the latest version of the Kotlin plugin",
NotificationType.INFORMATION, null)
notification.notify(null)
}
}
}
else {
ApplicationManager.getApplication().invokeLater { queueUpdateCheck() }
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.actions
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import org.jetbrains.kotlin.idea.KotlinPluginUpdater
class CheckPluginUpdatesAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
KotlinPluginUpdater.getInstance().queueUpdateCheck(true)
}
}