From 464489da4eddb026d7526b550247b643e9b7d0f9 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Wed, 22 Jan 2020 17:21:11 +0900 Subject: [PATCH] version of update window is added --- .../electron-update-window.service.ts | 28 ++++++++++++++----- .../src/lib/types/channel.type.ts | 4 ++- .../assets/notification/preload.js | 23 +++++++++++---- .../assets/update-window/preload.js | 15 +++++++++- .../assets/update-window/template.html | 5 +++- .../ucap-webmessenger-electron/src/index.ts | 4 +++ .../src/assets/i18n/en.json | 2 +- .../src/assets/i18n/ko.json | 4 +-- 8 files changed, 66 insertions(+), 19 deletions(-) diff --git a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts index 63fb466e..951dbc33 100644 --- a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/services/electron-update-window.service.ts @@ -8,12 +8,18 @@ import { } from '../models/electron-update-window-options'; import { Channel } from '../types/channel.type'; +import { ElectronWebContentsChannel } from '@ucap-webmessenger/electron-core'; export class ElectronUpdateWindowService { private customOptions: ElectronUpdateWindowOptions; private browserWindow: BrowserWindow; private templateUrl: string; + versionInfo: { + installed?: string; + latest?: string; + }; + constructor(options: ElectronUpdateWindowOptions) { this.customOptions = { ...DefaultElectronUpdateWindowOptions @@ -60,14 +66,22 @@ export class ElectronUpdateWindowService { this.browserWindow.on('closed', () => { this.browserWindow = null; }); - this.browserWindow.webContents.on('did-finish-load', () => { - if (process.env.NODE_ENV === 'development') { - this.browserWindow.webContents.openDevTools(); + this.browserWindow.webContents.on( + ElectronWebContentsChannel.DidFinishLoad, + () => { + if (process.env.NODE_ENV === 'development') { + this.browserWindow.webContents.openDevTools(); + } + if (!!this.customOptions.onReady) { + this.customOptions.onReady(); + } + + this.browserWindow.webContents.send( + Channel.browserWindowSetContents, + this.versionInfo + ); } - if (!!this.customOptions.onReady) { - this.customOptions.onReady(); - } - }); + ); ipcMain.on(Channel.acceptUpdate, this._acceptUpdateHandler.bind(this)); ipcMain.on(Channel.denyUpdate, this._denyUpdateHandler.bind(this)); diff --git a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts index e6096c75..ae936560 100644 --- a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts @@ -4,5 +4,7 @@ export enum Channel { cancelDownload = 'UCAP::ElectronUpdateWindow::cancelDownload', downloadProcess = 'UCAP::ElectronUpdateWindow::downloadProcess', - downloadComplete = 'UCAP::ElectronUpdateWindow::downloadComplete' + downloadComplete = 'UCAP::ElectronUpdateWindow::downloadComplete', + + browserWindowSetContents = 'UCAP::ElectronUpdateWindow::BrowserWindowSetContents' } diff --git a/electron-projects/ucap-webmessenger-electron/assets/notification/preload.js b/electron-projects/ucap-webmessenger-electron/assets/notification/preload.js index 86975a25..cbdaeb42 100644 --- a/electron-projects/ucap-webmessenger-electron/assets/notification/preload.js +++ b/electron-projects/ucap-webmessenger-electron/assets/notification/preload.js @@ -1,7 +1,7 @@ 'use strict'; const electron = require('electron'); -const ipc = electron.ipcRenderer; +const ipcRenderer = electron.ipcRenderer; const winId = electron.remote.getCurrentWindow().id; function setStyle(config) { @@ -90,13 +90,21 @@ function setContents(event, notificationObj) { let closeButton = notiDoc.getElementById('close'); closeButton.addEventListener('click', function(event) { event.stopPropagation(); - ipc.send('UCAP::ElectronNotification::close', winId, notificationObj); + ipcRenderer.send( + 'UCAP::ElectronNotification::close', + winId, + notificationObj + ); }); // URL let container = notiDoc.getElementById('container'); container.addEventListener('click', function() { - ipc.send('UCAP::ElectronNotification::click', winId, notificationObj); + ipcRenderer.send( + 'UCAP::ElectronNotification::click', + winId, + notificationObj + ); }); } @@ -130,9 +138,12 @@ function reset() { closeButton.parentNode.replaceChild(newCloseButton, closeButton); } -ipc.on('UCAP::ElectronNotification::BrowserWindowSetContents', setContents); -ipc.on('UCAP::ElectronNotification::loadConfig', loadConfig); -ipc.on('UCAP::ElectronNotification::reset', reset); +ipcRenderer.on( + 'UCAP::ElectronNotification::BrowserWindowSetContents', + setContents +); +ipcRenderer.on('UCAP::ElectronNotification::loadConfig', loadConfig); +ipcRenderer.on('UCAP::ElectronNotification::reset', reset); function log() { console.log.apply(console, arguments); diff --git a/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js b/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js index c1129d0b..15f28fe0 100644 --- a/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js +++ b/electron-projects/ucap-webmessenger-electron/assets/update-window/preload.js @@ -1,6 +1,7 @@ 'use strict'; -const { ipcRenderer } = require('electron'); +const electron = require('electron'); +const ipcRenderer = electron.ipcRenderer; const updateWindowContainer = document.getElementById( 'update-window-container' @@ -40,6 +41,16 @@ downloadingCancel && 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) => { @@ -55,3 +66,5 @@ ipcRenderer.on( updateWindowContainer.style.transform = 'translateX(-1000px)'; } ); + +ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents); diff --git a/electron-projects/ucap-webmessenger-electron/assets/update-window/template.html b/electron-projects/ucap-webmessenger-electron/assets/update-window/template.html index 9e697844..b6688a5b 100644 --- a/electron-projects/ucap-webmessenger-electron/assets/update-window/template.html +++ b/electron-projects/ucap-webmessenger-electron/assets/update-window/template.html @@ -13,7 +13,10 @@