mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
fix: move config to AppData to prevent settings loss on update, add config.dev.json for dev environment
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,5 +7,7 @@
|
|||||||
/ressources/ffprobe.exe
|
/ressources/ffprobe.exe
|
||||||
/ressources/deno.exe
|
/ressources/deno.exe
|
||||||
|
|
||||||
|
config/config.dev.json
|
||||||
|
|
||||||
logs/*.json
|
logs/*.json
|
||||||
logs/*.log
|
logs/*.log
|
||||||
@@ -1,18 +1,10 @@
|
|||||||
const { ipcMain, dialog, shell } = require("electron");
|
const { ipcMain, dialog, shell } = require("electron");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
|
||||||
const { logger, logDir } = require("../server/logger");
|
const { logger, logDir } = require("../server/logger");
|
||||||
const { configFeatures } = require("../config");
|
const { configFeatures, featuresPath } = require("../config");
|
||||||
const config = require("../config");
|
const config = require("../config");
|
||||||
const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator");
|
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([
|
const FEATURE_WHITELIST = new Set([
|
||||||
"autoUpdate",
|
"autoUpdate",
|
||||||
"discordRPC",
|
"discordRPC",
|
||||||
@@ -25,6 +17,8 @@ const FEATURE_WHITELIST = new Set([
|
|||||||
"customCodec",
|
"customCodec",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const configFolderPath = featuresPath;
|
||||||
|
|
||||||
function registerIpcHandlers(getMainWindow) {
|
function registerIpcHandlers(getMainWindow) {
|
||||||
|
|
||||||
// Infos générales
|
// Infos générales
|
||||||
|
|||||||
38
config.js
38
config.js
@@ -5,23 +5,39 @@ const path = require("path");
|
|||||||
|
|
||||||
const localMode = !app.isPackaged;
|
const localMode = !app.isPackaged;
|
||||||
|
|
||||||
// Change path for JSON file
|
function resolveConfigPath() {
|
||||||
const featuresPath = path.join(path.join(`${localMode ? __dirname : process.resourcesPath}`,"config/" , "config.json"));
|
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() {
|
function loadFeatures() {
|
||||||
const raw = fs.readFileSync(featuresPath, "utf-8");
|
const raw = fs.readFileSync(featuresPath, "utf-8");
|
||||||
features = JSON.parse(raw);
|
return JSON.parse(raw);
|
||||||
return features;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const configFeatures = loadFeatures();
|
const configFeatures = loadFeatures();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
version: packageJson.version,
|
version: packageJson.version,
|
||||||
applicationPort: "8787",
|
applicationPort: "8787",
|
||||||
localMode,
|
localMode,
|
||||||
DiscordRPCID: "1410934537051181146",
|
DiscordRPCID: "1410934537051181146",
|
||||||
configFeatures
|
configFeatures,
|
||||||
|
featuresPath
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,8 @@
|
|||||||
],
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"**/*",
|
"**/*",
|
||||||
"node_modules/**/*"
|
"node_modules/**/*",
|
||||||
|
"!config/config.dev.json"
|
||||||
],
|
],
|
||||||
"directories": {
|
"directories": {
|
||||||
"buildResources": "build"
|
"buildResources": "build"
|
||||||
@@ -77,8 +78,8 @@
|
|||||||
"to": "binaries/deno.exe"
|
"to": "binaries/deno.exe"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"from": "config/config.json",
|
"from": "config/config.default.json",
|
||||||
"to": "config/config.json"
|
"to": "config/config.default.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
|
|||||||
Reference in New Issue
Block a user