Skip to content

Commit 9343f08

Browse files
committed
chore: remove internal API usages
- removed usages for some internal and deprecated APIs - there are still a couple of usages remaining for which I could not find an equivalent. Especially stuff around creating the remote deployer.
1 parent aeff367 commit 9343f08

File tree

6 files changed

+82
-26
lines changed

6 files changed

+82
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
## Unreleased
66

7+
### Added
8+
9+
- support for Gateway 2023
10+
711
## 2.1.7 - 2023-02-28
812

913
### Fixed
14+
1015
- terminal link is now correct when host ends in `/`
1116
- improved resiliency and error handling when trying to open the last successful connection
1217

src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.coder.gateway
22

3+
import com.coder.gateway.help.ABOUT_HELP_TOPIC
34
import com.coder.gateway.icons.CoderIcons
45
import com.coder.gateway.views.CoderGatewayConnectorWizardWrapperView
56
import com.coder.gateway.views.CoderGatewayRecentWorkspaceConnectionsView
6-
import com.intellij.ui.components.ActionLink
7-
import com.intellij.ui.components.BrowserLink
7+
import com.intellij.openapi.help.HelpManager
88
import com.jetbrains.gateway.api.GatewayConnector
9+
import com.jetbrains.gateway.api.GatewayConnectorDocumentation
910
import com.jetbrains.gateway.api.GatewayConnectorView
1011
import com.jetbrains.gateway.api.GatewayRecentConnections
1112
import com.jetbrains.rd.util.lifetime.Lifetime
1213
import java.awt.Component
1314
import javax.swing.Icon
14-
import javax.swing.JComponent
1515

