From 6d0bfc1798af3e34b0c834e42db3f45daee04521 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Fri, 17 Apr 2020 22:59:54 -0700 Subject: [PATCH] changing initial screen to be a welcome page/nav page to other servers --- freechat-client/example-dev-config.json | 3 +- freechat-client/src/js/testfile.json | 1 + freechat-client/src/js/welcome.js | 46 +++++++++++++++++++++++++ freechat-client/src/pages/index.html | 15 +++----- 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 freechat-client/src/js/testfile.json create mode 100644 freechat-client/src/js/welcome.js diff --git a/freechat-client/example-dev-config.json b/freechat-client/example-dev-config.json index 6764060..604f253 100644 --- a/freechat-client/example-dev-config.json +++ b/freechat-client/example-dev-config.json @@ -1,9 +1,10 @@ { + "username": "shockrah", "servers": [ { "name": "cool1", "domain": "freechat.shockrah.io/", - "ip": 0.0.0.0, + "ip": "0.0.0.0", "description": "really good", "key": "given by server don't worry fow now", "username": "this is optional per server" diff --git a/freechat-client/src/js/testfile.json b/freechat-client/src/js/testfile.json new file mode 100644 index 0000000..58830bd --- /dev/null +++ b/freechat-client/src/js/testfile.json @@ -0,0 +1 @@ +{"username":null} \ No newline at end of file diff --git a/freechat-client/src/js/welcome.js b/freechat-client/src/js/welcome.js new file mode 100644 index 0000000..f53ac8c --- /dev/null +++ b/freechat-client/src/js/welcome.js @@ -0,0 +1,46 @@ +// Dank welcome +const fs = require('fs'); +const homedir = require('os').homedir(); +const config_path = homedir + '/.config/freechat-client/config.json'; + +function create_config() { + let default_config = JSON.stringify({ + 'username':null + }); + fs.writeFile(config_path, default_config, function(err) { + if(err) { + console.log('Unable to create config\nERR: ' + err); + } + else { + console.log('config created'); + return default_config; + } + }); +} + +function welcome_msg(username) { + console.log('welcome message'); + let d = document.getElementById('welcome'); + d.text('Welcome ' + username); +} + +function get_config() { + try { + let raw = fs.readFileSync(config_path); + return JSON.parse(raw); + } + catch { + return false; + } +} +let config = get_config(); +if(!config) { + config = create_config(); +} + +if(config['username'] === null){ + console.log('no user name setup yet'); +} +else { + welcome_msg(config['username']); +} diff --git a/freechat-client/src/pages/index.html b/freechat-client/src/pages/index.html index af10837..a6227fc 100644 --- a/freechat-client/src/pages/index.html +++ b/freechat-client/src/pages/index.html @@ -2,20 +2,13 @@ - - + + Freechat

Freechat login

- -
-
-
-
-
-
-
-
+

+