From d01355bee1edf49bea9072fbe854fc0528fe0956 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 29 Dec 2025 01:32:51 +0000 Subject: [PATCH] Fixed linux and macOS builds. --- package.json | 7 +++---- src/electron/window.js | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5ee62eb..c851939 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,6 @@ "author": "Tom Butcher", "license": "ISC", "dependencies": { - "@ant-design/icons": "^6.1.0", - "ant-design": "^1.0.0", - "antd": "^5.28.0", "axios": "^1.13.2", "canvas": "^3.2.0", "etcd3": "^1.1.2", @@ -36,13 +33,14 @@ "node-cache": "^5.1.2", "node-thermal-printer": "^4.5.0", "pdf-to-img": "^5.0.0", - "prop-types": "^15.8.1", "sharp": "^0.34.5", "socket.io": "^4.8.1", "socket.io-client": "^4.8.1", "ws": "^8.18.3" }, "devDependencies": { + "@ant-design/icons": "^6.1.0", + "antd": "^5.28.0", "@electron/rebuild": "^4.0.1", "@vitejs/plugin-react": "^5.1.1", "concurrently": "^9.2.1", @@ -52,6 +50,7 @@ "jest": "^30.2.0", "nodemon": "^3.1.11", "pkg": "^5.8.1", + "prop-types": "^15.8.1", "react": "^19.2.0", "react-dom": "^19.2.0", "rimraf": "^6.1.2", diff --git a/src/electron/window.js b/src/electron/window.js index 74f32a1..555f35b 100644 --- a/src/electron/window.js +++ b/src/electron/window.js @@ -36,9 +36,22 @@ export async function createElectronWindow() { const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); + // Determine if we are running from the build directory or src + const isRunningFromBuild = + __dirname.includes(path.sep + "build") || __dirname.includes("app.asar"); + return new Promise((resolve) => { function createWindow() { logger.debug("Creating browser window..."); + + // Resolve paths correctly based on environment + const preloadPath = + process.env.NODE_ENV === "development" + ? path.join(__dirname, "preload.js") + : isRunningFromBuild + ? path.join(__dirname, "preload.js") + : path.join(__dirname, "..", "build", "electron", "preload.js"); + const win = new BrowserWindow({ width: 900, height: 600, @@ -49,25 +62,25 @@ export async function createElectronWindow() { webPreferences: { nodeIntegration: true, contextIsolation: true, - preload: - process.env.NODE_ENV === "development" - ? path.join(__dirname, "preload.js") - : path.join(__dirname, "..", "build", "electron", "preload.js"), + preload: preloadPath, }, }); // Make the window globally accessible for IPC global.mainWindow = win; - logger.info("Preload Script", path.join(__dirname, "preload.js")); + logger.info("Preload Script", preloadPath); if (process.env.NODE_ENV === "development") { logger.info("Loading development url..."); win.loadURL("http://localhost:5287"); // Vite dev server } else { // In production, the built files will be in the build/electron directory - win.loadFile( - path.join(__dirname, "..", "build", "electron", "index.html") - ); + const htmlPath = isRunningFromBuild + ? path.join(__dirname, "index.html") + : path.join(__dirname, "..", "build", "electron", "index.html"); + + logger.info("Loading production file:", htmlPath); + win.loadFile(htmlPath); } // Resolve the promise when the window is ready