-
Notifications
You must be signed in to change notification settings - Fork 42
feat: add custom workspace icons #922
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,7 @@ export class WorkspaceProvider | |
| workspace, | ||
| this.getWorkspacesQuery === WorkspaceQuery.All, | ||
| showMetadata, | ||
| this.client.getAxiosInstance().defaults.baseURL, | ||
| ); | ||
|
|
||
| return workspaceTreeItem; | ||
|
|
@@ -258,12 +259,16 @@ export class WorkspaceProvider | |
| // We need to do this for now because the reporting isn't super accurate | ||
| // yet. | ||
| appStatuses.push( | ||
| new AppStatusTreeItem({ | ||
| id: status.id, | ||
| name: status.message, | ||
| command: app.command, | ||
| workspace_name: element.workspace.name, | ||
| }), | ||
| new AppStatusTreeItem( | ||
| { | ||
| id: status.id, | ||
| name: status.message, | ||
| command: app.command, | ||
| workspace_name: element.workspace.name, | ||
| icon: app.icon, | ||
| }, | ||
| this.client.getAxiosInstance().defaults.baseURL, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -358,6 +363,45 @@ class AgentMetadataTreeItem extends vscode.TreeItem { | |
| } | ||
| } | ||
|
|
||
| function resolveTreeItemIconPath( | ||
| icon: string | undefined, | ||
| baseUrl?: string, | ||
| ): vscode.Uri | undefined { | ||
| if (!icon?.trim()) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const trimmed = icon.trim(); | ||
| if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(trimmed)) { | ||
| return vscode.Uri.parse(trimmed); | ||
| } | ||
|
|
||
| if (!baseUrl) { | ||
| return undefined; | ||
| } | ||
|
Comment on lines
+374
to
+381
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed, the |
||
|
|
||
| try { | ||
| const fullIconUrl = new URL(trimmed, baseUrl).toString(); | ||
| return vscode.Uri.parse(fullIconUrl); | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| function defaultTreeItemIconPath(): { | ||
| light: vscode.Uri; | ||
| dark: vscode.Uri; | ||
| } { | ||
| return { | ||
| light: vscode.Uri.file( | ||
| path.join(__dirname, "..", "..", "media", "logo-black.svg"), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong now, it used to be |
||
| ), | ||
| dark: vscode.Uri.file( | ||
| path.join(__dirname, "..", "..", "media", "logo-white.svg"), | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| class AppStatusTreeItem extends vscode.TreeItem { | ||
| constructor( | ||
| public readonly app: { | ||
|
|
@@ -366,12 +410,16 @@ class AppStatusTreeItem extends vscode.TreeItem { | |
| url?: string; | ||
| command?: string; | ||
| workspace_name?: string; | ||
| icon?: string; | ||
| }, | ||
| baseUrl?: string, | ||
| ) { | ||
| super("", vscode.TreeItemCollapsibleState.None); | ||
| super(app.name, vscode.TreeItemCollapsibleState.None); | ||
| this.id = app.id; | ||
| this.description = app.name; | ||
| this.description = app.workspace_name; | ||
|
Comment on lines
+417
to
+419
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly name here is confusing, this is If we want the status to be more prominent here then maybe we just show |
||
| this.contextValue = "coderAppStatus"; | ||
| const resolvedAppIcon = resolveTreeItemIconPath(app.icon, baseUrl); | ||
| this.iconPath = resolvedAppIcon ?? defaultTreeItemIconPath(); | ||
|
|
||
| // Add command to handle clicking on the app | ||
| this.command = { | ||
|
|
@@ -409,16 +457,8 @@ export class OpenableTreeItem extends vscode.TreeItem { | |
| tags.push("running"); | ||
| } | ||
| this.contextValue = tags.join("+"); | ||
| this.iconPath ??= defaultTreeItemIconPath(); | ||
| } | ||
|
|
||
| override iconPath = { | ||
| light: vscode.Uri.file( | ||
| path.join(__filename, "..", "..", "media", "logo-black.svg"), | ||
| ), | ||
| dark: vscode.Uri.file( | ||
| path.join(__filename, "..", "..", "media", "logo-white.svg"), | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| export class AgentTreeItem extends OpenableTreeItem { | ||
|
|
@@ -446,6 +486,7 @@ export class WorkspaceTreeItem extends OpenableTreeItem { | |
| workspace: Workspace, | ||
| public readonly showOwner: boolean, | ||
| public readonly watchMetadata = false, | ||
| baseUrl?: string, | ||
| ) { | ||
| const status = workspaceStatusLabel(workspace.latest_build.status); | ||
|
|
||
|
|
@@ -467,5 +508,13 @@ export class WorkspaceTreeItem extends OpenableTreeItem { | |
| ? "coderWorkspaceMultipleAgents" | ||
| : "coderWorkspaceSingleAgent", | ||
| ); | ||
|
|
||
| const resolvedWorkspaceIcon = resolveTreeItemIconPath( | ||
| workspace.template_icon, | ||
| baseUrl, | ||
| ); | ||
| if (resolvedWorkspaceIcon) { | ||
| this.iconPath = resolvedWorkspaceIcon; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should pass the resolved icon instead of the baseUrl here (esp. since it should always be defined). That way we do not leak abstraction into the
AppStatusTreeItemwhich shouldn't be aware of those details