mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-31 18:18:02 +01:00
e527e2ab77
With this PR, Electron will generate a new authorization key that the Go backend will look for in any incoming requests. The Electron backend will inject this header with all requests to the backend to ensure no additional work is required on the frontend. This also adds a `fetchutil` abstraction that will use the Electron `net` module when calls are made from the Electron backend to the Go backend. When using the `node:fetch` module, Electron can't inject headers to requests. The Electron `net` module is also faster than the Node module. This also breaks out platform functions in emain into their own file so other emain modules can import them.
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { WaveDevVarName, WaveDevViteVarName } from "@/util/isdev";
|
|
import { app, ipcMain } from "electron";
|
|
import os from "os";
|
|
import path from "path";
|
|
import * as keyutil from "../frontend/util/keyutil";
|
|
|
|
const isDev = !app.isPackaged;
|
|
const isDevVite = isDev && process.env.ELECTRON_RENDERER_URL;
|
|
if (isDev) {
|
|
process.env[WaveDevVarName] = "1";
|
|
}
|
|
if (isDevVite) {
|
|
process.env[WaveDevViteVarName] = "1";
|
|
}
|
|
|
|
app.setName(isDev ? "TheNextWave (Dev)" : "TheNextWave");
|
|
const unamePlatform = process.platform;
|
|
const unameArch: string = process.arch === "x64" ? "amd64" : process.arch;
|
|
keyutil.setKeyUtilPlatform(unamePlatform);
|
|
|
|
ipcMain.on("get-is-dev", (event) => {
|
|
event.returnValue = isDev;
|
|
});
|
|
ipcMain.on("get-platform", (event, url) => {
|
|
event.returnValue = unamePlatform;
|
|
});
|
|
|
|
// must match golang
|
|
function getWaveHomeDir() {
|
|
return path.join(os.homedir(), isDev ? ".w2-dev" : ".w2");
|
|
}
|
|
|
|
function getElectronAppBasePath(): string {
|
|
return path.dirname(__dirname);
|
|
}
|
|
|
|
function getGoAppBasePath(): string {
|
|
return getElectronAppBasePath().replace("app.asar", "app.asar.unpacked");
|
|
}
|
|
|
|
const wavesrvBinName = `wavesrv.${unameArch}`;
|
|
|
|
function getWaveSrvPath(): string {
|
|
if (process.platform === "win32") {
|
|
const winBinName = `${wavesrvBinName}.exe`;
|
|
const appPath = path.join(getGoAppBasePath(), "bin", winBinName);
|
|
return `${appPath}`;
|
|
}
|
|
return path.join(getGoAppBasePath(), "bin", wavesrvBinName);
|
|
}
|
|
|
|
function getWaveSrvCwd(): string {
|
|
return getWaveHomeDir();
|
|
}
|
|
|
|
export {
|
|
getElectronAppBasePath,
|
|
getGoAppBasePath,
|
|
getWaveHomeDir,
|
|
getWaveSrvCwd,
|
|
getWaveSrvPath,
|
|
isDev,
|
|
isDevVite,
|
|
unameArch,
|
|
unamePlatform,
|
|
};
|