SymphonyElectron/js/basicAuth/renderer.js
Kiran Niranjan 3be2986c7e Electron-401 (fixes crash reporter) (#334)
- fix crash reporter
- fix typo
- Add support to generate crash report
- Add logic to store globally and return
- PR review fixes
- Add logic to validate file mime type
2018-04-11 18:43:59 +05:30

71 lines
1.6 KiB
JavaScript

'use strict';
const { ipcRenderer, crashReporter } = require('electron');
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', () => {
ipcRenderer.send('close-basic-auth');
});
}
}
/**
* 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) {
ipcRenderer.send('login', { username, password });
}
}
/**
* Updates the hosts name
*/
ipcRenderer.on('hostname', (event, host) => {
let hostname = document.getElementById('hostname');
if (hostname){
hostname.innerHTML = host || 'unknown';
}
});
/**
* Triggered if user credentials are invalid
*/
ipcRenderer.on('isValidCredentials', (event, isValidCredentials) => {
let credentialsError = document.getElementById('credentialsError');
if (credentialsError){
credentialsError.style.display = isValidCredentials ? 'none' : 'block'
}
});
ipcRenderer.on('register-crash-reporter', (event, arg) => {
if (arg && typeof arg === 'object') {
crashReporter.start(arg);
}
});