Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Linux support for VSCode extension (#688) #829

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const EMULATOR_BINARY = path.join(
Platform.select({
macos: "emulator",
windows: "emulator.exe",
linux: "emulator",
})
);
const ADB_PATH = path.join(
Expand All @@ -34,6 +35,7 @@ const ADB_PATH = path.join(
Platform.select({
macos: "adb",
windows: "adb.exe",
linux: "adb",
})
);
const DISPOSE_TIMEOUT = 9000;
Expand Down Expand Up @@ -697,8 +699,9 @@ async function ensureOldEmulatorProcessExited(avdId: string) {
macos: "ps",
windows:
'powershell.exe "Get-WmiObject Win32_Process | Select-Object ProcessId, CommandLine | ConvertTo-Csv -NoTypeInformation"',
linux: "ps",
});
const args = Platform.select({ macos: ["-Ao", "pid,command"], windows: [] });
const args = Platform.select({ macos: ["-Ao", "pid,command"], windows: [], linux: ["-Ao", "pid,command"] });
const subprocess = exec(command, args);
const regexpPattern = new RegExp(`(\\d+).*qemu.*-avd ${avdId}`);
lineReader(subprocess).onLineRead(async (line) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export function deactivate(context: ExtensionContext): undefined {
export async function activate(context: ExtensionContext) {
handleUncaughtErrors();

if (Platform.OS !== "macos" && Platform.OS !== "windows") {
window.showErrorMessage("Radon IDE works only on macOS and Windows.", "Dismiss");
if (Platform.OS !== "macos" && Platform.OS !== "windows" && Platform.OS !== "linux") {
window.showErrorMessage("Radon IDE works only on macOS and Windows and Linux.", "Dismiss");
return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/vscode-extension/src/utilities/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ANDROID_HOME =
Platform.select({
macos: path.join(os.homedir(), "Library/Android/sdk"),
windows: path.join(os.homedir(), "AppData\\Local\\Android\\Sdk"),
linux: path.join(os.homedir(), "Android/Sdk"),
});

export async function findJavaHome() {
Expand Down Expand Up @@ -36,11 +37,13 @@ export async function findJavaHome() {
const androidStudioPath = Platform.select({
macos: "/Applications/Android Studio.app",
windows: path.join(path.parse(os.homedir()).root, "Program Files\\Android\\Android Studio"),
linux: "/usr/local/android-studio",
});

const jbrPath = Platform.select({
macos: path.join(androidStudioPath, "Contents/jbr/Contents/Home"),
windows: path.join(androidStudioPath, "jbr"),
linux: path.join(androidStudioPath, "jbr"),
});

if (fs.existsSync(jbrPath)) {
Expand All @@ -50,5 +53,8 @@ export async function findJavaHome() {
return Platform.select({
macos: path.join(androidStudioPath, "Contents/jre/Contents/Home"),
windows: path.join(androidStudioPath, "jre"),
// Returning undefined as the Android Studio directory on Linux
// might not include a jre directory, preferring jbr instead
linux: undefined,
});
}
6 changes: 4 additions & 2 deletions packages/vscode-extension/src/utilities/platform.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os from "os";

const OS: "macos" | "windows" | "unsupported" = (() => {
const OS: "macos" | "windows" | "linux" | "unsupported" = (() => {
const platform = os.platform();
switch (platform) {
case "darwin":
return "macos";
case "win32":
return "windows";
case "linux":
return "linux";
default:
return "unsupported";
}
})();
export const Platform = {
OS,
select: <R, T>(obj: { macos: R; windows: T }) => {
select: <R, T>(obj: { macos: R; windows: T; linux: T }) => {
// we assume that the 'unsupported' OS type will never occur here
return Platform.OS !== "unsupported" ? obj[Platform.OS] : obj["macos"];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function simulatorServerBinary() {
return path.join(
extensionContext.extensionPath,
"dist",
Platform.select({ macos: "simulator-server-macos", windows: "simulator-server-windows.exe" })
Platform.select({
macos: "simulator-server-macos",
windows: "simulator-server-windows.exe",
linux: "simulator-server-linux",
})
);
}
6 changes: 3 additions & 3 deletions packages/vscode-extension/src/utilities/subprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function exec(
const subprocess = execa(
name,
args,
Platform.select({ macos: overrideEnv(options), windows: options })
Platform.select({ macos: overrideEnv(options), windows: options, linux: options })
);
const allowNonZeroExit = options?.allowNonZeroExit;
async function printErrorsOnExit() {
Expand Down Expand Up @@ -122,7 +122,7 @@ export function execSync(name: string, args?: string[], options?: execa.SyncOpti
const result = execa.sync(
name,
args,
Platform.select({ macos: overrideEnv(options), windows: options })
Platform.select({ macos: overrideEnv(options), windows: options, linux: options })
);
if (result.stderr) {
Logger.debug("Subprocess", name, args?.join(" "), "produced error output:", result.stderr);
Expand All @@ -136,7 +136,7 @@ export function command(
) {
const subprocess = execa.command(
commandWithArgs,
Platform.select({ macos: overrideEnv(options), windows: options })
Platform.select({ macos: overrideEnv(options), windows: options, linux: options })
);
async function printErrorsOnExit() {
try {
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode-extension/src/utilities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Utils implements UtilsInterface {
Platform.select({
macos: path.join("Library", "Application Support"),
windows: path.join("AppDat", "Roaming"),
linux: path.join(".config"),
}),
ideName,
"User",
Expand Down Expand Up @@ -91,6 +92,7 @@ export class Utils implements UtilsInterface {
const defaultFolder = Platform.select({
macos: path.join(homedir(), "Desktop"),
windows: homedir(),
linux: homedir(),
});
const defaultUri = Uri.file(path.join(defaultFolder, newFileName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ function Preview({
const isMultiTouchKey = Platform.select({
macos: e.code === "AltLeft" || e.code === "AltRight",
windows: e.code === "ControlLeft" || e.code === "ControlRight",
linux: e.code === "ControlLeft" || e.code === "ControlRight",
});

const isPanningKey = e.code === "ShiftLeft" || e.code === "ShiftRight";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { UtilsInterface } from "../../common/utils";
declare global {
interface Window {
// set in generateWebviewContent()
RNIDE_hostOS: "macos" | "windows";
RNIDE_hostOS: "macos" | "windows" | "linux";
}
}

export const Platform = {
OS: window.RNIDE_hostOS,
select: <R, T>(obj: { macos: R; windows: T }) => {
select: <R, T>(obj: { macos: R; windows: T; linux: T }) => {
return obj[Platform.OS];
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function useSupportedDevices() {
})),
},
windows: { label: "", items: [] },
linux: { label: "", items: [] },
}),
errors?.emulator
? { label: "Android – error, check diagnostics", items: [] }
Expand Down