Skip to content

Impl: icons with support for light&dark themes #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
### Added

- initial support for JetBrains Toolbox 2.6.0.38311 with the possibility to manage the workspaces - i.e. start, stop,
update and delete actions and also quick shortcuts to templates, web terminal and dashboard.
update and delete actions and also quick shortcuts to templates, web terminal and dashboard.
- support for light & dark themes
81 changes: 48 additions & 33 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,59 @@ class CoderRemoteEnvironment(

override val actionsList: MutableStateFlow<List<ActionDescription>> = MutableStateFlow(getAvailableActions())

private fun getAvailableActions(): List<ActionDescription> = listOf(
Action(context.i18n.ptrl("Open web terminal")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
context.ui.showErrorInfoPopup(it)
private fun getAvailableActions(): List<ActionDescription> {
val actions = mutableListOf(
Action(context.i18n.ptrl("Open web terminal")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
context.ui.showErrorInfoPopup(it)
}
}
}
},
Action(context.i18n.ptrl("Open in dashboard")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
context.ui.showErrorInfoPopup(it)
},
Action(context.i18n.ptrl("Open in dashboard")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
context.ui.showErrorInfoPopup(it)
}
}
}
},
},

Action(context.i18n.ptrl("View template")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
context.ui.showErrorInfoPopup(it)
Action(context.i18n.ptrl("View template")) {
context.cs.launch {
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
context.ui.showErrorInfoPopup(it)
}
}
})

if (wsRawStatus.canStart()) {
if (workspace.outdated) {
actions.add(Action(context.i18n.ptrl("Update and start")) {
val build = client.updateWorkspace(workspace)
update(workspace.copy(latestBuild = build), agent)
})
} else {
actions.add(Action(context.i18n.ptrl("Start")) {
val build = client.startWorkspace(workspace)
update(workspace.copy(latestBuild = build), agent)
})
}
},
Action(context.i18n.ptrl("Start"), enabled = { wsRawStatus.canStart() }) {
val build = client.startWorkspace(workspace)
workspace = workspace.copy(latestBuild = build)
update(workspace, agent)
},
Action(context.i18n.ptrl("Stop"), enabled = { wsRawStatus.canStop() }) {
val build = client.stopWorkspace(workspace)
workspace = workspace.copy(latestBuild = build)
update(workspace, agent)
},
Action(context.i18n.ptrl("Update"), enabled = { workspace.outdated }) {
val build = client.updateWorkspace(workspace)
workspace = workspace.copy(latestBuild = build)
update(workspace, agent)
})
}
if (wsRawStatus.canStop()) {
if (workspace.outdated) {
actions.add(Action(context.i18n.ptrl("Update and restart")) {
val build = client.updateWorkspace(workspace)
update(workspace.copy(latestBuild = build), agent)
})
} else {
actions.add(Action(context.i18n.ptrl("Stop")) {
val build = client.stopWorkspace(workspace)
update(workspace.copy(latestBuild = build), agent)
})
}
}
return actions
}

/**
* Update the workspace/agent status to the listeners, if it has changed.
Expand Down
11 changes: 9 additions & 2 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.coder.toolbox.views.NewEnvironmentPage
import com.coder.toolbox.views.SignInPage
import com.coder.toolbox.views.TokenPage
import com.jetbrains.toolbox.api.core.ui.icons.SvgIcon
import com.jetbrains.toolbox.api.core.ui.icons.SvgIcon.IconType
import com.jetbrains.toolbox.api.core.util.LoadableState
import com.jetbrains.toolbox.api.remoteDev.ProviderVisibilityState
import com.jetbrains.toolbox.api.remoteDev.RemoteProvider
Expand Down Expand Up @@ -181,10 +182,16 @@ class CoderRemoteProvider(
}

override val svgIcon: SvgIcon =
SvgIcon(this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf())
SvgIcon(
this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf(),
type = IconType.Masked
)

override val noEnvironmentsSvgIcon: SvgIcon? =
SvgIcon(this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf())
SvgIcon(
this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf(),
type = IconType.Masked
)

/**
* TODO@JB: It would be nice to show "loading workspaces" at first but it
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/com/coder/toolbox/views/CoderPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.coder.toolbox.views

import com.coder.toolbox.CoderToolboxContext
import com.jetbrains.toolbox.api.core.ui.icons.SvgIcon
import com.jetbrains.toolbox.api.core.ui.icons.SvgIcon.IconType
import com.jetbrains.toolbox.api.localization.LocalizableString
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
import com.jetbrains.toolbox.api.ui.components.UiField
Expand Down Expand Up @@ -46,9 +47,12 @@ abstract class CoderPage(
* This seems to only work on the first page.
*/
override val svgIcon: SvgIcon? = if (showIcon) {
SvgIcon(this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf())
SvgIcon(
this::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf(),
type = IconType.Masked
)
} else {
SvgIcon(byteArrayOf())
SvgIcon(byteArrayOf(), type = IconType.Masked)
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/localization/defaultMessages.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ msgstr ""
msgid "Stop"
msgstr ""

msgid "Update"
msgid "Update and start"
msgstr ""

msgid "Update and restart"
msgstr ""

msgid "Settings"
Expand Down
Loading