From c4e3fa72ce021da7326f4e688f707daf52552c44 Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 8 Mar 2021 19:50:01 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20More=20comprehensive=20example=20us?= =?UTF-8?q?er=20config=20=E2=9E=95=20Moving=20main.js=20to=20use=20more=20?= =?UTF-8?q?async=20code=20and=20make=20things=20a=20bit=20more=20homogeneo?= =?UTF-8?q?us?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freechat-client/example-dev-config.json | 41 +++++++++++++------------ freechat-client/main.js | 21 +++++++++---- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/freechat-client/example-dev-config.json b/freechat-client/example-dev-config.json index cd21f98..5f5ef27 100644 --- a/freechat-client/example-dev-config.json +++ b/freechat-client/example-dev-config.json @@ -1,22 +1,23 @@ { - "servers": [ - { - "name": "cool1", - "domain": "freechat.shockrah.io", - "ip": "0.0.0.0", - "description": "really good", - "key": "this right here is the secret for that user", - "username": "this is optional per server" - }, - { - "name": "another one" - }, - { - "name": "shockrah's lair" - } - ], - - "ignore-me": "global's like this are mainly for default configuration things", - "global-username": "shockrah", - "global-proxy": "one day this will be a thing but not today" + "servers": [ + { + "server": { + "description": "Server for sick development things", + "hostname": "localhost", + "name": "Freechat Sample Server", + "port": 4536, + "protocol": "http" + }, + "user": { + "id": 1, + "joindate": 1615187538, + "name": "shockrah", + "permissions": 51, + "secret": "ooky-spooky-base64-string===", + "status": 0 + } + } + ], + "username": "shockrah" } + diff --git a/freechat-client/main.js b/freechat-client/main.js index 7a9029a..d8ef867 100644 --- a/freechat-client/main.js +++ b/freechat-client/main.js @@ -1,12 +1,21 @@ const { ipcMain } = require('electron') const { app, BrowserWindow } = require('electron') +const { ArgumentParser } = require('argparse') const path = require('path') -const cfg = require('./src/config.js') +const { Config, from_cli_parser } = require('./src/config.js') + +const arguments = (() => { + const parser = new ArgumentParser({ + description: 'Freechat client' + }) + parser.add_argument('-c', '--config', {help: 'Specify config path'}) + return parser +})() let win -let config = cfg.get_config(cfg.load_parser()) +let config = from_cli_parser(arguments) // NOTE: this line is only here for demonstration as the current make script exposes this var // so that we can test against self signed certificates but still use ssl @@ -50,14 +59,14 @@ app.on('activate', () => { } }); -// returns the config +// returns the in-memory config reference ipcMain.handle('config-request', async function(event, _arg) { return config; }) -ipcMain.handle('config-update', function(event, data) { - config = data; - cfg.update_file(data, data['path']); +ipcMain.handle('config-update', async function(event, updated_config) { + config = new Config(updated_config.path, updated_config.data) + await config.write_disk() })