Hardening to prevent reverse engineering.

This commit is contained in:
Patrick Fic
2026-03-20 15:59:01 -07:00
parent fe6dec09db
commit 1b9c04f418
9 changed files with 664 additions and 409 deletions

172
dist-electron/main.cjs Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
console.log("Running preloader!");var{contextBridge:l,ipcRenderer:n}=require("electron");l.exposeInMainWorld("logger",{info:(...e)=>{console.log(...e)},debug:(...e)=>{console.log(...e)},warn:(...e)=>{console.log(...e)},error:(...e)=>{console.log(...e)},silly:(...e)=>{console.log(...e)}});l.exposeInMainWorld("ipcRenderer",{send:(e,o)=>{n.send(e,o)},on:(e,o)=>{n.on(e,o)},invoke:(e,o)=>n.invoke(e,o),removeAllListeners:(...e)=>{n.removeAllListeners(...e)}});

367
electron/main-src.js Normal file
View File

@@ -0,0 +1,367 @@
const path = require("path");
const { app, BrowserWindow, Tray, Menu, ipcMain, dialog, shell, globalShortcut } = require("electron");
const isDev = require("electron-is-dev");
const { default: ipcTypes } = require("../src/ipc.types.commonjs");
const { store } = require("./electron-store");
const { autoUpdater } = require("electron-updater");
const log = require("electron-log");
const contextMenu = require("electron-context-menu");
const Sentry = require("@sentry/electron/main");
//const Nucleus = require("nucleus-nodejs");
require("./ipc-main-handler");
require("./analytics");
Sentry.init({
dsn: "https://9840e0f304124299e379d9347e12d2e6@o492140.ingest.sentry.io/4505728058523648",
ignoreErrors: [
"SimpleURLLoaderWrapper",
"Cannot read properties of null (reading 'webContents')",
"EBUSY: resource busy or locked"
]
});
autoUpdater.autoDownload = true;
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
log.info("App starting...", app.getVersion());
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension, REACT_DEVELOPER_TOOLS;
if (isDev) {
const devTools = require("electron-devtools-installer");
installExtension = devTools.default;
REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
}
var menu = Menu.buildFromTemplate([
{
label: "File",
submenu: [
{
label: "Relaunch",
click() {
app.exit();
app.relaunch();
}
},
{
label: "Clear Settings",
click() {
store.reset("filePaths");
mainWindow.webContents.session.clearStorageData();
}
},
{
label: "Sign Out",
click() {
mainWindow.webContents.send(ipcTypes.app.toRenderer.signOut);
}
},
{
label: "Exit",
click() {
app.quit();
}
}
]
// Other code removed for brevity
},
{
label: isDev ? "DEVELOPMENT -- HELP" : "Help",
submenu: [
{
label: "Rescue",
click() {
shell.openExternal("http://imexrescue.com");
}
},
{
label: `Check for Updates (currently ${app.getVersion()})`,
click() {
checkForUpdates();
}
},
{
label: `Show Release Notes`,
click() {
mainWindow.webContents.send(
ipcTypes.app.toRenderer.setReleaseNotes,
require("./changelog.json")[app.getVersion()]
);
}
},
{
label: "Open Config File",
click() {
shell.openPath(store.path);
}
},
{
label: "Open Log File",
click() {
shell.openPath(path.join(app.getPath("appData"), "ImeX RPS\\logs"));
}
},
{
label: "Third Party Notices",
click() {
openNoticeWindow();
}
}
]
}
]);
let mainWindow;
let noticeWindow;
let tray = null;
contextMenu({ showInspectElement: false });
function createWindow() {
// Create the browser window.
Menu.setApplicationMenu(menu);
mainWindow = new BrowserWindow({
// width: 800,
// height: 600,
title: `ImEX RPS ${app.getVersion()}`,
icon: path.join(__dirname, "../src/assets/logo192.png"),
webPreferences: {
nodeIntegration: false,
enableRemoteModule: false,
webSecurity: true,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
devTools: isDev,
preload: path.join(__dirname, "preload.js") // use a preload script
}
});
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
mainWindow.maximize();
}
});
// and load the index.html of the app.
// win.loadFile("index.html");
mainWindow.loadURL(isDev ? "http://localhost:3000" : `file://${path.join(__dirname, "/../build/index.html")}`);
// mainWindow.on("close", function (event) {
// event.preventDefault();
// mainWindow.hide();
// if (!tray) {
// tray = createTray();
// }
// });
mainWindow.on("minimize", function (event) {
event.preventDefault();
mainWindow.hide();
if (!tray) {
tray = createTray();
}
});
ipcMain.on(ipcTypes.quit, (event, arg) => {
app.isQuiting = true;
app.quit();
});
// Open the DevTools.
if (isDev) {
mainWindow.webContents.openDevTools({
// mode: "detach"
});
}
mainWindow.maximize();
if (isDev) {
globalShortcut.register("CommandOrControl+Shift+I", () => {
mainWindow.webContents.toggleDevTools();
});
}
}
}
exports.mainWindow = mainWindow;
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow();
if (isDev) {
console.log(`Path to Settings File: ${store.path}`);
console.log(`Path to Log File: ${log.log}`);
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((error) => console.log(`An error occurred: , ${error}`));
}
setInterval(() => {
checkForUpdates();
}, 1000 * 60 * 30); //Added auto update check for RPS-38
// ipcMain.on(ipcTypes.default.webcontent, (event, ...obj) => {
// console.log("event", event);
// mainWindow.webContents.send(event, obj);
// });
});
if (isDev) app.setAppUserModelId(process.execPath);
else app.setAppUserModelId("com.imex.rps");
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
console.log("Activate");
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
function createTray() {
let appIcon = new Tray(path.join(__dirname, "../src/assets/logo192.png"));
const contextMenu = Menu.buildFromTemplate([
{
label: "Show",
click: function () {
mainWindow.show();
}
},
{
label: "Exit",
click: function () {
app.isQuiting = true;
app.quit();
}
}
]);
appIcon.on("double-click", function (event) {
mainWindow.show();
mainWindow.maximize();
});
appIcon.setToolTip(`ImEX RPS ${app.getVersion()}`);
appIcon.setContextMenu(contextMenu);
return appIcon;
}
function checkForUpdates() {
try {
autoUpdater.checkForUpdates();
} catch (error) {
log.error("Error checking for updates", error);
}
}
function openNoticeWindow() {
if (noticeWindow) {
noticeWindow.show();
return;
}
noticeWindow = new BrowserWindow({
width: 900,
height: 700,
title: "Third Party Notices",
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
devTools: isDev
}
});
noticeWindow.loadURL(`file://${path.join(__dirname, "licenses.txt")}`);
noticeWindow.on("closed", () => {
noticeWindow = null;
});
}
autoUpdater.on("update-available", (ev) => {
log.log("Update available.", ev);
if (mainWindow) mainWindow.webContents.send(ipcTypes.app.toRenderer.updateAvailable, ev);
});
autoUpdater.on("update-not-available", (ev) => {
log.log("Update not available.", ev);
});
autoUpdater.on("error", (ev, err) => {
log.log("Error in auto-updater.", ev, err);
});
ipcMain.on(ipcTypes.app.toMain.setReleaseChannel, (event, channel) => {
autoUpdater.channel = channel;
checkForUpdates();
});
ipcMain.on(ipcTypes.app.toMain.checkForUpdates, (event, args) => {
checkForUpdates();
});
ipcMain.on(ipcTypes.app.toMain.downloadUpdates, (event, args) => {
//Nucleus.track("DOWNLOAD_UPDATE_FROM_RENDERER");
autoUpdater.downloadUpdate();
});
ipcMain.on(ipcTypes.app.toMain.installUpdates, (event, args) => {
//Nucleus.track("INSTALL_UPDATE_FROM_RENDERER");
const isSilent = true;
const isForceRunAfter = true;
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
});
autoUpdater.on("download-progress", (ev) => {
log.log("Download Progress:", ev);
if (mainWindow) mainWindow.webContents.send(ipcTypes.app.toRenderer.downloadProgress, ev);
});
autoUpdater.on("update-downloaded", (ev, info) => {
//Nucleus.track("UPDATE_DOWNLOADED", ev);
if (mainWindow) {
mainWindow.webContents.send(ipcTypes.app.toRenderer.downloadProgress, {
...ev,
percent: 100
});
}
dialog
.showMessageBox({
type: "info",
title: "ImeX RPS Update Manager",
message: `ImEX RPS is ready to update to Version ${ev.version}. It is highly recommended that you update immediately. Would you like to update now? RPS will automatically restart.`,
buttons: ["Yes", "No"]
})
.then(({ response }) => {
if (response === 0) {
const isSilent = true;
const isForceRunAfter = true;
store.set("showChangeLog", true);
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
} else {
log.warn("Updated ignored.");
}
});
});

