From 9b4b0306c77d391b64686eca0d67690a4fa92e0e Mon Sep 17 00:00:00 2001 From: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com> Date: Sat, 11 Apr 2026 16:33:58 +0200 Subject: [PATCH] fix: move config to AppData to prevent settings loss on update, add config.dev.json for dev environment --- .gitignore | 2 ++ app/ipcHandlers.js | 12 ++----- config.js | 38 +++++++++++++++------ config/{config.json => config.default.json} | 0 package.json | 7 ++-- 5 files changed, 36 insertions(+), 23 deletions(-) rename config/{config.json => config.default.json} (100%) diff --git a/.gitignore b/.gitignore index b044080..3c5cf2c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,7 @@ /ressources/ffprobe.exe /ressources/deno.exe +config/config.dev.json + logs/*.json logs/*.log \ No newline at end of file diff --git a/app/ipcHandlers.js b/app/ipcHandlers.js index 8e953a0..556f1c3 100644 --- a/app/ipcHandlers.js +++ b/app/ipcHandlers.js @@ -1,18 +1,10 @@ const { ipcMain, dialog, shell } = require("electron"); const fs = require("fs"); -const path = require("path"); const { logger, logDir } = require("../server/logger"); -const { configFeatures } = require("../config"); +const { configFeatures, featuresPath } = require("../config"); const config = require("../config"); const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator"); -const configFolderPath = path.join( - config.localMode - - ? path.join(__dirname, "..") - : path.join(path.dirname(process.execPath), "resources"), "config", "config.json" -); - const FEATURE_WHITELIST = new Set([ "autoUpdate", "discordRPC", @@ -25,6 +17,8 @@ const FEATURE_WHITELIST = new Set([ "customCodec", ]); +const configFolderPath = featuresPath; + function registerIpcHandlers(getMainWindow) { // Infos générales diff --git a/config.js b/config.js index 4a40e97..3e8a43d 100644 --- a/config.js +++ b/config.js @@ -5,23 +5,39 @@ const path = require("path"); const localMode = !app.isPackaged; -// Change path for JSON file -const featuresPath = path.join(path.join(`${localMode ? __dirname : process.resourcesPath}`,"config/" , "config.json")); +function resolveConfigPath() { + if (localMode) { + const devConfigPath = path.join(__dirname, "config", "config.dev.json"); + if (!fs.existsSync(devConfigPath)) { + const defaultConfigPath = path.join(__dirname, "config", "config.default.json"); + fs.copyFileSync(defaultConfigPath, devConfigPath); + } + return devConfigPath; + } -let features = {}; + const userConfigPath = path.join(app.getPath("userData"), "config.json"); + if (!fs.existsSync(userConfigPath)) { + const defaultConfigPath = path.join(process.resourcesPath, "config", "config.default.json"); + fs.copyFileSync(defaultConfigPath, userConfigPath); + } + + return userConfigPath; +} + +const featuresPath = resolveConfigPath(); function loadFeatures() { - const raw = fs.readFileSync(featuresPath, "utf-8"); - features = JSON.parse(raw); - return features; + const raw = fs.readFileSync(featuresPath, "utf-8"); + return JSON.parse(raw); } const configFeatures = loadFeatures(); module.exports = { - version: packageJson.version, - applicationPort: "8787", - localMode, - DiscordRPCID: "1410934537051181146", - configFeatures + version: packageJson.version, + applicationPort: "8787", + localMode, + DiscordRPCID: "1410934537051181146", + configFeatures, + featuresPath } \ No newline at end of file diff --git a/config/config.json b/config/config.default.json similarity index 100% rename from config/config.json rename to config/config.default.json diff --git a/package.json b/package.json index dfff853..a9e324a 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ ], "files": [ "**/*", - "node_modules/**/*" + "node_modules/**/*", + "!config/config.dev.json" ], "directories": { "buildResources": "build" @@ -77,8 +78,8 @@ "to": "binaries/deno.exe" }, { - "from": "config/config.json", - "to": "config/config.json" + "from": "config/config.default.json", + "to": "config/config.default.json" } ], "win": {