mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-10-31 03:53:34 +00:00 
			
		
		
		
	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.
		
			
				
	
	
		
			75 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| const fs = require('fs');
 | |
| const path = require('path');
 | |
| const process = require('process');
 | |
| const remote =
 | |
| 	process.type === 'renderer' ? require('electron').remote : require('electron');
 | |
| const JsonDB = require('node-json-db');
 | |
| const Logger = require('./logger-util');
 | |
| 
 | |
| const logger = new Logger({
 | |
| 	file: 'linux-update-util.log',
 | |
| 	timestamp: true
 | |
| });
 | |
| 
 | |
| /* To make the util runnable in both main and renderer process */
 | |
| const { dialog, app } = remote;
 | |
| 
 | |
| let instance = null;
 | |
| 
 | |
| class LinuxUpdateUtil {
 | |
| 	constructor() {
 | |
| 		if (instance) {
 | |
| 			return instance;
 | |
| 		} else {
 | |
| 			instance = this;
 | |
| 		}
 | |
| 
 | |
| 		this.reloadDB();
 | |
| 		return instance;
 | |
| 	}
 | |
| 
 | |
| 	getUpdateItem(key, defaultValue = null) {
 | |
| 		this.reloadDB();
 | |
| 		const value = this.db.getData('/')[key];
 | |
| 		if (value === undefined) {
 | |
| 			this.setUpdateItem(key, defaultValue);
 | |
| 			return defaultValue;
 | |
| 		} else {
 | |
| 			return value;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	setUpdateItem(key, value) {
 | |
| 		this.db.push(`/${key}`, value, true);
 | |
| 		this.reloadDB();
 | |
| 	}
 | |
| 
 | |
| 	removeUpdateItem(key) {
 | |
| 		this.db.delete(`/${key}`);
 | |
| 		this.reloadDB();
 | |
| 	}
 | |
| 
 | |
| 	reloadDB() {
 | |
| 		const linuxUpdateJsonPath = path.join(app.getPath('userData'), '/config/updates.json');
 | |
| 		try {
 | |
| 			const file = fs.readFileSync(linuxUpdateJsonPath, 'utf8');
 | |
| 			JSON.parse(file);
 | |
| 		} catch (err) {
 | |
| 			if (fs.existsSync(linuxUpdateJsonPath)) {
 | |
| 				fs.unlinkSync(linuxUpdateJsonPath);
 | |
| 				dialog.showErrorBox(
 | |
| 					'Error saving update notifications.',
 | |
| 					'We encountered an error while saving the update notifications.'
 | |
| 				);
 | |
| 				logger.error('Error while JSON parsing updates.json: ');
 | |
| 				logger.error(err);
 | |
| 			}
 | |
| 		}
 | |
| 		this.db = new JsonDB(linuxUpdateJsonPath, true, true);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| module.exports = new LinuxUpdateUtil();
 |