From d98140491f0ea48d3dd0112cc31aae1ec10ff4f9 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 28 Dec 2025 22:18:23 +0000 Subject: [PATCH] Fixed config path issue. --- src/config.js | 53 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/src/config.js b/src/config.js index 4c42f39..3fbe571 100644 --- a/src/config.js +++ b/src/config.js @@ -5,13 +5,16 @@ import { fileURLToPath } from "url"; import log4js from "log4js"; // Determine environment -const NODE_ENV = process.env.NODE_ENV || "development"; - -// Configure paths const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +const isPackaged = __dirname.includes("app.asar"); +const NODE_ENV = + process.env.NODE_ENV || (isPackaged ? "production" : "development"); + +// Configure paths function getProductionConfigPath() { + const homeDir = process.env.HOME || process.env.USERPROFILE || ""; switch (process.platform) { case "win32": return path.join( @@ -20,19 +23,55 @@ function getProductionConfigPath() { "config.json" ); case "darwin": - // macOS standard for system-wide config is often /etc or /Library/Application Support - // We'll stick to /etc as requested for parity with Linux - return "/etc/farmcontrol-server/config.json"; + return path.join( + homeDir, + "Library", + "Application Support", + "farmcontrol-server", + "config.json" + ); case "linux": default: return "/etc/farmcontrol-server/config.json"; } } +function getDevelopmentConfigPath() { + // If we're in a packaged app (asar), we can't write to the app directory. + // We should use a writable user data directory instead. + if (isPackaged) { + const homeDir = process.env.HOME || process.env.USERPROFILE || ""; + switch (process.platform) { + case "win32": + return path.join( + process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"), + "farmcontrol-server", + "config.json" + ); + case "darwin": + return path.join( + homeDir, + "Library", + "Application Support", + "farmcontrol-server", + "config.json" + ); + default: + return path.join( + homeDir, + ".config", + "farmcontrol-server", + "config.json" + ); + } + } + return path.resolve(__dirname, "../config.json"); +} + const CONFIG_PATH = NODE_ENV === "production" ? getProductionConfigPath() - : path.resolve(__dirname, "../config.json"); + : getDevelopmentConfigPath(); const logger = log4js.getLogger("Config"); logger.level = "info";