Skip to content

Commit

Permalink
Show unsupported platforms error message (#638)
Browse files Browse the repository at this point in the history
This PR fixes fixes issue where error messages for unsupported platforms
were not displayed and prevents Xcode errors from appearing on Windows
by ensuring the checkXcodeExists function is only executed on macOS.

Previously, an error related to the OS const in `platform.ts` was always
thrown before the check in `extension.ts`. This change ensures the
verification process happens correctly.

Fixes #620 

### How Has This Been Tested: 
- run extension on currently unsupported platform (linux)
- run extension and check the logs for any errors caused by xcrun on
Windows


![image](https://github.com/user-attachments/assets/e509d0c1-ea0d-41da-bd01-3bee60c44989)
  • Loading branch information
p-malecki authored Oct 18, 2024
1 parent 79675ad commit 7966b77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
],
"version": "0.0.20",
"engines": {
"vscode": "^1.75.0",
"os": "darwin"
"vscode": "^1.75.0"
},
"extensionKind": [
"workspace"
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/devices/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class DeviceManager implements DeviceManagerInterface {

let shouldLoadSimulators = Platform.OS === "macos";

if (!(await checkXcodeExists())) {
if (shouldLoadSimulators && !(await checkXcodeExists())) {
shouldLoadSimulators = false;
Logger.debug("Couldn't list iOS simulators as XCode installation wasn't found");
}
Expand Down
7 changes: 4 additions & 3 deletions packages/vscode-extension/src/utilities/platform.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import os from "os";

const OS: "macos" | "windows" = (() => {
const OS: "macos" | "windows" | "unsupported" = (() => {
const platform = os.platform();
switch (platform) {
case "darwin":
return "macos";
case "win32":
return "windows";
default:
throw new Error("Unsupported platform");
return "unsupported";
}
})();
export const Platform = {
OS,
select: <R, T>(obj: { macos: R; windows: T }) => {
return obj[Platform.OS];
// we assume that the 'unsupported' OS type will never occur here
return Platform.OS !== "unsupported" ? obj[Platform.OS] : obj["macos"];
},
};

Expand Down

0 comments on commit 7966b77

Please sign in to comment.