mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
30 lines
803 B
TypeScript
30 lines
803 B
TypeScript
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { getApi } from "@/app/store/global";
|
|
|
|
function getWindow(): Window {
|
|
return globalThis.window;
|
|
}
|
|
|
|
function getProcess(): NodeJS.Process {
|
|
return globalThis.process;
|
|
}
|
|
|
|
/**
|
|
* Gets an environment variable from the host process, either directly or via IPC if called from the browser.
|
|
* @param paramName The name of the environment variable to attempt to retrieve.
|
|
* @returns The value of the environment variable or null if not present.
|
|
*/
|
|
export function getEnv(paramName: string): string {
|
|
const win = getWindow();
|
|
if (win != null) {
|
|
return getApi().getEnv(paramName);
|
|
}
|
|
const proc = getProcess();
|
|
if (proc != null) {
|
|
return proc.env[paramName];
|
|
}
|
|
return null;
|
|
}
|