From 7966b7715abb883b7fa04d1f19be292e83362614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Ma=C5=82ecki?= <92953623+p-malecki@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:53:07 +0000 Subject: [PATCH] Show unsupported platforms error message (#638) 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) --- packages/vscode-extension/package.json | 3 +-- packages/vscode-extension/src/devices/DeviceManager.ts | 2 +- packages/vscode-extension/src/utilities/platform.ts | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index c1c796eea..a8633c7fd 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -17,8 +17,7 @@ ], "version": "0.0.20", "engines": { - "vscode": "^1.75.0", - "os": "darwin" + "vscode": "^1.75.0" }, "extensionKind": [ "workspace" diff --git a/packages/vscode-extension/src/devices/DeviceManager.ts b/packages/vscode-extension/src/devices/DeviceManager.ts index bf2b6ef74..41af3ceb2 100644 --- a/packages/vscode-extension/src/devices/DeviceManager.ts +++ b/packages/vscode-extension/src/devices/DeviceManager.ts @@ -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"); } diff --git a/packages/vscode-extension/src/utilities/platform.ts b/packages/vscode-extension/src/utilities/platform.ts index 47948b408..7303e6517 100644 --- a/packages/vscode-extension/src/utilities/platform.ts +++ b/packages/vscode-extension/src/utilities/platform.ts @@ -1,6 +1,6 @@ import os from "os"; -const OS: "macos" | "windows" = (() => { +const OS: "macos" | "windows" | "unsupported" = (() => { const platform = os.platform(); switch (platform) { case "darwin": @@ -8,13 +8,14 @@ const OS: "macos" | "windows" = (() => { case "win32": return "windows"; default: - throw new Error("Unsupported platform"); + return "unsupported"; } })(); export const Platform = { OS, select: (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"]; }, };