config-files: Move all the configuration files into config folder. (#508)

This commit moves all the configuration(.json) files into a config folder
if the config folder doesn't already exist. It also updates the places
where these files are being accessed with the new address.
This will help us zip the folder easily in the future.
This commit is contained in:
Abhigyan Khaund
2018-07-04 14:46:13 +05:30
committed by Akash Nimare
parent eeb0b4a666
commit df35ffc3b0
7 changed files with 48 additions and 6 deletions

View File

@@ -54,7 +54,8 @@ function createMainWindow() {
// Load the previous state with fallback to defaults // Load the previous state with fallback to defaults
const mainWindowState = windowStateKeeper({ const mainWindowState = windowStateKeeper({
defaultWidth: 1100, defaultWidth: 1100,
defaultHeight: 720 defaultHeight: 720,
path: `${app.getPath('userData')}/config`
}); });
// Let's keep the window position global so that we can access it in other process // Let's keep the window position global so that we can access it in other process

View File

@@ -423,7 +423,7 @@ class AppMenu {
const resetAppSettingsMessage = 'By proceeding you will be removing all connected organizations and preferences from Zulip.'; const resetAppSettingsMessage = 'By proceeding you will be removing all connected organizations and preferences from Zulip.';
// We save App's settings/configurations in following files // We save App's settings/configurations in following files
const settingFiles = ['window-state.json', 'domain.json', 'settings.json', 'certificates.json']; const settingFiles = ['config/window-state.json', 'config/domain.json', 'config/settings.json', 'config/certificates.json'];
dialog.showMessageBox({ dialog.showMessageBox({
type: 'warning', type: 'warning',

View File

@@ -64,7 +64,7 @@ class CertificateUtil {
this.reloadDB(); this.reloadDB();
} }
reloadDB() { reloadDB() {
const settingsJsonPath = path.join(app.getPath('userData'), '/certificates.json'); const settingsJsonPath = path.join(app.getPath('userData'), '/config/certificates.json');
try { try {
const file = fs.readFileSync(settingsJsonPath, 'utf8'); const file = fs.readFileSync(settingsJsonPath, 'utf8');
JSON.parse(file); JSON.parse(file);

View File

@@ -66,7 +66,7 @@ class ConfigUtil {
} }
reloadDB() { reloadDB() {
const settingsJsonPath = path.join(app.getPath('userData'), '/settings.json'); const settingsJsonPath = path.join(app.getPath('userData'), '/config/settings.json');
try { try {
const file = fs.readFileSync(settingsJsonPath, 'utf8'); const file = fs.readFileSync(settingsJsonPath, 'utf8');
JSON.parse(file); JSON.parse(file);

View File

@@ -11,6 +11,7 @@ if (process.type === 'renderer') {
const zulipDir = app.getPath('userData'); const zulipDir = app.getPath('userData');
const logDir = `${zulipDir}/Logs/`; const logDir = `${zulipDir}/Logs/`;
const certificatesDir = `${zulipDir}/certificates/`; const certificatesDir = `${zulipDir}/certificates/`;
const configDir = `${zulipDir}/config/`;
const initSetUp = () => { const initSetUp = () => {
// if it is the first time the app is running // if it is the first time the app is running
// create zulip dir in userData folder to // create zulip dir in userData folder to
@@ -28,6 +29,46 @@ const initSetUp = () => {
fs.mkdirSync(certificatesDir); fs.mkdirSync(certificatesDir);
} }
// Migrate config files from app data folder to config folder inside app
// data folder. This will be done once when a user updates to the new version.
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
const domainJson = `${zulipDir}/domain.json`;
const certificatesJson = `${zulipDir}/certificates.json`;
const settingsJson = `${zulipDir}/settings.json`;
const updatesJson = `${zulipDir}/updates.json`;
const windowStateJson = `${zulipDir}/window-state.json`;
const configData = [
{
path: domainJson,
fileName: `domain.json`
},
{
path: certificatesJson,
fileName: `certificates.json`
},
{
path: settingsJson,
fileName: `settings.json`
},
{
path: updatesJson,
fileName: `updates.json`
}
];
configData.forEach(data => {
if (fs.existsSync(data.path)) {
fs.copyFileSync(data.path, configDir + data.fileName);
fs.unlinkSync(data.path);
}
});
// window-state.json is only deleted not moved, as the electron-window-state
// package will recreate the file in the config folder.
if (fs.existsSync(windowStateJson)) {
fs.unlinkSync(windowStateJson);
}
}
setupCompleted = true; setupCompleted = true;
} }
}; };

View File

@@ -251,7 +251,7 @@ class DomainUtil {
} }
reloadDB() { reloadDB() {
const domainJsonPath = path.join(app.getPath('userData'), '/domain.json'); const domainJsonPath = path.join(app.getPath('userData'), 'config/domain.json');
try { try {
const file = fs.readFileSync(domainJsonPath, 'utf8'); const file = fs.readFileSync(domainJsonPath, 'utf8');
JSON.parse(file); JSON.parse(file);

View File

@@ -52,7 +52,7 @@ class LinuxUpdateUtil {
} }
reloadDB() { reloadDB() {
const linuxUpdateJsonPath = path.join(app.getPath('userData'), '/updates.json'); const linuxUpdateJsonPath = path.join(app.getPath('userData'), '/config/updates.json');
try { try {
const file = fs.readFileSync(linuxUpdateJsonPath, 'utf8'); const file = fs.readFileSync(linuxUpdateJsonPath, 'utf8');
JSON.parse(file); JSON.parse(file);