next-ucap-messenger/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js
2020-01-22 17:21:11 +09:00

71 lines
2.2 KiB
JavaScript

'use strict';
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
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');
});
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 || '';
}
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)';
}
);
ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents);