mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-04 05:53:21 +00:00 
			
		
		
		
	Add ConfigUtil to manage config items.
This commit is contained in:
		
							
								
								
									
										39
									
								
								app/renderer/js/utils/config-util.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								app/renderer/js/utils/config-util.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
const {app} = require('electron').remote;
 | 
			
		||||
const JsonDB = require('node-json-db');
 | 
			
		||||
 | 
			
		||||
let instance = null;
 | 
			
		||||
 | 
			
		||||
class ConfigUtil {
 | 
			
		||||
	constructor() {
 | 
			
		||||
		if (instance) {
 | 
			
		||||
			return instance;
 | 
			
		||||
		} else {
 | 
			
		||||
			instance = this;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		this.db = new JsonDB(app.getPath('userData') + '/config.json', true, true);
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	getConfigItem(key, defaultValue=null) {
 | 
			
		||||
		let value = this.db.getData('/')[key];
 | 
			
		||||
		if (value === undefined) {
 | 
			
		||||
			this.setConfigItem(key, value);
 | 
			
		||||
			return defaultValue;
 | 
			
		||||
		} else {
 | 
			
		||||
			return value;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	setConfigItem(key, value) {
 | 
			
		||||
		this.db.push(`/${key}`, value, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	removeConfigItem(key) {
 | 
			
		||||
		this.db.delete(`/${key}`);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = new ConfigUtil();
 | 
			
		||||
		Reference in New Issue
	
	Block a user