Skip to content

Commit d58b133

Browse files
committed
Detect if swiftly is already installed
1 parent 25a4344 commit d58b133

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
@@ -115,7 +115,7 @@ export class Swiftly {
115115
}
116116
}
117117

118-
private static isSupported() {
118+
public static isSupported() {
119119
return process.platform === "linux" || process.platform === "darwin";
120120
}
121121

@@ -172,4 +172,22 @@ export class Swiftly {
172172
);
173173
return JSON.parse(swiftlyConfigRaw);
174174
}
175+
176+
public static async isInstalled() {
177+
178+
if(!Swiftly.isSupported()) {
179+
return false;
180+
}
181+
182+
try {
183+
await Swiftly.version();
184+
return true;
185+
} catch (error) {
186+
if (error instanceof ExecFileError && 'code' in error && error.code === "ENOENT") {
187+
return false;
188+
}
189+
throw error;
190+
}
191+
192+
}
175193
}

src/ui/ToolchainSelection.ts

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

0 commit comments

Comments
 (0)