changing initial screen to be a welcome page/nav page to other servers
This commit is contained in:
1
freechat-client/src/js/testfile.json
Normal file
1
freechat-client/src/js/testfile.json
Normal file
@@ -0,0 +1 @@
|
||||
{"username":null}
|
||||
46
freechat-client/src/js/welcome.js
Normal file
46
freechat-client/src/js/welcome.js
Normal file
@@ -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']);
|
||||
}
|
||||
Reference in New Issue
Block a user