From 93edb607c302ac1aa8cf7ad6627ecf485cc37d23 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Fri, 16 Feb 2024 12:14:35 -0800 Subject: [PATCH] [menu-bar][electron] Fix support for runCli env vars (#180) * [menu-bar][electron] Fix support for runCli env vars * Fix Input text color on web * Add changelog entry --- CHANGELOG.md | 2 +- apps/menu-bar/electron/package.json | 2 ++ apps/menu-bar/electron/vite.main.config.ts | 8 ++++++++ apps/menu-bar/global.css | 4 ++++ .../menu-bar/modules/menu-bar/electron/main.ts | 18 +++++++++++++++++- .../modules/menu-bar/electron/spawnCliAsync.ts | 10 ++++++++-- packages/common-types/src/storage.ts | 5 +++++ 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 433b8b66..36dc68c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### 🎉 New features - Add support for launching Expo updates. ([#134](https://github.com/expo/orbit/pull/134), [#137](https://github.com/expo/orbit/pull/137), [#138](https://github.com/expo/orbit/pull/138), [#144](https://github.com/expo/orbit/pull/144), [#148](https://github.com/expo/orbit/pull/148) by [@gabrieldonadel](https://github.com/gabrieldonadel)) -- Add experimental support for Windows and Linux. ([#152](https://github.com/expo/orbit/pull/152), [#157](https://github.com/expo/orbit/pull/157), [#158](https://github.com/expo/orbit/pull/158), [#160](https://github.com/expo/orbit/pull/160), [#161](https://github.com/expo/orbit/pull/161), [#165](https://github.com/expo/orbit/pull/165), [#170](https://github.com/expo/orbit/pull/170), [#171](https://github.com/expo/orbit/pull/171), [#172](https://github.com/expo/orbit/pull/172), [#173](https://github.com/expo/orbit/pull/173), [#174](https://github.com/expo/orbit/pull/174), [#175](https://github.com/expo/orbit/pull/175), [#177](https://github.com/expo/orbit/pull/177), [#178](https://github.com/expo/orbit/pull/178) by [@gabrieldonadel](https://github.com/gabrieldonadel)) +- Add experimental support for Windows and Linux. ([#152](https://github.com/expo/orbit/pull/152), [#157](https://github.com/expo/orbit/pull/157), [#158](https://github.com/expo/orbit/pull/158), [#160](https://github.com/expo/orbit/pull/160), [#161](https://github.com/expo/orbit/pull/161), [#165](https://github.com/expo/orbit/pull/165), [#170](https://github.com/expo/orbit/pull/170), [#171](https://github.com/expo/orbit/pull/171), [#172](https://github.com/expo/orbit/pull/172), [#173](https://github.com/expo/orbit/pull/173), [#174](https://github.com/expo/orbit/pull/174), [#175](https://github.com/expo/orbit/pull/175), [#177](https://github.com/expo/orbit/pull/177), [#178](https://github.com/expo/orbit/pull/178), [#180](https://github.com/expo/orbit/pull/180) by [@gabrieldonadel](https://github.com/gabrieldonadel)) ### 🐛 Bug fixes diff --git a/apps/menu-bar/electron/package.json b/apps/menu-bar/electron/package.json index 61429f36..82884a97 100644 --- a/apps/menu-bar/electron/package.json +++ b/apps/menu-bar/electron/package.json @@ -28,6 +28,8 @@ "typescript": "~4.9.4" }, "dependencies": { + "@expo/json-file": "^8.2.37", + "common-types": "1.0.0", "electron-squirrel-startup": "^1.0.0", "express": "^4.18.2", "react-native-electron-modules": "1.0.0" diff --git a/apps/menu-bar/electron/vite.main.config.ts b/apps/menu-bar/electron/vite.main.config.ts index c93ad038..85d3b4da 100644 --- a/apps/menu-bar/electron/vite.main.config.ts +++ b/apps/menu-bar/electron/vite.main.config.ts @@ -7,4 +7,12 @@ export default defineConfig({ browserField: false, mainFields: ['module', 'jsnext:main', 'jsnext'], }, + optimizeDeps: { + include: ['common-types'], + }, + build: { + commonjsOptions: { + include: [/common-types/, /node_modules/], + }, + }, }); diff --git a/apps/menu-bar/global.css b/apps/menu-bar/global.css index 7b233ff1..7a84fcbb 100644 --- a/apps/menu-bar/global.css +++ b/apps/menu-bar/global.css @@ -2,6 +2,10 @@ body { background-color: var(--orbit-window-background); } +input { + color: var(--text-color); +} + :not(input):not(textarea), :not(input):not(textarea)::after, :not(input):not(textarea)::before { diff --git a/apps/menu-bar/modules/menu-bar/electron/main.ts b/apps/menu-bar/modules/menu-bar/electron/main.ts index fbb15dc8..b7ef2af5 100644 --- a/apps/menu-bar/modules/menu-bar/electron/main.ts +++ b/apps/menu-bar/modules/menu-bar/electron/main.ts @@ -1,13 +1,25 @@ +import JsonFile from '@expo/json-file'; +import { StorageUtils } from 'common-types'; import { app, dialog } from 'electron'; +import os from 'os'; import path from 'path'; import spawnCliAsync from './spawnCliAsync'; import { NativeMenuBarModule } from '../src/types'; +function getUserSettingsJsonFile() { + return new JsonFile(StorageUtils.userSettingsFile(os.homedir()), { + jsonParseErrorDefault: {}, + cantReadFileDefault: {}, + }); +} + const runCli = async (command: string, args: string[], listenerId: number) => { const cliPath = path.join(__dirname, '../../../../cli/build/index.js'); - const commandOutput = await spawnCliAsync(cliPath, command, args, listenerId); + const userSettingsJsonFile = getUserSettingsJsonFile(); + const { envVars } = await userSettingsJsonFile.readAsync(); + const commandOutput = await spawnCliAsync(cliPath, command, args, listenerId, envVars); return commandOutput; }; @@ -33,6 +45,10 @@ const MenuBarModule: Partial & { name: string } = { return response; }, + setEnvVars(envVars) { + const userSettingsJsonFile = getUserSettingsJsonFile(); + userSettingsJsonFile.setAsync('envVars', envVars); + }, }; export default MenuBarModule; diff --git a/apps/menu-bar/modules/menu-bar/electron/spawnCliAsync.ts b/apps/menu-bar/modules/menu-bar/electron/spawnCliAsync.ts index 4da994fe..19dc818a 100644 --- a/apps/menu-bar/modules/menu-bar/electron/spawnCliAsync.ts +++ b/apps/menu-bar/modules/menu-bar/electron/spawnCliAsync.ts @@ -1,6 +1,12 @@ import { fork, ChildProcess } from 'child_process'; -function spawnCliAsync(cliPath: string, command: string, args: string[] = [], listenerId: number) { +function spawnCliAsync( + cliPath: string, + command: string, + args: string[] = [], + listenerId: number, + envVars: Record = {} +) { let child: ChildProcess; let hasReachedReturnOutput = false; let hasReachedError = false; @@ -8,7 +14,7 @@ function spawnCliAsync(cliPath: string, command: string, args: string[] = [], li const promise = new Promise((resolve, reject) => { child = fork(cliPath, [command, ...args], { - env: { ...process.env, EXPO_MENU_BAR: true } as any, + env: { ...process.env, EXPO_MENU_BAR: true, ...envVars } as any, stdio: 'pipe', }); diff --git a/packages/common-types/src/storage.ts b/packages/common-types/src/storage.ts index 5d41943f..7472576b 100644 --- a/packages/common-types/src/storage.ts +++ b/packages/common-types/src/storage.ts @@ -8,3 +8,8 @@ export function getExpoOrbitDirectory(homedir: string) { export function userSettingsFile(homedir: string): string { return `${getExpoOrbitDirectory(homedir)}/${AUTH_FILE_NAME}`; } + +export type UserSettingsData = { + sessionSecret?: string; + envVars?: Record; +};