Skip to content

Commit c6a5c62

Browse files
authored
Merge pull request #134 from coder/more-perf-improvements
More perf improvements
2 parents 08887b3 + 592892c commit c6a5c62

File tree

7 files changed

+193
-140
lines changed

7 files changed

+193
-140
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
### Added
88
- ability to open a template in the Dashboard
9+
- ability to sort by workspace name, or by template name or by workspace status
10+
- a new token is requested when the one persisted is expired
911

1012
### Changed
1113
- renamed the plugin from `Coder Gateway` to `Gateway`
1214
- workspaces and agents are now resolved and displayed progressively
1315

1416
### Fixed
15-
- icon rendering on macOS
17+
- icon rendering on `macOS`
18+
- `darwin` agents are now recognized as `macOS`
19+
- unsupported OS warning is displayed only for running workspaces
1620

1721
## 2.1.3 - 2022-12-09
1822

src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ data class WorkspaceAgentModel(
1212
val name: String,
1313
val templateID: UUID,
1414
val templateName: String,
15-
val templateIcon: Icon,
15+
val templateIconPath: String,
16+
var templateIcon: Icon?,
1617
val status: WorkspaceVersionStatus,
1718
val agentStatus: WorkspaceAgentStatus,
1819
val lastBuildTransition: WorkspaceTransition,

src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ package com.coder.gateway.models
33
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
44
import com.coder.gateway.sdk.v2.models.Workspace
55
import com.coder.gateway.sdk.v2.models.WorkspaceTransition
6+
import com.intellij.ui.JBColor
67

78
enum class WorkspaceAgentStatus(val label: String) {
89
QUEUED("◍ Queued"), STARTING("⦿ Starting"), STOPPING("◍ Stopping"), DELETING("⦸ Deleting"),
910
RUNNING("⦿ Running"), STOPPED("◍ Stopped"), DELETED("⦸ Deleted"),
1011
CANCELING("◍ Canceling action"), CANCELED("◍ Canceled action"), FAILED("ⓧ Failed");
1112

13+
fun statusColor() = when (this) {
14+
RUNNING -> JBColor.GREEN
15+
FAILED -> JBColor.RED
16+
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
17+
}
18+
1219
companion object {
1320
fun from(workspace: Workspace) = when (workspace.latestBuild.job.status) {
1421
ProvisionerJobStatus.PENDING -> QUEUED
@@ -28,5 +35,7 @@ enum class WorkspaceAgentStatus(val label: String) {
2835
ProvisionerJobStatus.CANCELED -> CANCELED
2936
ProvisionerJobStatus.FAILED -> FAILED
3037
}
38+
39+
fun from(str: String) = WorkspaceAgentStatus.values().first { it.label.contains(str, true) }
3140
}
3241
}

src/main/kotlin/com/coder/gateway/sdk/TemplateIconDownloader.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import javax.swing.Icon
1313
@Service(Service.Level.APP)
1414
class TemplateIconDownloader {
1515
private val coderClient: CoderRestClientService = service()
16+
private val cache = mutableMapOf<Pair<String, String>, Icon>()
1617

1718
fun load(path: String, templateName: String): Icon {
1819
var url: URL? = null
@@ -23,9 +24,15 @@ class TemplateIconDownloader {
2324
}
2425

2526
if (url != null) {
27+
val cachedIcon = cache[Pair(templateName, path)]
28+
if (cachedIcon != null) {
29+
return cachedIcon
30+
}
2631
var img = ImageLoader.loadFromUrl(url)
2732
if (img != null) {
28-
return IconUtil.toRetinaAwareIcon(Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, 32))
33+
val icon = IconUtil.toRetinaAwareIcon(Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, 32))
34+
cache[Pair(templateName, path)] = icon
35+
return icon
2936
}
3037
}
3138

src/main/kotlin/com/coder/gateway/sdk/os.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.coder.gateway.sdk
22

3+
import java.util.Locale
4+
35
fun getOS(): OS? {
46
return OS.from(System.getProperty("os.name"))
57
}
68

79
fun getArch(): Arch? {
8-
return Arch.from(System.getProperty("os.arch").toLowerCase())
10+
return Arch.from(System.getProperty("os.arch").lowercase(Locale.getDefault()))
911
}
1012

1113
enum class OS {
@@ -22,7 +24,7 @@ enum class OS {
2224
LINUX
2325
}
2426

25-
os.contains("mac", true) -> {
27+
os.contains("mac", true) || os.contains("darwin", true) -> {
2628
MAC
2729
}
2830

0 commit comments

Comments
 (0)