Skip to content

Commit 88b31a2

Browse files
chore: apply feedback
1 parent 2de7f12 commit 88b31a2

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/inbox.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Api } from "coder/site/src/api/api"
2+
import { ProxyAgent } from "proxy-agent"
23
import * as vscode from "vscode"
34
import { WebSocket } from "ws"
45
import { errToStr } from "./api-helper"
5-
import { Storage } from "./storage"
6-
import { ProxyAgent } from "proxy-agent"
6+
import { type Storage } from "./storage"
77

88
type InboxMessage = {
99
unread_count: number
@@ -14,26 +14,26 @@ type InboxMessage = {
1414
targets: string[]
1515
title: string
1616
content: string
17-
actions: {
18-
[key: string]: string
19-
}
17+
actions: Record<string, string>
2018
read_at: string
2119
created_at: string
2220
}
2321
}
2422

25-
const TemplateWorkspaceOutOfMemory = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
26-
const TemplateWorkspaceOutOfDisk = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"
23+
// These are the template IDs of our notifications.
24+
// Maybe in the future we should avoid hardcoding
25+
// these in both coderd and here.
26+
const TEMPLATE_WORKSPACE_OUT_OF_MEMORY = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
27+
const TEMPLATE_WORKSPACE_OUT_OF_DISK = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"
2728

2829
export class Inbox implements vscode.Disposable {
30+
private readonly storage: Storage
2931
private disposed = false
3032
private socket: WebSocket
3133

32-
constructor(
33-
httpAgent: ProxyAgent,
34-
restClient: Api,
35-
private readonly storage: Storage,
36-
) {
34+
constructor(httpAgent: ProxyAgent, restClient: Api, storage: Storage) {
35+
this.storage = storage
36+
3737
const baseUrlRaw = restClient.getAxiosInstance().defaults.baseURL
3838
if (!baseUrlRaw) {
3939
throw new Error("No base URL set on REST client")
@@ -43,11 +43,12 @@ export class Inbox implements vscode.Disposable {
4343
const socketProto = baseUrl.protocol === "https:" ? "wss:" : "ws:"
4444
const socketUrlRaw = `${socketProto}//${baseUrl.host}/api/v2/notifications/watch`
4545

46+
const coderSessionTokenHeader = "Coder-Session-Token"
4647
this.socket = new WebSocket(new URL(socketUrlRaw), {
4748
followRedirects: true,
4849
agent: httpAgent,
4950
headers: {
50-
"Coder-Session-Token": restClient.getAxiosInstance().defaults.headers.common["Coder-Session-Token"] as
51+
[coderSessionTokenHeader]: restClient.getAxiosInstance().defaults.headers.common[coderSessionTokenHeader] as
5152
| string
5253
| undefined,
5354
},
@@ -66,8 +67,8 @@ export class Inbox implements vscode.Disposable {
6667
const inboxMessage = JSON.parse(data.toString()) as InboxMessage
6768

6869
if (
69-
inboxMessage.notification.template_id === TemplateWorkspaceOutOfDisk ||
70-
inboxMessage.notification.template_id === TemplateWorkspaceOutOfMemory
70+
inboxMessage.notification.template_id === TEMPLATE_WORKSPACE_OUT_OF_DISK ||
71+
inboxMessage.notification.template_id === TEMPLATE_WORKSPACE_OUT_OF_MEMORY
7172
) {
7273
vscode.window.showWarningMessage(inboxMessage.notification.title)
7374
}

src/remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class Remote {
405405
disposables.push(monitor.onChange.event((w) => (this.commands.workspace = w)))
406406

407407
// Watch coder inbox for messages
408-
const httpAgent = await createHttpAgent();
408+
const httpAgent = await createHttpAgent()
409409
const inbox = new Inbox(httpAgent, workspaceRestClient, this.storage)
410410
disposables.push(inbox)
411411

0 commit comments

Comments
 (0)