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) notification.notify(null)
} }
fun installPluginUpdate(update: PluginUpdateStatus.Update, fun installPluginUpdate(
cancelCallback: () -> Unit = {}) { update: PluginUpdateStatus.Update,
successCallback: () -> Unit = {}, cancelCallback: () -> Unit = {}, errorCallback: () -> Unit = {}
) {
val descriptor = update.pluginDescriptor val descriptor = update.pluginDescriptor
val pluginDownloader = PluginDownloader.createDownloader(descriptor, update.hostToInstallFrom, null) 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) { override fun run(indicator: ProgressIndicator) {
var installed = false var installed = false
var message: String? = null var message: String? = null
val prepareResult = try { val prepareResult = try {
pluginDownloader.prepareToInstall(indicator) pluginDownloader.prepareToInstall(indicator)
} } catch (e: IOException) {
catch (e: IOException) {
LOG.info(e) LOG.info(e)
message = e.message message = e.message
false false
@@ -250,8 +253,13 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
} }
} }
if (!installed) { ApplicationManager.getApplication().invokeLater {
notifyNotInstalled(message) if (!installed) {
errorCallback()
notifyNotInstalled(message)
} else {
successCallback()
}
} }
} }
@@ -263,20 +271,18 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
private fun notifyNotInstalled(message: String?) { private fun notifyNotInstalled(message: String?) {
val fullMessage = message?.let { ": $it" } ?: "" val fullMessage = message?.let { ": $it" } ?: ""
ApplicationManager.getApplication().invokeLater { val notification = notificationGroup.createNotification(
val notification = notificationGroup.createNotification( "Kotlin",
"Kotlin", "Plugin update was not installed$fullMessage. <a href=\"#\">See the log for more information</a>",
"Plugin update was not installed$fullMessage. <a href=\"#\">See the log for more information</a>", NotificationType.INFORMATION
NotificationType.INFORMATION) { notification, event -> ) { notification, _ ->
val logFile = File(PathManager.getLogPath(), "idea.log")
ShowFilePathAction.openFile(logFile)
val logFile = File(PathManager.getLogPath(), "idea.log") notification.expire()
ShowFilePathAction.openFile(logFile)
notification.expire()
}
notification.notify(null)
} }
notification.notify(null)
} }
override fun dispose() { override fun dispose() {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.configuration package org.jetbrains.kotlin.idea.configuration
import com.intellij.ide.IdeBundle
import com.intellij.openapi.options.Configurable import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.SearchableConfigurable import com.intellij.openapi.options.SearchableConfigurable
import com.intellij.openapi.updateSettings.impl.UpdateSettings import com.intellij.openapi.updateSettings.impl.UpdateSettings
@@ -43,6 +44,11 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
private val form = ConfigurePluginUpdatesForm() private val form = ConfigurePluginUpdatesForm()
private var update: PluginUpdateStatus.Update? = null 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 getId(): String = ID
override fun getDisplayName(): String = "Kotlin Updates" override fun getDisplayName(): String = "Kotlin Updates"
@@ -53,6 +59,11 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
// Selected channel is now saved automatically // Selected channel is now saved automatically
} }
private fun setInstalledVersion(installedVersion: String?, installingStatus: String?) {
this.installedVersion = installedVersion
this.installingStatus = installingStatus
}
override fun createComponent(): JComponent? { override fun createComponent(): JComponent? {
form.updateCheckProgressIcon.suspend() form.updateCheckProgressIcon.suspend()
form.updateCheckProgressIcon.setPaintPassiveIcon(false) form.updateCheckProgressIcon.setPaintPassiveIcon(false)
@@ -64,7 +75,36 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
form.installButton.isVisible = false form.installButton.isVisible = false
form.installButton.addActionListener { form.installButton.addActionListener {
update?.let { 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 -> { is PluginUpdateStatus.Update -> {
update = pluginUpdateStatus update = pluginUpdateStatus
versionForInstallation = update?.pluginDescriptor?.version
form.setUpdateStatus("A new version ${pluginUpdateStatus.pluginDescriptor.version} is available", true) 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 -> 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"/> <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> </constraints>
</vspacer> </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"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <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"/> <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> </component>
</children> </children>
</grid> </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> <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"/> <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> </constraints>
@@ -51,11 +51,24 @@
<constraints/> <constraints/>
<properties> <properties>
<actionCommand value="Install"/> <actionCommand value="Install"/>
<label value="Install..."/> <label value="Install"/>
<text value="&amp;Install..."/> <text value="&amp;Install"/>
<visible value="true"/> <visible value="true"/>
</properties> </properties>
</component> </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> </children>
</grid> </grid>
<grid id="209b0" layout-manager="FlowLayout" hgap="5" vgap="0" flow-align="0"> <grid id="209b0" layout-manager="FlowLayout" hgap="5" vgap="0" flow-align="0">
@@ -16,6 +16,7 @@ public class ConfigurePluginUpdatesForm {
public AsyncProcessIcon updateCheckProgressIcon; public AsyncProcessIcon updateCheckProgressIcon;
public JLabel updateStatusLabel; public JLabel updateStatusLabel;
public JButton installButton; public JButton installButton;
public JLabel installStatusLabel;
public ConfigurePluginUpdatesForm() { public ConfigurePluginUpdatesForm() {
int size = channelCombo.getModel().getSize(); int size = channelCombo.getModel().getSize();
@@ -36,10 +37,26 @@ public class ConfigurePluginUpdatesForm {
public void resetUpdateStatus() { public void resetUpdateStatus() {
updateStatusLabel.setText(" "); updateStatusLabel.setText(" ");
installButton.setVisible(false); installButton.setVisible(false);
installStatusLabel.setVisible(false);
} }
public void setUpdateStatus(String message, boolean showInstallButton) { public void setUpdateStatus(String message, boolean showInstallButton) {
installButton.setEnabled(true);
installButton.setVisible(showInstallButton); installButton.setVisible(showInstallButton);
updateStatusLabel.setText(message); 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);
} }
} }