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

71 lines
2.2 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) {
let updateDoc = global.window.document;
let latestVersion = updateDoc.getElementById('latestVersion');
latestVersion.innerHTML = versionInfo.latest || '';
let installedVersion = updateDoc.getElementById('installedVersion');
installedVersion.innerHTML = versionInfo.installed || '';
}
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
ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents);