Skip to content

Commit 0fd3e02

Browse files
committed
Active Windows mode on Windows
1 parent 3e1a0a4 commit 0fd3e02

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

agent/agent.go

+2
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
484484
}
485485
a.reconnectingPTYs.Store(id, rpty)
486486
go func() {
487+
// CommandContext isn't respected for Windows PTYs right now,
488+
// so we need to manually track the lifecycle.
487489
// When the context has been completed either:
488490
// 1. The timeout completed.
489491
// 2. The parent context was canceled.

site/src/api/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface WorkspaceResource {
8787
export interface WorkspaceAgent {
8888
id: string
8989
name: string
90+
operating_system: string
9091
}
9192

9293
export interface APIKeyResponse {

site/src/pages/TerminalPage/TerminalPage.tsx

+17-17
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ export const TerminalPage: React.FC<{
3939
// a round-trip, and must be a UUIDv4.
4040
const [reconnectionToken] = React.useState<string>(() => {
4141
const search = new URLSearchParams(location.search)
42-
let reconnect = search.get("reconnect")
43-
if (reconnect === null) {
44-
reconnect = crypto.randomUUID()
45-
}
46-
return reconnect
42+
return search.get("reconnect") ?? crypto.randomUUID()
4743
})
4844
const [terminalState, sendEvent] = useMachine(terminalMachine, {
4945
actions: {
@@ -59,6 +55,8 @@ export const TerminalPage: React.FC<{
5955
},
6056
})
6157
const isConnected = terminalState.matches("connected")
58+
const { organizationsError, workspaceError, workspaceAgentError, workspaceAgent, websocketError } =
59+
terminalState.context
6260

6361
// Create the terminal!
6462
React.useEffect(() => {
@@ -150,17 +148,17 @@ export const TerminalPage: React.FC<{
150148
terminal.options = {
151149
disableStdin: true,
152150
}
153-
if (terminalState.context.organizationsError instanceof Error) {
154-
terminal.writeln(Language.organizationsErrorMessagePrefix + terminalState.context.organizationsError.message)
151+
if (organizationsError instanceof Error) {
152+
terminal.writeln(Language.organizationsErrorMessagePrefix + organizationsError.message)
155153
}
156-
if (terminalState.context.workspaceError instanceof Error) {
157-
terminal.writeln(Language.workspaceErrorMessagePrefix + terminalState.context.workspaceError.message)
154+
if (workspaceError instanceof Error) {
155+
terminal.writeln(Language.workspaceErrorMessagePrefix + workspaceError.message)
158156
}
159-
if (terminalState.context.workspaceAgentError instanceof Error) {
160-
terminal.writeln(Language.workspaceAgentErrorMessagePrefix + terminalState.context.workspaceAgentError.message)
157+
if (workspaceAgentError instanceof Error) {
158+
terminal.writeln(Language.workspaceAgentErrorMessagePrefix + workspaceAgentError.message)
161159
}
162-
if (terminalState.context.websocketError instanceof Error) {
163-
terminal.writeln(Language.websocketErrorMessagePrefix + terminalState.context.websocketError.message)
160+
if (websocketError instanceof Error) {
161+
terminal.writeln(Language.websocketErrorMessagePrefix + websocketError.message)
164162
}
165163
return
166164
}
@@ -174,6 +172,7 @@ export const TerminalPage: React.FC<{
174172
terminal.focus()
175173
terminal.options = {
176174
disableStdin: false,
175+
windowsMode: workspaceAgent?.operating_system === "windows",
177176
}
178177

179178
// Update the terminal size post-fit.
@@ -185,10 +184,11 @@ export const TerminalPage: React.FC<{
185184
},
186185
})
187186
}, [
188-
terminalState.context.workspaceError,
189-
terminalState.context.organizationsError,
190-
terminalState.context.workspaceAgentError,
191-
terminalState.context.websocketError,
187+
workspaceError,
188+
organizationsError,
189+
workspaceAgentError,
190+
websocketError,
191+
workspaceAgent,
192192
terminal,
193193
fitAddon,
194194
isConnected,

site/src/testHelpers/entities.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const MockWorkspace: Workspace = {
102102
export const MockWorkspaceAgent: WorkspaceAgent = {
103103
id: "test-workspace-agent",
104104
name: "a-workspace-agent",
105+
operating_system: "linux",
105106
}
106107

107108
export const MockWorkspaceResource: WorkspaceResource = {

site/src/xServices/terminal/terminalXService.ts

+9-18
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,20 @@ export const terminalMachine =
167167
const agentName = workspaceNameParts[1]
168168

169169
const resources = await API.getWorkspaceResources(context.workspace.latest_build.id)
170-
for (let i = 0; i < resources.length; i++) {
171-
const resource = resources[i]
172-
if (!resource.agents) {
173-
continue
174-
}
175-
if (resource.agents.length <= 0) {
176-
continue
170+
171+
const agent = resources.map((resource) => {
172+
if (!resource.agents || resource.agents.length < 1) {
173+
return
177174
}
178175
if (!agentName) {
179176
return resource.agents[0]
180177
}
181-
for (let a = 0; a < resource.agents.length; a++) {
182-
const agent = resource.agents[a]
183-
if (agent.name !== agentName) {
184-
continue
185-
}
186-
return agent
187-
}
178+
return resource.agents.find((agent) => agent.name === agentName)
179+
}).filter(a => a)[0]
180+
if (!agent) {
181+
throw new Error("no agent found with id")
188182
}
189-
throw new Error("no agent found with id")
183+
return agent
190184
},
191185
connect: (context: TerminalContext) => (send) => {
192186
return new Promise<WebSocket>((resolve, reject) => {
@@ -275,9 +269,6 @@ export const terminalMachine =
275269
}
276270
context.websocket.send(new TextEncoder().encode(JSON.stringify(event.request)))
277271
},
278-
readMessage: () => {
279-
// Override this with the terminal writer!
280-
},
281272
disconnect: (context: TerminalContext) => {
282273
// Code 1000 is a successful exit!
283274
context.websocket?.close(1000)

0 commit comments

Comments
 (0)