MCPcopy
hub / github.com/coder/mux / PortableDesktopSession

Class PortableDesktopSession

src/node/services/desktop/PortableDesktopSession.ts:96–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96export class PortableDesktopSession {
97 private binaryPath: string | null = null;
98 private width: number | null = null;
99 private height: number | null = null;
100 private vncPort: number | null = null;
101 private sessionId: string | undefined;
102 private stateFile: string | null = null;
103
104 constructor(
105 private readonly options: {
106 workspaceId: string;
107 rootDir: string;
108 width?: number;
109 height?: number;
110 }
111 ) {}
112
113 static resolveBinary(rootDir: string): string {
114 return resolvePortableDesktopBinary(rootDir);
115 }
116
117 static checkAvailability(rootDir: string): boolean {
118 try {
119 PortableDesktopSession.resolveBinary(rootDir);
120 return true;
121 } catch (error) {
122 if (error instanceof PortableDesktopBinaryNotFoundError) {
123 return false;
124 }
125 throw error;
126 }
127 }
128
129 private resolveBinary(): string {
130 return PortableDesktopSession.resolveBinary(this.options.rootDir);
131 }
132
133 private parseStartupInfo(rawLine: string): PortableDesktopStartupInfo {
134 let parsed: unknown;
135 try {
136 parsed = JSON.parse(rawLine);
137 } catch (error) {
138 throw new Error(
139 `Failed to parse PortableDesktop startup JSON line for workspace ${this.options.workspaceId}: ${getErrorMessage(error)}`
140 );
141 }
142
143 assert(isRecord(parsed), "PortableDesktop startup output must be a JSON object");
144
145 const geometry = parsed.geometry;
146 const vncPort = parsed.vncPort;
147 const stateFile = parsed.stateFile;
148
149 assert(typeof geometry === "string", "PortableDesktop startup geometry must be a string");
150 const geometryMatch = /^(\d+)x(\d+)$/i.exec(geometry.trim());
151 assert(
152 geometryMatch != null,
153 'PortableDesktop startup geometry must use the format "WIDTHxHEIGHT"'

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected