Skip to content

Commit e3dc243

Browse files
committed
Extracts host app name lookup into reusable helper
1 parent fc05e44 commit e3dc243

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/system/-webview/vscode.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,53 @@ import { exists } from './vscode/uris';
1212

1313
export const deviceCohortGroup = getDistributionGroup(env.machineId);
1414

15-
let _hostExecutablePath: string | undefined;
16-
export async function getHostExecutablePath(): Promise<string> {
17-
if (_hostExecutablePath != null) return _hostExecutablePath;
15+
let _hostAppName: string | undefined | null;
16+
export async function getHostAppName(): Promise<string | undefined> {
17+
if (_hostAppName !== undefined) return _hostAppName ?? undefined;
1818

19-
const platform = getPlatform();
20-
21-
let app: string;
2219
switch (env.appName) {
2320
case 'Visual Studio Code':
24-
app = 'code';
21+
_hostAppName = 'code';
2522
break;
2623
case 'Visual Studio Code - Insiders':
27-
app = 'code-insiders';
24+
_hostAppName = 'code-insiders';
2825
break;
2926
case 'Visual Studio Code - Exploration':
30-
app = 'code-exploration';
27+
_hostAppName = 'code-exploration';
3128
break;
3229
case 'VSCodium':
33-
app = 'codium';
30+
_hostAppName = 'codium';
3431
break;
3532
case 'Cursor':
36-
app = 'cursor';
33+
_hostAppName = 'cursor';
3734
break;
3835
case 'Windsurf':
39-
app = 'windsurf';
36+
_hostAppName = 'windsurf';
4037
break;
4138
default: {
4239
try {
4340
const bytes = await workspace.fs.readFile(Uri.file(joinPaths(env.appRoot, 'product.json')));
4441
const product = JSON.parse(new TextDecoder().decode(bytes));
45-
app = product.applicationName;
42+
_hostAppName = product.applicationName;
4643
} catch {
47-
app = 'code';
44+
_hostAppName = null;
4845
}
4946

5047
break;
5148
}
5249
}
5350

51+
return _hostAppName ?? undefined;
52+
}
53+
54+
let _hostExecutablePath: string | undefined;
55+
export async function getHostExecutablePath(): Promise<string> {
56+
if (_hostExecutablePath != null) return _hostExecutablePath;
57+
58+
const platform = getPlatform();
59+
60+
const app = (await getHostAppName()) ?? 'code';
61+
5462
_hostExecutablePath = app;
5563
if (env.remoteName) return app;
5664

0 commit comments

Comments
 (0)