Skip to content

Commit c531c62

Browse files
committed
Detect if swiftly is already installed
1 parent 9f02c6e commit c531c62

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
@@ -133,7 +133,7 @@ export class Swiftly {
133133
}
134134
}
135135

136-
private static isSupported() {
136+
public static isSupported() {
137137
return process.platform === "linux" || process.platform === "darwin";
138138
}
139139

@@ -194,4 +194,22 @@ export class Swiftly {
194194
);
195195
return JSON.parse(swiftlyConfigRaw);
196196
}
197+
198+
public static async isInstalled() {
199+
200+
if(!Swiftly.isSupported()) {
201+
return false;
202+
}
203+
204+
try {
205+
await Swiftly.version();
206+
return true;
207+
} catch (error) {
208+
if (error instanceof ExecFileError && 'code' in error && error.code === "ENOENT") {
209+
return false;
210+
}
211+
throw error;
212+
}
213+
214+
}
197215
}

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)