✨ Moving as much auth/initialization logic out of index.html
➕ New local push function in auth for push server buttons onto the dom
This commit is contained in:
@@ -2,6 +2,23 @@ const { ipcRenderer } = require('electron')
|
||||
const got = require('got')
|
||||
|
||||
|
||||
function push_srv(remote, user, enabled) {
|
||||
let classes = 'btn btn-outline-secondary btn-nav-settings'
|
||||
if(!enabled) { classes += ' disabled' }
|
||||
|
||||
let btn = $('<input>').attr({
|
||||
type: 'button',
|
||||
'class': classes,
|
||||
id: remote['hostname'],
|
||||
value: remote['name']
|
||||
})
|
||||
|
||||
let cb = async () => { await channels.list(remote, user) }
|
||||
$(`#${remote['hostname']}`).on('click', cb)
|
||||
|
||||
$('#server-list').append(btn)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} protocol http|https
|
||||
* @param {String} host Just the hostname one.two.xyz
|
||||
@@ -34,16 +51,19 @@ exports.init = async function() {
|
||||
const config = await ipcRenderer.invoke('config-request')
|
||||
|
||||
for(const index in config.data['servers']) {
|
||||
console.log('Initial login', config.data['servers'][index])
|
||||
const remote = config.data['servers'][index]['server']
|
||||
const user = config.data['servers'][index]['user']
|
||||
|
||||
try {
|
||||
// update the jwt first
|
||||
const jwt = await login(remote['protocol'], remote['hostname'], remote['port'], user)
|
||||
config.data['servers'][index]['user']['jwt'] = jwt
|
||||
user['jwt'] = jwt
|
||||
|
||||
push_srv(remote, user, true);
|
||||
} catch (err) {
|
||||
continue
|
||||
push_srv(remote, user, false)
|
||||
const e_container = { error: err, server: remote, creds: user }
|
||||
console.log('Failure to communicate with server: ', e_container)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user