Show plugin installation status in Kotlin Updates settings (KT-23980)

#KT-23980 Fixed
This commit is contained in:
Nikolay Krasko
2018-04-26 18:38:29 +03:00
parent bf82da7584
commit 8bce29df3a
4 changed files with 106 additions and 24 deletions
@@ -221,18 +221,21 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
notification.notify(null)
}
fun installPluginUpdate(update: PluginUpdateStatus.Update,
cancelCallback: () -> Unit = {}) {
fun installPluginUpdate(
update: PluginUpdateStatus.Update,
successCallback: () -> Unit = {}, cancelCallback: () -> Unit = {}, errorCallback: () -> Unit = {}
) {
val descriptor = update.pluginDescriptor
val pluginDownloader = PluginDownloader.createDownloader(descriptor, update.hostToInstallFrom, null)
ProgressManager.getInstance().run(object : Task.Backgroundable(null, "Downloading plugins", true) {
ProgressManager.getInstance().run(object : Task.Backgroundable(
null, "Downloading plugins", true, PluginManagerUISettings.getInstance()
) {
override fun run(indicator: ProgressIndicator) {
var installed = false
var message: String? = null
val prepareResult = try {
pluginDownloader.prepareToInstall(indicator)
}
catch (e: IOException) {
} catch (e: IOException) {
LOG.info(e)
message = e.message
false
@@ -250,8 +253,13 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
}
}
if (!installed) {
notifyNotInstalled(message)
ApplicationManager.getApplication().invokeLater {
if (!installed) {
errorCallback()
notifyNotInstalled(message)
} else {
successCallback()
}
}
}
@@ -263,20 +271,18 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
private fun notifyNotInstalled(message: String?) {
val fullMessage = message?.let { ": $it" } ?: ""
ApplicationManager.getApplication().invokeLater {
val notification = notificationGroup.createNotification(
"Kotlin",
"Plugin update was not installed$fullMessage. <a href=\"#\">See the log for more information</a>",
NotificationType.INFORMATION) { notification, event ->
val notification = notificationGroup.createNotification(
"Kotlin",
"Plugin update was not installed$fullMessage. <a href=\"#\">See the log for more information</a>",
NotificationType.INFORMATION
) { notification, _ ->
val logFile = File(PathManager.getLogPath(), "idea.log")
ShowFilePathAction.openFile(logFile)
val logFile = File(PathManager.getLogPath(), "idea.log")
ShowFilePathAction.openFile(logFile)
notification.expire()
}
notification.notify(null)
notification.expire()
}
notification.notify(null)
}
override fun dispose() {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.configuration
import com.intellij.ide.IdeBundle
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.SearchableConfigurable
import com.intellij.openapi.updateSettings.impl.UpdateSettings
@@ -43,6 +44,11 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
private val form = ConfigurePluginUpdatesForm()
private var update: PluginUpdateStatus.Update? = null
private var versionForInstallation: String? = null
private var installedVersion: String? = null
private var installingStatus: String? = null
override fun getId(): String = ID
override fun getDisplayName(): String = "Kotlin Updates"
@@ -53,6 +59,11 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
// Selected channel is now saved automatically
}
private fun setInstalledVersion(installedVersion: String?, installingStatus: String?) {
this.installedVersion = installedVersion
this.installingStatus = installingStatus
}
override fun createComponent(): JComponent? {
form.updateCheckProgressIcon.suspend()
form.updateCheckProgressIcon.setPaintPassiveIcon(false)
@@ -64,7 +75,36 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
form.installButton.isVisible = false
form.installButton.addActionListener {
update?.let {
KotlinPluginUpdater.getInstance().installPluginUpdate(it)
form.hideInstallButton()
setInstalledVersion(it.pluginDescriptor.version, "Installing...")
form.installStatusLabel.text = installingStatus
KotlinPluginUpdater.getInstance().installPluginUpdate(
it,
successCallback = {
setInstalledVersion(it.pluginDescriptor.version, IdeBundle.message("plugin.manager.installed.tooltip"))
if (versionForInstallation == it.pluginDescriptor.version) {
form.installStatusLabel.text = installingStatus
}
},
cancelCallback = {
if (versionForInstallation == it.pluginDescriptor.version) {
form.installStatusLabel.text = ""
form.showInstallButton()
setInstalledVersion(null, null)
}
},
errorCallback = {
if (versionForInstallation == it.pluginDescriptor.version) {
form.installStatusLabel.text = "Installation failed"
form.showInstallButton()
setInstalledVersion(null, null)
}
}
)
}
}
@@ -99,7 +139,13 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
is PluginUpdateStatus.Update -> {
update = pluginUpdateStatus
versionForInstallation = update?.pluginDescriptor?.version
form.setUpdateStatus("A new version ${pluginUpdateStatus.pluginDescriptor.version} is available", true)
if (installedVersion != null && installedVersion == versionForInstallation) {
// Installation of the plugin has been started or finished
form.hideInstallButton()
form.installStatusLabel.text = installingStatus
}
}
is PluginUpdateStatus.CheckFailed ->
@@ -22,7 +22,7 @@
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="2505b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="2505b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -40,7 +40,7 @@
</component>
</children>
</grid>
<grid id="b171" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<grid id="b171" layout-manager="FlowLayout" hgap="-1" vgap="5" flow-align="0">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
@@ -51,11 +51,24 @@
<constraints/>
<properties>
<actionCommand value="Install"/>
<label value="Install..."/>
<text value="&amp;Install..."/>
<label value="Install"/>
<text value="&amp;Install"/>
<visible value="true"/>
</properties>
</component>
<grid id="5d5c6" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints/>
<properties/>
<border type="none"/>
<children>
<component id="6d2f7" class="javax.swing.JLabel" binding="installStatusLabel">
<constraints/>
<properties>
<text value=" "/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="209b0" layout-manager="FlowLayout" hgap="5" vgap="0" flow-align="0">
@@ -16,6 +16,7 @@ public class ConfigurePluginUpdatesForm {
public AsyncProcessIcon updateCheckProgressIcon;
public JLabel updateStatusLabel;
public JButton installButton;
public JLabel installStatusLabel;
public ConfigurePluginUpdatesForm() {
int size = channelCombo.getModel().getSize();
@@ -36,10 +37,26 @@ public class ConfigurePluginUpdatesForm {
public void resetUpdateStatus() {
updateStatusLabel.setText(" ");
installButton.setVisible(false);
installStatusLabel.setVisible(false);
}
public void setUpdateStatus(String message, boolean showInstallButton) {
installButton.setEnabled(true);
installButton.setVisible(showInstallButton);
updateStatusLabel.setText(message);
installStatusLabel.setVisible(true);
installStatusLabel.setText("");
}
public void showInstallButton() {
installButton.setEnabled(true);
installButton.setVisible(true);
}
public void hideInstallButton() {
installButton.setEnabled(false);
installButton.setVisible(false);
}
}