version of update window is added

This commit is contained in:
richard-loafle 2020-01-22 17:21:11 +09:00
parent 41fb1b14a0
commit 464489da4e
8 changed files with 66 additions and 19 deletions

View File

@ -8,12 +8,18 @@ import {
} from '../models/electron-update-window-options'; } from '../models/electron-update-window-options';
import { Channel } from '../types/channel.type'; import { Channel } from '../types/channel.type';
import { ElectronWebContentsChannel } from '@ucap-webmessenger/electron-core';
export class ElectronUpdateWindowService { export class ElectronUpdateWindowService {
private customOptions: ElectronUpdateWindowOptions; private customOptions: ElectronUpdateWindowOptions;
private browserWindow: BrowserWindow; private browserWindow: BrowserWindow;
private templateUrl: string; private templateUrl: string;
versionInfo: {
installed?: string;
latest?: string;
};
constructor(options: ElectronUpdateWindowOptions) { constructor(options: ElectronUpdateWindowOptions) {
this.customOptions = { this.customOptions = {
...DefaultElectronUpdateWindowOptions ...DefaultElectronUpdateWindowOptions
@ -60,14 +66,22 @@ export class ElectronUpdateWindowService {
this.browserWindow.on('closed', () => { this.browserWindow.on('closed', () => {
this.browserWindow = null; this.browserWindow = null;
}); });
this.browserWindow.webContents.on('did-finish-load', () => { this.browserWindow.webContents.on(
if (process.env.NODE_ENV === 'development') { ElectronWebContentsChannel.DidFinishLoad,
this.browserWindow.webContents.openDevTools(); () => {
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.acceptUpdate, this._acceptUpdateHandler.bind(this));
ipcMain.on(Channel.denyUpdate, this._denyUpdateHandler.bind(this)); ipcMain.on(Channel.denyUpdate, this._denyUpdateHandler.bind(this));

View File

@ -4,5 +4,7 @@ export enum Channel {
cancelDownload = 'UCAP::ElectronUpdateWindow::cancelDownload', cancelDownload = 'UCAP::ElectronUpdateWindow::cancelDownload',
downloadProcess = 'UCAP::ElectronUpdateWindow::downloadProcess', downloadProcess = 'UCAP::ElectronUpdateWindow::downloadProcess',
downloadComplete = 'UCAP::ElectronUpdateWindow::downloadComplete' downloadComplete = 'UCAP::ElectronUpdateWindow::downloadComplete',
browserWindowSetContents = 'UCAP::ElectronUpdateWindow::BrowserWindowSetContents'
} }

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const electron = require('electron'); const electron = require('electron');
const ipc = electron.ipcRenderer; const ipcRenderer = electron.ipcRenderer;
const winId = electron.remote.getCurrentWindow().id; const winId = electron.remote.getCurrentWindow().id;
function setStyle(config) { function setStyle(config) {
@ -90,13 +90,21 @@ function setContents(event, notificationObj) {
let closeButton = notiDoc.getElementById('close'); let closeButton = notiDoc.getElementById('close');
closeButton.addEventListener('click', function(event) { closeButton.addEventListener('click', function(event) {
event.stopPropagation(); event.stopPropagation();
ipc.send('UCAP::ElectronNotification::close', winId, notificationObj); ipcRenderer.send(
'UCAP::ElectronNotification::close',
winId,
notificationObj
);
}); });
// URL // URL
let container = notiDoc.getElementById('container'); let container = notiDoc.getElementById('container');
container.addEventListener('click', function() { 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); closeButton.parentNode.replaceChild(newCloseButton, closeButton);
} }
ipc.on('UCAP::ElectronNotification::BrowserWindowSetContents', setContents); ipcRenderer.on(
ipc.on('UCAP::ElectronNotification::loadConfig', loadConfig); 'UCAP::ElectronNotification::BrowserWindowSetContents',
ipc.on('UCAP::ElectronNotification::reset', reset); setContents
);
ipcRenderer.on('UCAP::ElectronNotification::loadConfig', loadConfig);
ipcRenderer.on('UCAP::ElectronNotification::reset', reset);
function log() { function log() {
console.log.apply(console, arguments); console.log.apply(console, arguments);

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const { ipcRenderer } = require('electron'); const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
const updateWindowContainer = document.getElementById( const updateWindowContainer = document.getElementById(
'update-window-container' 'update-window-container'
@ -40,6 +41,16 @@ downloadingCancel &&
ipcRenderer.send('UCAP::ElectronUpdateWindow::cancelDownload'); 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( ipcRenderer.on(
'UCAP::ElectronUpdateWindow::downloadProcess', 'UCAP::ElectronUpdateWindow::downloadProcess',
(event, ...args) => { (event, ...args) => {
@ -55,3 +66,5 @@ ipcRenderer.on(
updateWindowContainer.style.transform = 'translateX(-1000px)'; updateWindowContainer.style.transform = 'translateX(-1000px)';
} }
); );
ipc.on('UCAP::ElectronUpdateWindow::BrowserWindowSetContents', setContents);

View File

@ -13,7 +13,10 @@
<!--[S]버전다운로드--> <!--[S]버전다운로드-->
<div id="confirmation" class="versionup popup step1"> <div id="confirmation" class="versionup popup step1">
<header> <header>
<h1>DS Talk의 새로운 버전이 존재합니다.</h1> <h1>
DS Talk의 새로운 버전[<span id="latestVersion"></span>]이
존재합니다.
</h1>
</header> </header>
<!-- <a class="no-drag btn_close"> <!-- <a class="no-drag btn_close">
<label class="global">닫기</label> <label class="global">닫기</label>

View File

@ -359,6 +359,10 @@ ipcMain.on(UpdaterChannel.Check, (event: IpcMainEvent, ...args: any[]) => {
const ver = args[0]; const ver = args[0];
if (semver.lt(app.getVersion(), ver)) { if (semver.lt(app.getVersion(), ver)) {
updateWindowService.versionInfo = {
latest: ver,
installed: app.getVersion()
};
autoUpdater autoUpdater
.checkForUpdatesAndNotify() .checkForUpdatesAndNotify()
.then(result => { .then(result => {

View File

@ -76,7 +76,7 @@
"information": { "information": {
"label": "Information", "label": "Information",
"version": "Version", "version": "Version",
"installedVersion": "Installed version", "installedVersion": "Current version",
"latestVersion": "Latest version", "latestVersion": "Latest version",
"checkForUpdates": "Check for updates", "checkForUpdates": "Check for updates",
"checkForUpdatesInProgress": "Checking for updates", "checkForUpdatesInProgress": "Checking for updates",

View File

@ -76,9 +76,9 @@
"information": { "information": {
"label": "정보", "label": "정보",
"version": "버전", "version": "버전",
"installedVersion": "설치된 버전", "installedVersion": "현재 버전",
"latestVersion": "최신 버전", "latestVersion": "최신 버전",
"checkForUpdates": "업데이트 확인", "checkForUpdates": "버전 확인",
"checkForUpdatesInProgress": "업데이트를 확인하고 있습니다.", "checkForUpdatesInProgress": "업데이트를 확인하고 있습니다.",
"applyUpdates": "업데이트 설치" "applyUpdates": "업데이트 설치"
}, },