Skip to content

Commit

Permalink
[menu-bar][electron] Fix support for runCli env vars (#180)
Browse files Browse the repository at this point in the history
* [menu-bar][electron] Fix support for runCli env vars

* Fix Input text color on web

* Add changelog entry
  • Loading branch information
gabrieldonadel authored Feb 16, 2024
1 parent cd682f8 commit 93edb60
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions apps/menu-bar/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions apps/menu-bar/electron/vite.main.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/],
},
},
});
4 changes: 4 additions & 0 deletions apps/menu-bar/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion apps/menu-bar/modules/menu-bar/electron/main.ts
Original file line number Diff line number Diff line change
@@ -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.UserSettingsData>(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;
};

Expand All @@ -33,6 +45,10 @@ const MenuBarModule: Partial<NativeMenuBarModule> & { name: string } = {

return response;
},
setEnvVars(envVars) {
const userSettingsJsonFile = getUserSettingsJsonFile();
userSettingsJsonFile.setAsync('envVars', envVars);
},
};

export default MenuBarModule;
10 changes: 8 additions & 2 deletions apps/menu-bar/modules/menu-bar/electron/spawnCliAsync.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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<string, string> = {}
) {
let child: ChildProcess;
let hasReachedReturnOutput = false;
let hasReachedError = false;
let returnOutput = '';

const promise = new Promise<string>((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',
});

Expand Down
5 changes: 5 additions & 0 deletions packages/common-types/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
};

0 comments on commit 93edb60

Please sign in to comment.