View File

@@ -1,356 +1,11 @@
const path = require("path");
const { app, BrowserWindow, Tray, Menu, ipcMain, dialog, shell, globalShortcut } = require("electron");
const isDev = require("electron-is-dev");
const { default: ipcTypes } = require("../src/ipc.types.commonjs");
const { store } = require("./electron-store");
const { autoUpdater } = require("electron-updater");
const log = require("electron-log");
const contextMenu = require("electron-context-menu");
const Sentry = require("@sentry/electron/main");
const fs = require("fs");
//const Nucleus = require("nucleus-nodejs");
require("./ipc-main-handler");
require("./analytics");
// Loader entrypoint:
// - In dev: run the original source (electron/main-src.js)
// - In packaged/prod: run the bundled/minified output (dist-electron/main.cjs)
Sentry.init({
dsn: "https://9840e0f304124299e379d9347e12d2e6@o492140.ingest.sentry.io/4505728058523648",
ignoreErrors: [
"SimpleURLLoaderWrapper",
"Cannot read properties of null (reading 'webContents')",
"EBUSY: resource busy or locked"
]
});
autoUpdater.autoDownload = true;
const distMain = path.join(__dirname, "..", "dist-electron", "main.cjs");
const useDist = !require("electron-is-dev") && fs.existsSync(distMain);
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
log.info("App starting...", app.getVersion());
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension, REACT_DEVELOPER_TOOLS;
if (isDev) {
const devTools = require("electron-devtools-installer");
installExtension = devTools.default;
REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
}
var menu = Menu.buildFromTemplate([
{
label: "File",
submenu: [
{
label: "Relaunch",
click() {
app.exit();
app.relaunch();
}
},
{
label: "Clear Settings",
click() {
store.reset("filePaths");
mainWindow.webContents.session.clearStorageData();
}
},
{
label: "Sign Out",
click() {
mainWindow.webContents.send(ipcTypes.app.toRenderer.signOut);
}
},
{
label: "Exit",
click() {
app.quit();
}
}
]
// Other code removed for brevity
},
{
label: isDev ? "DEVELOPMENT -- HELP" : "Help",
submenu: [
{
label: "Rescue",
click() {
shell.openExternal("http://imexrescue.com");
}
},
{
label: `Check for Updates (currently ${app.getVersion()})`,
click() {
checkForUpdates();
}
},
{
label: `Show Release Notes`,
click() {
mainWindow.webContents.send(
ipcTypes.app.toRenderer.setReleaseNotes,
require("./changelog.json")[app.getVersion()]
);
}
},
{
label: "Open Config File",
click() {
shell.openPath(store.path);
}
},
{
label: "Open Log File",
click() {
shell.openPath(path.join(app.getPath("appData"), "ImeX RPS\\logs"));
}
},
{
label: "Third Party Notices",
click() {
openNoticeWindow();
}
}
]
}
]);
let mainWindow;
let noticeWindow;
let tray = null;
contextMenu({ showInspectElement: false });
function createWindow() {
// Create the browser window.
Menu.setApplicationMenu(menu);
mainWindow = new BrowserWindow({
// width: 800,
// height: 600,
title: `ImEX RPS ${app.getVersion()}`,
icon: path.join(__dirname, "../src/assets/logo192.png"),
webPreferences: {
nodeIntegration: false,
enableRemoteModule: false,
webSecurity: true,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, "preload.js") // use a preload script
}
});
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
mainWindow.maximize();
}
});
// and load the index.html of the app.
// win.loadFile("index.html");
mainWindow.loadURL(isDev ? "http://localhost:3000" : `file://${path.join(__dirname, "/../build/index.html")}`);
// mainWindow.on("close", function (event) {
// event.preventDefault();
// mainWindow.hide();
// if (!tray) {
// tray = createTray();
// }
// });
mainWindow.on("minimize", function (event) {
event.preventDefault();
mainWindow.hide();
if (!tray) {
tray = createTray();
}
});
ipcMain.on(ipcTypes.quit, (event, arg) => {
app.isQuiting = true;
app.quit();
});
// Open the DevTools.
if (isDev) {
mainWindow.webContents.openDevTools({
// mode: "detach"
});
}
mainWindow.maximize();
globalShortcut.register("CommandOrControl+Shift+I", () => {
mainWindow.webContents.toggleDevTools();
});
}
}
exports.mainWindow = mainWindow;
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow();
if (isDev) {
console.log(`Path to Settings File: ${store.path}`);
console.log(`Path to Log File: ${log.log}`);
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((error) => console.log(`An error occurred: , ${error}`));
}
setInterval(() => {
checkForUpdates();
}, 1000 * 60 * 30); //Added auto update check for RPS-38
// ipcMain.on(ipcTypes.default.webcontent, (event, ...obj) => {
// console.log("event", event);
// mainWindow.webContents.send(event, obj);
// });
});
if (isDev) app.setAppUserModelId(process.execPath);
else app.setAppUserModelId("com.imex.rps");
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
console.log("Activate");
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
function createTray() {
let appIcon = new Tray(path.join(__dirname, "../src/assets/logo192.png"));
const contextMenu = Menu.buildFromTemplate([
{
label: "Show",
click: function () {
mainWindow.show();
}
},
{
label: "Exit",
click: function () {
app.isQuiting = true;
app.quit();
}
}
]);
appIcon.on("double-click", function (event) {
mainWindow.show();
mainWindow.maximize();
});
appIcon.setToolTip(`ImEX RPS ${app.getVersion()}`);
appIcon.setContextMenu(contextMenu);
return appIcon;
}
autoUpdater.on("update-available", (ev) => {
log.log("Update available.", ev);
mainWindow.webContents.send(ipcTypes.app.toRenderer.updateAvailable, ev);
});
autoUpdater.on("update-not-available", (ev) => {
log.log("Update not available.", ev);
});
autoUpdater.on("error", (ev, err) => {
log.log("Error in auto-updater.", ev, err);
});
function openNoticeWindow() {
if (noticeWindow) {
noticeWindow.focus();
return;
}
noticeWindow = new BrowserWindow({
height: 600,
width: 800,
title: "ImEX RPS - Third Party Notices"
});
noticeWindow.loadURL("file://" + __dirname + "/licenses.txt");
noticeWindow.on("closed", function () {
noticeWindow = null;
});
}
ipcMain.on(ipcTypes.app.toMain.setReleaseChannel, (event, channel) => {
autoUpdater.channel = channel;
checkForUpdates();
});
ipcMain.on(ipcTypes.app.toMain.checkForUpdates, (event, args) => {
checkForUpdates();
});
ipcMain.on(ipcTypes.app.toMain.downloadUpdates, (event, args) => {
//Nucleus.track("DOWNLOAD_UPDATE_FROM_RENDERER");
autoUpdater.downloadUpdate();
});
ipcMain.on(ipcTypes.app.toMain.installUpdates, (event, args) => {
//Nucleus.track("INSTALL_UPDATE_FROM_RENDERER");
const isSilent = true;
const isForceRunAfter = true;
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
});
autoUpdater.on("download-progress", (ev) => {
log.log("Download Progress:", ev);
mainWindow.webContents.send(ipcTypes.app.toRenderer.downloadProgress, ev);
});
autoUpdater.on("update-downloaded", (ev, info) => {
//Nucleus.track("UPDATE_DOWNLOADED", ev);
// if (process.env.NODE_ENV === "production") {
mainWindow.webContents.send(ipcTypes.app.toRenderer.downloadProgress, {
...ev,
percent: 100
});
dialog
.showMessageBox({
type: "info",
title: "ImeX RPS Update Manager",
message: `ImEX RPS is ready to update to Version ${ev.version}. It is highly recommended that you update immediately. Would you like to update now? RPS will automatically restart.`,
buttons: ["Yes", "No"]
})
.then(({ response }) => {
if (response === 0) {
const isSilent = true;
const isForceRunAfter = true;
store.set("showChangeLog", true);
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
} else {
log.warn("Updated ignored.");
}
});
});
async function checkForUpdates() {
try {
log.info("Checking for updates.");
autoUpdater.checkForUpdates();
} catch (error) {
log.error("Error while checking for update", error);
}
}
require(useDist ? distMain : "./main-src");

