Skip to content

Commit

Permalink
Use environment variables instead of command-line arguments in Electr…
Browse files Browse the repository at this point in the history
…on app
  • Loading branch information
somebody1234 committed Aug 9, 2023
1 parent dc9f902 commit e350ced
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
7 changes: 5 additions & 2 deletions app/ide-desktop/lib/client/electron-builder-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ export function createElectronBuilderConfig(passedArgs: Arguments): electronBuil
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
appBundleId: macBuildOptions.appId!,
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
// It is a mistake for either of these to be undefined.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
appleId: process.env.APPLEID!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
appleIdPassword: process.env.APPLEIDPASS!,
})
}
},
Expand Down
19 changes: 12 additions & 7 deletions app/ide-desktop/lib/client/src/bin/project-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,37 @@ export function pathOrPanic(args: config.Args): string {
}

/** Execute the Project Manager with given arguments. */
async function exec(args: config.Args, processArgs: string[]) {
async function exec(args: config.Args, processArgs: string[], env?: NodeJS.ProcessEnv) {
const binPath = pathOrPanic(args)
return await execFile(binPath, processArgs)
return await execFile(binPath, processArgs, { env })
}

/** Spawn the Project Manager process.
*
* The standard output and error handles will be redirected to the output and error handles of the
* Electron app. Input is piped to this process, so it will not be closed until this process
* finishes. */
export function spawn(args: config.Args, processArgs: string[]): childProcess.ChildProcess {
export function spawn(
args: config.Args,
processArgs: string[],
env?: NodeJS.ProcessEnv
): childProcess.ChildProcess {
return logger.groupMeasured(
`Starting the backend process with the following options: ${processArgs.join(', ')}.`,
() => {
const binPath = pathOrPanic(args)
const process = childProcess.spawn(binPath, processArgs, {
const pmProcess = childProcess.spawn(binPath, processArgs, {
stdio: [/* stdin */ 'pipe', /* stdout */ 'inherit', /* stderr */ 'inherit'],
env,
// The Project Manager should never spawn any windows. On Windows OS this needs
// to be manually prevented, as the default is to spawn a console window.
windowsHide: true,
})
logger.log(`Backend has been spawned (pid = ${String(process.pid)}).`)
process.on('exit', code => {
logger.log(`Backend has been spawned (pid = ${String(pmProcess.pid)}).`)
pmProcess.on('exit', code => {
logger.log(`Backend exited with code ${String(code)}.`)
})
return process
return pmProcess
}
)
}
Expand Down
15 changes: 9 additions & 6 deletions app/ide-desktop/lib/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ class App {
})
const projectManagerUrl = `ws://${this.projectManagerHost}:${this.projectManagerPort}`
this.args.groups.engine.options.projectManagerUrl.value = projectManagerUrl
const backendOpts = [
...(this.args.groups.debug.options.verbose.value ? ['-vv'] : []),
`--server-host=${this.projectManagerHost}`,
`--server-port=${this.projectManagerPort}`,
]
projectManager.spawn(this.args, backendOpts)
const backendOpts = this.args.groups.debug.options.verbose.value ? ['-vv'] : []
const backendEnv = Object.assign({}, process.env, {
// These are environment variables, and MUST be in CONSTANT_CASE.
// eslint-disable-next-line @typescript-eslint/naming-convention
SERVER_HOST: this.projectManagerHost,
// eslint-disable-next-line @typescript-eslint/naming-convention
SERVER_PORT: `${this.projectManagerPort}`,
})
projectManager.spawn(this.args, backendOpts, backendEnv)
})
}

Expand Down
5 changes: 3 additions & 2 deletions app/ide-desktop/lib/types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ declare global {
namespace NodeJS {
/** */
interface ProcessEnv {
// These are environment variables, and MUST be in CONSTANT_CASE.
/* eslint-disable @typescript-eslint/naming-convention */
APPLEID: string
APPLEIDPASS: string
APPLEID?: string
APPLEIDPASS?: string
/* eslint-enable @typescript-eslint/naming-convention */
}
}
Expand Down

0 comments on commit e350ced

Please sign in to comment.