fixed electron build + implemented dynamic settings + custom user data folder
This commit is contained in:
1 parent
8958ead210
commit
b872cd0733
14 files changed
+286
-81
No files matched your search
@@ -0,0 +1,61 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const parrentProcess = JSON.parse(process.env.PARENT_PROCESS || '{}');
|
||||
|
||||
let userDataPath = '';
|
||||
const defaultSettings = {
|
||||
userDataPath: '',
|
||||
tmdbApiUrl: '',
|
||||
tmdbApiKey: '',
|
||||
frontPort: '',
|
||||
backPort: '',
|
||||
portableMode: '',
|
||||
};
|
||||
|
||||
function getUserDataPath() {
|
||||
// return parrentProcess.electron_path || path.join(__dirname, '..', '..', 'data');
|
||||
return path.join(__dirname, '..', '..');
|
||||
}
|
||||
|
||||
function getSettingsFilePath() {
|
||||
return path.join(getUserDataPath(), 'settings.json');
|
||||
}
|
||||
|
||||
function getSettings() {
|
||||
const settingsFilePath = getSettingsFilePath();
|
||||
|
||||
try {
|
||||
const settingsData = fs.readFileSync(settingsFilePath);
|
||||
// console.log(`Loaded settings file.`);
|
||||
return JSON.parse(settingsData);
|
||||
} catch (err) {
|
||||
console.error('Error reading settings file:', err);
|
||||
console.log('Creating default settings file...');
|
||||
|
||||
let newSettingsFile = { ...defaultSettings };
|
||||
|
||||
let defaultDataPath = path.join(getUserDataPath(), 'data')
|
||||
|
||||
newSettingsFile.userDataPath = defaultDataPath;
|
||||
newSettingsFile.backPort = 4000;
|
||||
|
||||
fs.mkdirSync(defaultDataPath, { recursive: true });
|
||||
fs.writeFileSync(settingsFilePath, JSON.stringify(newSettingsFile, null, 2));
|
||||
console.log('Default settings file created.');
|
||||
|
||||
return defaultSettings;
|
||||
}
|
||||
}
|
||||
|
||||
function updateSettings(newSettings) {
|
||||
const settingsFilePath = getSettingsFilePath();
|
||||
|
||||
let updatedSettings = { ...userDataPath, ...newSettings };
|
||||
fs.mkdirSync(newSettings.userDataPath, { recursive: true }); // making sure the newly set data path is created before saving the new config
|
||||
fs.writeFileSync(settingsFilePath, JSON.stringify(updatedSettings, null, 2));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSettings,
|
||||
updateSettings
|
||||
};
|
||||
Reference in new issue
Block a user