1616
class CoderGatewayMainView : GatewayConnector {
1717
override fun getConnectorId() = CoderGatewayConstants.GATEWAY_CONNECTOR_ID
@@ -31,8 +31,10 @@ class CoderGatewayMainView : GatewayConnector {
3131
return CoderGatewayBundle.message("gateway.connector.description")
3232
}
3333

34-
override fun getDocumentationLink(): ActionLink {
35-
return BrowserLink("Learn more", "https://coder.com/docs/coder-oss/latest")
34+
override fun getDocumentationAction(): GatewayConnectorDocumentation {
35+
return GatewayConnectorDocumentation(true) {
36+
HelpManager.getInstance().invokeHelp(ABOUT_HELP_TOPIC)
37+
}
3638
}
3739

3840
override fun getRecentConnections(setContentCallback: (Component) -> Unit): GatewayRecentConnections {
@@ -43,10 +45,6 @@ class CoderGatewayMainView : GatewayConnector {
4345
return CoderGatewayBundle.message("gateway.connector.title")
4446
}
4547

46-
override fun getTitleAdornment(): JComponent? {
47-
return null
48-
}
49-
5048
override fun isAvailable(): Boolean {
5149
return true
5250
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.coder.gateway.help
2+
3+
import com.intellij.openapi.help.WebHelpProvider
4+
5+
const val ABOUT_HELP_TOPIC = "com.coder.gateway.about"
6+
7+
class CoderWebHelp : WebHelpProvider() {
8+
override fun getHelpPageUrl(helpTopicId: String): String {
9+
return when (helpTopicId) {
10+
ABOUT_HELP_TOPIC -> "https://coder.com/docs/coder-oss/latest"
11+
else -> "https://coder.com/docs/coder-oss/latest"
12+
}
13+
}
14+
}

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package com.coder.gateway.sdk
33
import com.coder.gateway.icons.CoderIcons
44
import com.intellij.openapi.components.Service
55
import com.intellij.openapi.components.service
6-
import com.intellij.util.IconUtil
6+
import com.intellij.ui.JreHiDpiUtil
7+
import com.intellij.ui.paint.alignToInt
8+
import com.intellij.ui.scale.JBUIScale
79
import com.intellij.util.ImageLoader
810
import com.intellij.util.ui.ImageUtil
911
import org.imgscalr.Scalr
12+
import java.awt.Component
13+
import java.awt.Graphics
14+
import java.awt.Graphics2D
15+
import java.awt.image.BufferedImage
1016
import java.net.URL
1117
import javax.swing.Icon
1218

@@ -30,7 +36,7 @@ class TemplateIconDownloader {
3036
}
3137
var img = ImageLoader.loadFromUrl(url)
3238
if (img != null) {
33-
val icon = IconUtil.toRetinaAwareIcon(Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, 32))
39+
val icon = toRetinaAwareIcon(Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, 32))
3440
cache[Pair(workspaceName, path)] = icon
3541
return icon
3642
}
@@ -39,6 +45,34 @@ class TemplateIconDownloader {
3945
return iconForChar(workspaceName.lowercase().first())
4046
}
4147

48+
private fun toRetinaAwareIcon(image: BufferedImage): Icon {
49+
val sysScale = JBUIScale.sysScale()
50+
return object : Icon {
51+
override fun paintIcon(c: Component?, g: Graphics, x: Int, y: Int) {
52+
if (isJreHiDPI) {
53+
val newG = g.create(x, y, image.width, image.height) as Graphics2D
54+
alignToInt(newG)
55+
newG.scale(1.0 / sysScale, 1.0 / sysScale)
56+
newG.drawImage(image, 0, 0, null)
57+
newG.dispose()
58+
} else {
59+
g.drawImage(image, x, y, null)
60+
}
61+
}
62+
63+
override fun getIconWidth(): Int = if (isJreHiDPI) (image.width / sysScale).toInt() else image.width
64+
65+
override fun getIconHeight(): Int = if (isJreHiDPI) (image.height / sysScale).toInt() else image.height
66+
67+
private val isJreHiDPI: Boolean
68+
get() = JreHiDpiUtil.isJreHiDPI(sysScale)
69+
70+
override fun toString(): String {
71+
return "TemplateIconDownloader.toRetinaAwareIcon for $image"
72+
}
73+
}
74+
}
75+
4276
private fun iconForChar(c: Char) = when (c) {
4377
'0' -> CoderIcons.ZERO
4478
'1' -> CoderIcons.ONE

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ import com.intellij.ide.BrowserUtil
2828
import com.intellij.ide.IdeBundle
2929
import com.intellij.ide.util.PropertiesComponent
3030
import com.intellij.openapi.Disposable
31+
import com.intellij.openapi.actionSystem.AnAction
3132
import com.intellij.openapi.actionSystem.AnActionEvent
33+
import com.intellij.openapi.application.ApplicationManager
3234
import com.intellij.openapi.application.ModalityState
33-
import com.intellij.openapi.application.invokeAndWaitIfNeeded
3435
import com.intellij.openapi.components.service
3536
import com.intellij.openapi.diagnostic.Logger
3637
import com.intellij.openapi.progress.ProgressIndicator
@@ -187,11 +188,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
187188
.disableAddAction()
188189
.disableRemoveAction()
189190
.disableUpDownActions()
190-
.addExtraAction(goToDashboardAction)
191-
.addExtraAction(startWorkspaceAction)
192-
.addExtraAction(stopWorkspaceAction)
193-
.addExtraAction(updateWorkspaceTemplateAction)
194-
.addExtraAction(createWorkspaceAction)
191+
.addExtraActions(goToDashboardAction, startWorkspaceAction, stopWorkspaceAction, updateWorkspaceTemplateAction, createWorkspaceAction as AnAction)
195192

196193

197194
private var poller: Job? = null
@@ -237,13 +234,15 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
237234
override val previousActionText = IdeBundle.message("button.back")
238235
override val nextActionText = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.next.text")
239236

240-
private inner class GoToDashboardAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderIcons.HOME) {
237+
private inner class GoToDashboardAction :
238+
AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderIcons.HOME) {
241239
override fun actionPerformed(p0: AnActionEvent) {
242240
BrowserUtil.browse(coderClient.coderURL)
243241
}
244242
}
245243

246-
private inner class StartWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderIcons.RUN) {
244+
private inner class StartWorkspaceAction :
245+
AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderIcons.RUN) {
247246
override fun actionPerformed(p0: AnActionEvent) {
248247
if (tableOfWorkspaces.selectedObject != null) {
249248
val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
@@ -261,7 +260,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
261260
}
262261
}
263262

264-
private inner class UpdateWorkspaceTemplateAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderIcons.UPDATE) {
263+
private inner class UpdateWorkspaceTemplateAction :
264+
AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderIcons.UPDATE) {
265265
override fun actionPerformed(p0: AnActionEvent) {
266266
if (tableOfWorkspaces.selectedObject != null) {
267267
val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
@@ -281,7 +281,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
281281
}
282282
}
283283

284-
private inner class StopWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderIcons.STOP) {
284+
private inner class StopWorkspaceAction :
285+
AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderIcons.STOP) {
285286
override fun actionPerformed(p0: AnActionEvent) {
286287
if (tableOfWorkspaces.selectedObject != null) {
287288
val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
@@ -299,7 +300,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
299300
}
300301
}
301302

302-
private inner class CreateWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
303+
private inner class CreateWorkspaceAction :
304+
AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
303305
override fun actionPerformed(p0: AnActionEvent) {
304306
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates"))
305307
}
@@ -460,7 +462,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
460462

461463
private fun askToken(): String? {
462464
BrowserUtil.browse(localWizardModel.coderURL.toURL().withPath("/login?redirect=%2Fcli-auth"))
463-
return invokeAndWaitIfNeeded(ModalityState.any()) {
465+
var tokenFromUser: String? = null
466+
ApplicationManager.getApplication().invokeAndWait({
464467
lateinit var sessionTokenTextField: JBTextField
465468

466469
val panel = panel {
@@ -474,10 +477,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
474477

475478
AppIcon.getInstance().requestAttention(null, true)
476479
if (!dialog(CoderGatewayBundle.message("gateway.connector.view.login.token.dialog"), panel = panel, focusedComponent = sessionTokenTextField).showAndGet()) {
477-
return@invokeAndWaitIfNeeded null
480+
return@invokeAndWait
478481
}
479-
return@invokeAndWaitIfNeeded sessionTokenTextField.text
480-
}
482+
tokenFromUser = sessionTokenTextField.text
483+
}, ModalityState.any())
484+
return tokenFromUser
481485
}
482486

483487
private fun triggerWorkspacePolling() {

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<applicationService serviceImplementation="com.coder.gateway.sdk.CoderRestClientService"></applicationService>
1919
<applicationService serviceImplementation="com.coder.gateway.sdk.TemplateIconDownloader"></applicationService>
2020
<applicationService serviceImplementation="com.coder.gateway.services.CoderRecentWorkspaceConnectionsService"></applicationService>
21+
<webHelpProvider implementation="com.coder.gateway.help.CoderWebHelp"></webHelpProvider>
2122
</extensions>
2223
<extensions defaultExtensionNs="com.jetbrains">
2324
<gatewayConnector implementation="com.coder.gateway.CoderGatewayMainView"/>

0 commit comments

Comments
 (0)