55
electron/preload-src.js Normal file
View File

@@ -0,0 +1,55 @@
console.log("Running preloader!");
const { contextBridge, ipcRenderer } = require("electron");
//const log = require("electron-log");
//ipcRenderer.removeAllListeners();
contextBridge.exposeInMainWorld("logger", {
info: (...msg) => {
console.log(...msg);
},
debug: (...msg) => {
console.log(...msg);
},
warn: (...msg) => {
console.log(...msg);
},
error: (...msg) => {
console.log(...msg);
},
silly: (...msg) => {
console.log(...msg);
}
});
contextBridge.exposeInMainWorld("ipcRenderer", {
send: (channel, data) => {
// whitelist channels
// let validChannels = ["toMain"];
// if (validChannels.includes(channel)) {
// log.info("[Main] ipcRenderer Send", channel);
ipcRenderer.send(channel, data);
//}
},
on: (channel, func) => {
// let validChannels = ["fromMain"];
// if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(
channel,
func
///(event, ...args) => func(...args)
);
// }
},
invoke: (channel, data) => {
return ipcRenderer.invoke(channel, data);
},
removeAllListeners: (...channels) => {
// let validChannels = ["fromMain"];
// if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.removeAllListeners(...channels);
// }
}
});

View File

@@ -1,55 +1,11 @@
console.log("Running preloader!");
const { contextBridge, ipcRenderer } = require("electron");
//const log = require("electron-log");
const path = require("path");
const fs = require("fs");
//ipcRenderer.removeAllListeners();
// Loader entrypoint:
// - In dev: run the original source (electron/preload-src.js)
// - In packaged/prod: run the bundled/minified output (dist-electron/preload.cjs)
contextBridge.exposeInMainWorld("logger", {
info: (...msg) => {
console.log(...msg);
},
debug: (...msg) => {
console.log(...msg);
},
warn: (...msg) => {
console.log(...msg);
},
error: (...msg) => {
console.log(...msg);
},
silly: (...msg) => {
console.log(...msg);
},
});
const distPreload = path.join(__dirname, "..", "dist-electron", "preload.cjs");
const useDist = !require("electron-is-dev") && fs.existsSync(distPreload);
contextBridge.exposeInMainWorld("ipcRenderer", {
send: (channel, data) => {
// whitelist channels
// let validChannels = ["toMain"];
// if (validChannels.includes(channel)) {
// log.info("[Main] ipcRenderer Send", channel);
ipcRenderer.send(channel, data);
//}
},
on: (channel, func) => {
// let validChannels = ["fromMain"];
// if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(
channel,
func
///(event, ...args) => func(...args)
);
// }
},
invoke: (channel, data) => {
return ipcRenderer.invoke(channel, data);
},
removeAllListeners: (...channels) => {
// let validChannels = ["fromMain"];
// if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.removeAllListeners(...channels);
// }
},
});
require(useDist ? distPreload : "./preload-src");

