Fixed linux and macOS builds.
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2025-12-29 01:32:51 +00:00
parent c9c59c2bff
commit d01355bee1
2 changed files with 24 additions and 12 deletions

View File

@ -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",

View File

@ -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