Files
SymphonyElectron/js/networkError/index.js
Kiran Niranjan c3bbadb955 ELECTRON-967 (Handle network state and implement retry logic) (#600)
* ELECTRON-967 - Display Error content when there is no active network connection

* ELECTRON-967 - Fix css issue for Windows

* ELECTRON-967 - Optimize code
2019-03-19 19:00:40 +05:30

44 lines
1.3 KiB
JavaScript

const { ipcRenderer } = require('electron');
const apiEnums = require('../enums/api.js');
const apiCmds = apiEnums.cmds;
const apiName = apiEnums.apiName;
const htmlContents = require('./contents');
class NetworkError {
constructor() {
this.domParser = new DOMParser();
}
showError(data) {
if (!data) {
return;
}
const { message, error } = data;
const errorContent = this.domParser.parseFromString(htmlContents.errorContent(message), 'text/html');
errorContent.getElementById('error-code').innerText = error || "UNKNOWN_ERROR";
// Add event listeners for buttons
const cancelRetryButton = errorContent.getElementById('cancel-retry-button');
cancelRetryButton.addEventListener('click', () => {
ipcRenderer.send(apiName, {
cmd: apiCmds.cancelNetworkStatusCheck
});
});
const quitButton = errorContent.getElementById('quit-button');
quitButton.addEventListener('click', () => {
ipcRenderer.send(apiName, {
cmd: apiCmds.quitWindow
})
});
const mainFrame = errorContent.getElementById('main-frame');
document.body.appendChild(mainFrame);
}
}
module.exports = {
NetworkError,
};