next-ucap-messenger/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-12-15 16:06:07 +00:00
'use strict';
2020-01-22 08:21:11 +00:00
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
2019-12-15 16:06:07 +00:00
const updateWindowContainer = document.getElementById(
'update-window-container'
);
const confirmation = document.getElementById('confirmation');
const downloading = document.getElementById('downloading');
const update = document.getElementById('update');
const confirmationOk = document.getElementById('confirmation-ok');
const confirmationCancel = document.getElementById('confirmation-cancel');
const downloadingProgressBar = document.getElementById(
'downloading-progress-bar'
);
const downloadingProgressLabel = document.getElementById(
'downloading-progress-label'
);
const downloadingCancel = document.getElementById('downloading-cancel');
confirmationOk &&
confirmationOk.addEventListener('click', e => {
console.log('UCAP::ElectronUpdateWindow::acceptUpdate');
ipcRenderer.send('UCAP::ElectronUpdateWindow::acceptUpdate');
downloadingProgressBar.style.width = `0%`;
downloadingProgressLabel.innerText = `0%`;
updateWindowContainer.style.transform = 'translateX(-500px)';
});
confirmationCancel &&
confirmationCancel.addEventListener('click', e => {
ipcRenderer.send('UCAP::ElectronUpdateWindow::denyUpdate');
});
downloadingCancel &&
downloadingCancel.addEventListener('click', e => {
ipcRenderer.send('UCAP::ElectronUpdateWindow::cancelDownload');
});
2020-01-22 08:21:11 +00:00
function setContents(event, versionInfo) {
2020-01-29 06:03:48 +00:00
const updateDoc = global.window.document;
2020-01-22 08:21:11 +00:00
2020-01-29 06:03:48 +00:00
const latestVersion = updateDoc.getElementById('latestVersion');
if (!!latestVersion) {
latestVersion.innerHTML = versionInfo.latest || '';
}
2020-01-22 08:21:11 +00:00
2020-01-29 06:03:48 +00:00
const installedVersion = updateDoc.getElementById('installedVersion');
if (!!installedVersion) {
installedVersion.innerHTML = versionInfo.installed || '';
}
2020-01-22 08:21:11 +00:00
}
2019-12-15 16:06:07 +00:00
ipcRenderer.on(
'UCAP::ElectronUpdateWindow::downloadProcess',
(event, ...args) => {
const percentage = (args[0] / args[1]) * 100;
downloadingProgressBar.style.width = `${percentage}%`;
downloadingProgressLabel.innerText = `${percentage}%`;
}
);
ipcRenderer.on(
'UCAP::ElectronUpdateWindow::downloadComplete',
(event, ...args) => {
updateWindowContainer.style.transform = 'translateX(-1000px)';
}
);
2020-01-22 08:21:11 +00:00
2020-01-29 06:03:48 +00:00
ipcRenderer.on(
'UCAP::ElectronUpdateWindow::BrowserWindowSetContents',
setContents
);