Skip to content

Commit 81c8a22

Browse files
committed
Detect if swiftly is already installed
1 parent b804284 commit 81c8a22

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/toolchain/swiftly.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class Swiftly {
158158
}
159159
}
160160

161-
private static isSupported() {
161+
public static isSupported() {
162162
return process.platform === "linux" || process.platform === "darwin";
163163
}
164164

@@ -245,4 +245,22 @@ export class Swiftly {
245245
);
246246
return JSON.parse(swiftlyConfigRaw);
247247
}
248+
249+
public static async isInstalled() {
250+
251+
if(!Swiftly.isSupported()) {
252+
return false;
253+
}
254+
255+
try {
256+
await Swiftly.version();
257+
return true;
258+
} catch (error) {
259+
if (error instanceof ExecFileError && 'code' in error && error.code === "ENOENT") {
260+
return false;
261+
}
262+
throw error;
263+
}
264+
265+
}
248266
}

src/ui/ToolchainSelection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async function getQuickPickItems(
257257
}
258258
// Various actions that the user can perform (e.g. to install new toolchains)
259259
const actionItems: ActionItem[] = [];
260-
if (process.platform === "linux" || process.platform === "darwin") {
260+
if (Swiftly.isSupported() && !(await Swiftly.isInstalled())) {
261261
const platformName = process.platform === "linux" ? "Linux" : "macOS";
262262
actionItems.push({
263263
type: "action",

0 commit comments

Comments
 (0)