2017-10-18 12:17:09 +05:30
|
|
|
'use strict';
|
2018-04-11 13:13:59 +00:00
|
|
|
const { ipcRenderer, crashReporter } = require('electron');
|
2017-10-18 12:17:09 +05:30
|
|
|
|
|
|
|
|
renderDom();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method that renders application data
|
|
|
|
|
*/
|
|
|
|
|
function renderDom() {
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
loadContent();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadContent() {
|
|
|
|
|
let basicAuth = document.getElementById('basicAuth');
|
|
|
|
|
let cancel = document.getElementById('cancel');
|
|
|
|
|
|
|
|
|
|
if (basicAuth) {
|
|
|
|
|
basicAuth.onsubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
submitForm();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cancel) {
|
|
|
|
|
cancel.addEventListener('click', () => {
|
2018-04-11 13:13:59 +00:00
|
|
|
ipcRenderer.send('close-basic-auth');
|
2017-10-18 12:17:09 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method that gets invoked on submitting the form
|
|
|
|
|
*/
|
|
|
|
|
function submitForm() {
|
|
|
|
|
let username = document.getElementById('username').value;
|
|
|
|
|
let password = document.getElementById('password').value;
|
|
|
|
|
|
|
|
|
|
if (username && password) {
|
2018-04-11 13:13:59 +00:00
|
|
|
ipcRenderer.send('login', { username, password });
|
2017-10-18 12:17:09 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the hosts name
|
|
|
|
|
*/
|
2018-04-11 13:13:59 +00:00
|
|
|
ipcRenderer.on('hostname', (event, host) => {
|
2017-10-18 12:17:09 +05:30
|
|
|
let hostname = document.getElementById('hostname');
|
|
|
|
|
|
|
|
|
|
if (hostname){
|
|
|
|
|
hostname.innerHTML = host || 'unknown';
|
|
|
|
|
}
|
2017-11-09 17:31:38 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Triggered if user credentials are invalid
|
|
|
|
|
*/
|
2018-04-11 13:13:59 +00:00
|
|
|
ipcRenderer.on('isValidCredentials', (event, isValidCredentials) => {
|
2017-11-09 17:31:38 +05:30
|
|
|
let credentialsError = document.getElementById('credentialsError');
|
|
|
|
|
|
|
|
|
|
if (credentialsError){
|
|
|
|
|
credentialsError.style.display = isValidCredentials ? 'none' : 'block'
|
|
|
|
|
}
|
2018-04-11 13:13:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcRenderer.on('register-crash-reporter', (event, arg) => {
|
|
|
|
|
if (arg && typeof arg === 'object') {
|
|
|
|
|
crashReporter.start(arg);
|
|
|
|
|
}
|
2018-06-19 20:26:04 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcRenderer.on('i18n-basic-auth', (event, content) => {
|
|
|
|
|
if (content && typeof content === 'object') {
|
|
|
|
|
const i18nNodes = document.querySelectorAll('[data-i18n-text]');
|
|
|
|
|
|
|
|
|
|
for (let node of i18nNodes) {
|
|
|
|
|
if (node.attributes['data-i18n-text'] && node.attributes['data-i18n-text'].value) {
|
|
|
|
|
node.innerText = content[node.attributes['data-i18n-text'].value] || node.attributes['data-i18n-text'].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-18 12:17:09 +05:30
|
|
|
});
|