Skip to content

Commit 25f9e82

Browse files
committed
Add nightly channel to the channels dialog
Fix update dialog never returning results on update check
1 parent dd97120 commit 25f9e82

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Minecraft Development for IntelliJ
66
| Service |Status|
77
|------------|------|
88
|**TeamCity**|[![TeamCity Build Status](https://img.shields.io/teamcity/http/ci.demonwav.com/s/MinecraftDev_Build.svg?style=flat-square)](https://ci.demonwav.com/viewType.html?buildTypeId=MinecraftDev_Build)|
9+
|**Nightly**|[![TeamCity Build Status](https://img.shields.io/teamcity/http/ci.demonwav.com/s/MinecraftDev_Nightly.svg?style=flat-square)](https://ci.demonwav.com/viewType.html?buildTypeId=MinecraftDev_Nightly)|
910
|**CircleCI**|[![Travis Build Status](https://img.shields.io/circleci/project/github/minecraft-dev/MinecraftDev/2017.1.svg?style=flat-square)](https://circleci.com/gh/minecraft-dev/MinecraftDev)|
1011
|**Travis** |[![CircleCI Build Status](https://img.shields.io/travis/minecraft-dev/MinecraftDev/2017.1.svg?style=flat-square)](https://travis-ci.org/minecraft-dev/MinecraftDev/)|
1112

src/main/kotlin/com/demonwav/mcdev/update/Channels.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ package com.demonwav.mcdev.update
1212

1313
import com.intellij.openapi.updateSettings.impl.UpdateSettings
1414

15-
enum class Channels(val title: String, val url: String, val index: Int) {
16-
;
15+
enum class Channels(val title: String, val url: String) {
16+
NIGHTLY("Nightly", "https://plugins.jetbrains.com/plugins/Nightly/8327");
1717

1818
fun hasChannel(): Boolean {
1919
return UpdateSettings.getInstance().pluginHosts.contains(url)
2020
}
21-
22-
companion object {
23-
fun getChannel(index: Int) = values().firstOrNull { it.index == index }
24-
fun orderedList() = listOf<Channels>()
25-
}
2621
}

src/main/kotlin/com/demonwav/mcdev/update/ConfigurePluginUpdatesDialog.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConfigurePluginUpdatesDialog : DialogWrapper(true) {
2727
form.updateCheckInProgressIcon.setPaintPassiveIcon(false)
2828

2929
form.channelBox.addItem("Stable")
30-
for (channels in Channels.orderedList()) {
30+
for (channels in Channels.values()) {
3131
form.channelBox.addItem(channels.title)
3232
}
3333

@@ -67,31 +67,29 @@ class ConfigurePluginUpdatesDialog : DialogWrapper(true) {
6767

6868
form.channelBox.addActionListener { resetUpdateStatus() }
6969

70-
for (channels in Channels.values()) {
71-
if (channels.hasChannel()) {
72-
initialSelectedChannel = channels.index
73-
break
70+
Channels.values().forEachIndexed { i, channel ->
71+
if (channel.hasChannel()) {
72+
initialSelectedChannel = i + 1
73+
return@forEachIndexed
7474
}
7575
}
7676

7777
form.channelBox.selectedIndex = initialSelectedChannel
7878
init()
7979
}
8080

81-
override fun createCenterPanel(): JComponent? {
82-
return form.panel
83-
}
81+
override fun createCenterPanel() = form.panel
8482

85-
private fun saveSelectedChannel(channel: Int) {
83+
private fun saveSelectedChannel(index: Int) {
8684
val hosts = UpdateSettings.getInstance().storedPluginHosts
87-
for (channels in Channels.values()) {
88-
hosts.remove(channels.url)
85+
for (channel in Channels.values()) {
86+
hosts.remove(channel.url)
8987
}
9088

91-
val channels = Channels.getChannel(channel) ?: // This really shouldn't happen
92-
return
93-
94-
hosts.add(channels.url)
89+
if (index != 0) {
90+
val channel = Channels.values()[index - 1]
91+
hosts.add(channel.url)
92+
}
9593
}
9694

9795
private fun saveSettings() {

src/main/kotlin/com/demonwav/mcdev/update/PluginUpdater.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package com.demonwav.mcdev.update
1212

1313
import com.demonwav.mcdev.util.forEachNotNull
14-
import com.demonwav.mcdev.util.invokeLater
14+
import com.demonwav.mcdev.util.invokeLaterAny
1515
import com.intellij.ide.plugins.IdeaPluginDescriptor
1616
import com.intellij.ide.plugins.PluginManager
1717
import com.intellij.ide.plugins.PluginManagerMain
@@ -47,11 +47,10 @@ object PluginUpdater {
4747
.forEachNotNull { updateStatus = updateStatus.mergeWith(checkUpdatesInCustomRepo(it)) }
4848

4949
val finalUpdate = updateStatus
50-
invokeLater { callback(finalUpdate) }
50+
invokeLaterAny { callback(finalUpdate) }
5151
} catch (e: Exception) {
5252
PluginUpdateStatus.CheckFailed("Minecraft Development plugin update check failed")
5353
}
54-
5554
}
5655

5756
private fun checkUpdatesInMainRepo(): PluginUpdateStatus {

src/main/kotlin/com/demonwav/mcdev/util/Util.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ inline fun invokeLater(crossinline func: () -> Unit) {
5959
}
6060
}
6161

62+
inline fun invokeLaterAny(crossinline func: () -> Unit) {
63+
if (ApplicationManager.getApplication().isDispatchThread) {
64+
func()
65+
} else {
66+
ApplicationManager.getApplication().invokeLater({ func() }, ModalityState.any())
67+
}
68+
}
69+
6270
/**
6371
* Returns an untyped array for the specified [Collection].
6472
*/

0 commit comments

Comments
 (0)