2024-08-22 00:04:39 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
import { app, ipcMain } from "electron";
|
|
|
|
import os from "os";
|
|
|
|
import path from "path";
|
2024-09-18 21:06:34 +02:00
|
|
|
import { WaveDevVarName, WaveDevViteVarName } from "../frontend/util/isdev";
|
2024-08-22 00:04:39 +02:00
|
|
|
import * as keyutil from "../frontend/util/keyutil";
|
|
|
|
|
2024-09-26 01:16:07 +02:00
|
|
|
const WaveHomeVarName = "WAVETERM_HOME";
|
|
|
|
|
2024-08-22 00:04:39 +02:00
|
|
|
const isDev = !app.isPackaged;
|
|
|
|
const isDevVite = isDev && process.env.ELECTRON_RENDERER_URL;
|
|
|
|
if (isDev) {
|
|
|
|
process.env[WaveDevVarName] = "1";
|
|
|
|
}
|
|
|
|
if (isDevVite) {
|
|
|
|
process.env[WaveDevViteVarName] = "1";
|
|
|
|
}
|
|
|
|
|
2024-09-19 23:04:47 +02:00
|
|
|
app.setName(isDev ? "Wave (Dev)" : "Wave");
|
2024-08-22 00:04:39 +02:00
|
|
|
const unamePlatform = process.platform;
|
2024-09-04 20:23:39 +02:00
|
|
|
const unameArch: string = process.arch;
|
2024-08-22 00:04:39 +02:00
|
|
|
keyutil.setKeyUtilPlatform(unamePlatform);
|
|
|
|
|
|
|
|
ipcMain.on("get-is-dev", (event) => {
|
|
|
|
event.returnValue = isDev;
|
|
|
|
});
|
|
|
|
ipcMain.on("get-platform", (event, url) => {
|
|
|
|
event.returnValue = unamePlatform;
|
|
|
|
});
|
2024-08-28 03:49:49 +02:00
|
|
|
ipcMain.on("get-user-name", (event) => {
|
|
|
|
const userInfo = os.userInfo();
|
|
|
|
event.returnValue = userInfo.username;
|
|
|
|
});
|
2024-09-06 03:54:12 +02:00
|
|
|
ipcMain.on("get-host-name", (event) => {
|
|
|
|
event.returnValue = os.hostname();
|
|
|
|
});
|
2024-10-05 01:34:05 +02:00
|
|
|
ipcMain.on("get-webview-preload", (event) => {
|
|
|
|
event.returnValue = path.join(getElectronAppBasePath(), "preload", "preload-webview.cjs");
|
|
|
|
});
|
2024-08-22 00:04:39 +02:00
|
|
|
|
|
|
|
// must match golang
|
|
|
|
function getWaveHomeDir() {
|
2024-09-26 01:16:07 +02:00
|
|
|
const override = process.env[WaveHomeVarName];
|
|
|
|
if (override) {
|
|
|
|
return override;
|
|
|
|
}
|
2024-09-06 00:01:28 +02:00
|
|
|
return path.join(os.homedir(), isDev ? ".waveterm-dev" : ".waveterm");
|
2024-08-22 00:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getElectronAppBasePath(): string {
|
2024-09-17 00:58:35 +02:00
|
|
|
return path.dirname(import.meta.dirname);
|
2024-08-22 00:04:39 +02:00
|
|
|
}
|
|
|
|
|
2024-10-04 05:28:05 +02:00
|
|
|
function getElectronAppUnpackedBasePath(): string {
|
2024-08-22 00:04:39 +02:00
|
|
|
return getElectronAppBasePath().replace("app.asar", "app.asar.unpacked");
|
|
|
|
}
|
|
|
|
|
|
|
|
const wavesrvBinName = `wavesrv.${unameArch}`;
|
|
|
|
|
|
|
|
function getWaveSrvPath(): string {
|
|
|
|
if (process.platform === "win32") {
|
|
|
|
const winBinName = `${wavesrvBinName}.exe`;
|
2024-10-04 05:28:05 +02:00
|
|
|
const appPath = path.join(getElectronAppUnpackedBasePath(), "bin", winBinName);
|
2024-08-22 00:04:39 +02:00
|
|
|
return `${appPath}`;
|
|
|
|
}
|
2024-10-04 05:28:05 +02:00
|
|
|
return path.join(getElectronAppUnpackedBasePath(), "bin", wavesrvBinName);
|
2024-08-22 00:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getWaveSrvCwd(): string {
|
|
|
|
return getWaveHomeDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
getElectronAppBasePath,
|
2024-10-04 05:28:05 +02:00
|
|
|
getElectronAppUnpackedBasePath,
|
2024-08-22 00:04:39 +02:00
|
|
|
getWaveHomeDir,
|
|
|
|
getWaveSrvCwd,
|
|
|
|
getWaveSrvPath,
|
|
|
|
isDev,
|
|
|
|
isDevVite,
|
|
|
|
unameArch,
|
|
|
|
unamePlatform,
|
|
|
|
};
|