Perform auto-check initial and checks after switching channels (KT-23980)

#KT-23980 Fixed
This commit is contained in:
Nikolay Krasko
2018-04-26 14:01:33 +03:00
parent 64845ac3b7
commit bf82da7584
3 changed files with 92 additions and 72 deletions
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.idea.PluginUpdateStatus
import org.jetbrains.kotlin.idea.configuration.ui.ConfigurePluginUpdatesForm
import javax.swing.JComponent
class KotlinUpdatesSettingsConfigurable() : SearchableConfigurable, Configurable.NoScroll {
class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.NoScroll {
companion object {
const val ID = "preferences.language.Kotlin"
@@ -43,46 +43,22 @@ class KotlinUpdatesSettingsConfigurable() : SearchableConfigurable, Configurable
private val form = ConfigurePluginUpdatesForm()
private var update: PluginUpdateStatus.Update? = null
private var savedChannel: Int = EAPChannels.EAP_1_3.indexIfAvailable() ?: EAPChannels.EAP_1_2.indexIfAvailable() ?: 0
override fun getId(): String = ID
override fun getDisplayName(): String = "Kotlin Updates"
override fun isModified(): Boolean {
return savedChannel != form.channelCombo.selectedIndex
}
override fun isModified() = false
override fun apply() {
saveSettings()
// Selected channel is now saved automatically
}
override fun createComponent(): JComponent? {
form.updateCheckProgressIcon.suspend()
form.updateCheckProgressIcon.setPaintPassiveIcon(false)
form.checkForUpdatesNowButton.addActionListener {
saveSettings()
form.updateCheckProgressIcon.resume()
form.resetUpdateStatus()
KotlinPluginUpdater.getInstance().runUpdateCheck{ pluginUpdateStatus ->
form.updateCheckProgressIcon.suspend()
when (pluginUpdateStatus) {
PluginUpdateStatus.LatestVersionInstalled ->
form.updateStatusLabel.text = "You have the latest version of the plugin (${KotlinPluginUtil.getPluginVersion()}) installed."
is PluginUpdateStatus.Update -> {
update = pluginUpdateStatus
form.installButton.isVisible = true
form.updateStatusLabel.text = "A new version ${pluginUpdateStatus.pluginDescriptor.version} is available"
}
is PluginUpdateStatus.CheckFailed ->
form.updateStatusLabel.text = "Update check failed: ${pluginUpdateStatus.message}"
}
false // do not auto-retry update check
}
form.reCheckButton.addActionListener {
checkForUpdates()
}
form.installButton.isVisible = false
@@ -92,18 +68,50 @@ class KotlinUpdatesSettingsConfigurable() : SearchableConfigurable, Configurable
}
}
val savedChannel: Int = EAPChannels.EAP_1_3.indexIfAvailable() ?: EAPChannels.EAP_1_2.indexIfAvailable() ?: 0
form.channelCombo.selectedIndex = savedChannel
form.channelCombo.addActionListener {
form.resetUpdateStatus()
checkForUpdates()
}
form.channelCombo.selectedIndex = savedChannel
checkForUpdates()
return form.mainPanel
}
private fun checkForUpdates() {
saveSettings()
form.updateCheckProgressIcon.resume()
form.resetUpdateStatus()
KotlinPluginUpdater.getInstance().runUpdateCheck{ pluginUpdateStatus ->
// Need this to show something is happening when check is very fast
Thread.sleep(30)
form.updateCheckProgressIcon.suspend()
when (pluginUpdateStatus) {
PluginUpdateStatus.LatestVersionInstalled -> {
form.setUpdateStatus(
"You have the latest version of the plugin (${KotlinPluginUtil.getPluginVersion()}) installed.",
false
)
}
is PluginUpdateStatus.Update -> {
update = pluginUpdateStatus
form.setUpdateStatus("A new version ${pluginUpdateStatus.pluginDescriptor.version} is available", true)
}
is PluginUpdateStatus.CheckFailed ->
form.setUpdateStatus("Update check failed: ${pluginUpdateStatus.message}", false)
}
false // do not auto-retry update check
}
}
private fun saveSettings() {
savedChannel = form.channelCombo.selectedIndex
saveSelectedChannel(savedChannel)
saveSelectedChannel(form.channelCombo.selectedIndex)
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.configuration.ui.ConfigurePluginUpdatesForm">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -22,41 +22,10 @@
<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>
<component id="ca1a9" class="javax.swing.JComboBox" binding="channelCombo">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Stable"/>
<item value="Early Access Preview 1.2.x"/>
<item value="Early Access Preview 1.3"/>
</model>
</properties>
</component>
<grid id="b171" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c7546" class="javax.swing.JButton" binding="checkForUpdatesNowButton" default-binding="true">
<constraints/>
<properties>
<text value="Check for updates &amp;now"/>
</properties>
</component>
<component id="3b585" class="com.intellij.util.ui.AsyncProcessIcon" binding="updateCheckProgressIcon" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</grid>
<grid id="2505b" layout-manager="GridLayoutManager" row-count="1" column-count="2" 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="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="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"/>
<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"/>
</constraints>
<properties/>
<border type="none"/>
@@ -69,17 +38,55 @@
<text value=" "/>
</properties>
</component>
</children>
</grid>
<grid id="b171" layout-manager="FlowLayout" hgap="5" 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>
<properties/>
<border type="none"/>
<children>
<component id="65662" class="javax.swing.JButton" binding="installButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<constraints/>
<properties>
<text value="&amp;Install"/>
<actionCommand value="Install"/>
<label value="Install..."/>
<text value="&amp;Install..."/>
<visible value="true"/>
</properties>
</component>
</children>
</grid>
<grid id="209b0" layout-manager="FlowLayout" hgap="5" vgap="0" flow-align="0">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ca1a9" class="javax.swing.JComboBox" binding="channelCombo">
<constraints/>
<properties>
<model>
<item value="Stable"/>
<item value="Early Access Preview 1.2.x"/>
<item value="Early Access Preview 1.3"/>
</model>
</properties>
</component>
<component id="c7546" class="javax.swing.JButton" binding="reCheckButton">
<constraints/>
<properties>
<text value="&amp;Recheck now"/>
</properties>
</component>
<component id="3b585" class="com.intellij.util.ui.AsyncProcessIcon" binding="updateCheckProgressIcon" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -11,7 +11,7 @@ import javax.swing.*;
public class ConfigurePluginUpdatesForm {
public JComboBox<String> channelCombo;
public JButton checkForUpdatesNowButton;
public JButton reCheckButton;
public JPanel mainPanel;
public AsyncProcessIcon updateCheckProgressIcon;
public JLabel updateStatusLabel;
@@ -37,4 +37,9 @@ public class ConfigurePluginUpdatesForm {
updateStatusLabel.setText(" ");
installButton.setVisible(false);
}
public void setUpdateStatus(String message, boolean showInstallButton) {
installButton.setVisible(showInstallButton);
updateStatusLabel.setText(message);
}
}