View File

@@ -54,12 +54,13 @@
"scripts": {
"start": "vite",
"build": "vite build",
"build:electron": "node scripts/build-electron.mjs",
"dev": "concurrently -k \"npm start\" \"npm:electron\"",
"electron": "electron .",
"pack": "electron-builder --dir",
"dist": "npm run build && electron-builder",
"distp": "npm run build && electron-builder --publish always",
"distnopublish": "npm run build && electron-builder --publish never",
"dist": "npm run build && npm run build:electron && electron-builder",
"distp": "npm run build && npm run build:electron && electron-builder --publish always",
"distnopublish": "npm run build && npm run build:electron && electron-builder --publish never",
"distpnb": "lectron-builder --publish always",
"postinstall": "electron-builder install-app-deps",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org imex --project rps ./build && sentry-cli sourcemaps upload --org imex --project rps ./build"
@@ -81,6 +82,7 @@
},
"devDependencies": {
"concurrently": "^9.1.2",
"esbuild": "^0.25.1",
"electron": "^35.0.1",
"electron-builder": "^25.1.8",
"electron-devtools-installer": "^4.0.0",
@@ -94,6 +96,7 @@
"vite-plugin-style-import": "^2.0.0"
},
"build": {
"asar": true,
"generateUpdatesFilesForAllChannels": true,
"extends": null,
"appId": "com.imex.rps",
@@ -101,7 +104,12 @@
"artifactName": "ImEX-RPS-${version}-${os}.${ext}",
"files": [
"build/**",
"electron/**",
"dist-electron/**",
"electron/main.js",
"electron/preload.js",
"electron/licenses.txt",
"electron/changelog.json",
"!**/*.map",
"src/ipc.types.js",
"src/ipc.types.json",
"src/ipc.types.commonjs.js",

View File

@@ -0,0 +1,40 @@
import { build } from "esbuild";
import fs from "node:fs";
import path from "node:path";
const repoRoot = path.resolve(process.cwd());
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, "package.json"), "utf8"));
const externals = [
"electron",
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {})
];
/**
* Bundle/minify Electron main + preload.
*
* NOTE: This is source protection / IP hardening, not a security boundary.
*/
await build({
entryPoints: {
main: path.join(repoRoot, "electron", "main-src.js"),
preload: path.join(repoRoot, "electron", "preload-src.js")
},
outdir: path.join(repoRoot, "dist-electron"),
outExtension: { ".js": ".cjs" },
platform: "node",
format: "cjs",
bundle: true,
minify: true,
sourcemap: false,
legalComments: "none",
target: "node22",
define: {
"process.env.NODE_ENV": '"production"'
},
external: externals,
logLevel: "info"
});
console.log("Built dist-electron outputs.");

View File

@@ -23,6 +23,7 @@ export default defineConfig({
open: true
},
build: {
outDir: "build"
outDir: "build",
sourcemap: false
}
});