Use different config folder/file in dev mode

This commit is contained in:
Alice Gaudon 2020-01-10 15:02:21 +01:00
parent 6ab28d30e3
commit 96ae08a513
3 changed files with 17 additions and 3 deletions

View File

@ -3,8 +3,9 @@ import path from "path";
import {homedir} from "os";
import Service from "./Service";
import Meta from "./Meta";
const configDir = path.resolve(homedir(), '.tabs-app');
const configDir = Meta.isDevMode() ? path.resolve(homedir(), '.config/tabs-app-dev') : path.resolve(homedir(), '.config/tabs-app');
const configFile = path.resolve(configDir, 'config.json');
export default class Config {
@ -39,6 +40,6 @@ export default class Config {
console.log('Saving config');
this.services = this.services.filter(s => s !== null);
fs.writeFileSync(configFile, JSON.stringify(this, null, 4));
console.log('> Config saved');
console.log('> Config saved to', configFile.toString());
}
}

12
src/Meta.js Normal file
View File

@ -0,0 +1,12 @@
export default class Meta {
static #devMode = null;
static isDevMode() {
if(this.#devMode === null) {
this.#devMode = process.argv.length > 2 && process.argv[2] === '--dev';
console.debug('Dev mode:', this.#devMode);
}
return this.#devMode;
}
}

View File

@ -2,6 +2,7 @@ import fs from "fs";
import path from "path";
import {app, BrowserWindow, ipcMain, Menu, shell, Tray} from "electron";
import Meta from "./Meta";
import Config from "./Config";
import Service from "./Service";
@ -10,7 +11,7 @@ const iconPath = path.resolve(resourcesDir, 'logo.png');
const config = new Config();
const devMode = process.argv.length > 2 && process.argv[2] === '--dev';
const devMode = Meta.isDevMode();
// Load icons
const brandIcons = listIcons('brands');