From e4a42d0dcc211571b9f8e2a4ee1f29c7e6c2135c Mon Sep 17 00:00:00 2001 From: Richard Park Date: Mon, 16 Dec 2019 01:06:07 +0900 Subject: [PATCH] electron update window is implemented --- .../services/electron-notification.service.ts | 36 +-- .../models/electron-update-window-options.ts | 22 ++ .../electron-update-window.service.ts | 123 +++++++++- .../src/lib/types/channel.type.ts | 8 + .../src/public-api.ts | 4 + .../update-window/images/btnimg_top_close.png | Bin 0 -> 3585 bytes .../resources/update-window/preload.js | 57 +++++ .../update-window/styles/update-window.css | 230 ++++++++++++++++++ .../resources/update-window/template.html | 86 +++++++ .../ucap-webmessenger-electron/src/index.ts | 80 +++++- 10 files changed, 626 insertions(+), 20 deletions(-) create mode 100644 electron-projects/ucap-webmessenger-electron-update-window/src/lib/models/electron-update-window-options.ts create mode 100644 electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts create mode 100644 electron-projects/ucap-webmessenger-electron/resources/update-window/images/btnimg_top_close.png create mode 100644 electron-projects/ucap-webmessenger-electron/resources/update-window/styles/update-window.css diff --git a/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts b/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts index ea13e059..0fdc8062 100644 --- a/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts +++ b/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts @@ -1,11 +1,11 @@ -import * as path from 'path'; -import * as url from 'url'; -import * as fse from 'fs-extra'; +import path from 'path'; +import url from 'url'; +import fse from 'fs-extra'; import { AnimationQueue } from '../utils/animation-queue'; import { ElectronNotificationOptions, - DefaultElectronNotificationOptions, + DefaultElectronNotificationOptions } from '../models/electron-notification-options'; import { screen, BrowserWindow, ipcMain, IpcMainEvent, shell } from 'electron'; import { ElectronNotification } from '../models/electron-notification'; @@ -43,12 +43,12 @@ export class ElectronNotificationService { constructor(options?: ElectronNotificationOptions) { this.customOptions = { - ...DefaultElectronNotificationOptions, + ...DefaultElectronNotificationOptions }; if (!!options) { this.customOptions = { ...this.customOptions, - ...options, + ...options }; } @@ -60,7 +60,7 @@ export class ElectronNotificationService { if (!!options) { this.customOptions = { ...this.customOptions, - ...options, + ...options }; } this.calcDimensions(); @@ -89,7 +89,7 @@ export class ElectronNotificationService { this.animationQueue.push({ context: this, func: this.showNotification, - args: [notification], + args: [notification] }); return notification.id; } @@ -124,7 +124,7 @@ export class ElectronNotificationService { this.lowerRightCornerPosition = { x: display.bounds.x + display.workArea.x + display.workAreaSize.width, - y: display.bounds.y + display.workArea.y + display.workAreaSize.height, + y: display.bounds.y + display.workArea.y + display.workAreaSize.height }; this.calcDimensions(); @@ -177,7 +177,7 @@ export class ElectronNotificationService { notificationWindow[onClickElectronNotification]({ type: ElectronNotificationEventType.Click, id: notification.id, - close: self.buildCloseNotificationSafely(onClose), + close: self.buildCloseNotificationSafely(onClose) }); delete notificationWindow[onClickElectronNotification]; } @@ -188,17 +188,17 @@ export class ElectronNotificationService { private calcDimensions() { this.totalDimension = { width: this.customOptions.width + this.customOptions.padding, - height: this.customOptions.height + this.customOptions.padding, + height: this.customOptions.height + this.customOptions.padding }; this.firstPosition = { x: this.lowerRightCornerPosition.x - this.totalDimension.width, - y: this.lowerRightCornerPosition.y - this.totalDimension.height, + y: this.lowerRightCornerPosition.y - this.totalDimension.height }; this.nextInsertPosition = { x: this.firstPosition.x, - y: this.firstPosition.y, + y: this.firstPosition.y }; } @@ -217,7 +217,7 @@ export class ElectronNotificationService { this.templateUrl = url.format({ pathname: this.customOptions.templatePath, protocol: 'file:', - slashes: true, + slashes: true }); } catch (e) { console.log( @@ -266,7 +266,7 @@ export class ElectronNotificationService { notification.onShow({ type: ElectronNotificationEventType.Show, id: notification.id, - close: onCloseNotificationSafely, + close: onCloseNotificationSafely }); } @@ -321,7 +321,7 @@ export class ElectronNotificationService { if (!!notificationWindow[onCloseElectronNotification]) { notificationWindow[onCloseElectronNotification]({ type: e, - id: notification.id, + id: notification.id }); delete notificationWindow[onCloseElectronNotification]; } @@ -353,7 +353,7 @@ export class ElectronNotificationService { self.animationQueue.push({ context: self, func: onClose, - args: [reason], + args: [reason] }); }; } @@ -366,7 +366,7 @@ export class ElectronNotificationService { this.animationQueue.push({ context: this, func: this.showNotification, - args: [this.notificationQueue.shift()], + args: [this.notificationQueue.shift()] }); } } diff --git a/electron-projects/ucap-webmessenger-electron-update-window/src/lib/models/electron-update-window-options.ts b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/models/electron-update-window-options.ts new file mode 100644 index 00000000..2f509efe --- /dev/null +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/models/electron-update-window-options.ts @@ -0,0 +1,22 @@ +import { BrowserWindowConstructorOptions } from 'electron'; + +export interface ElectronUpdateWindowOptions + extends BrowserWindowConstructorOptions { + templatePath?: string; + onReady?: () => void; + onAcceptUpdate?: () => void; + onDenyUpdate?: () => void; + onCancelDownload?: () => void; +} + +export const DefaultElectronUpdateWindowOptions: ElectronUpdateWindowOptions = { + width: 500, + height: 160, + frame: false, + skipTaskbar: true, + alwaysOnTop: true, + maximizable: false, + webPreferences: { + nodeIntegration: true + } +}; 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 886ec675..127a550f 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 @@ -1 +1,122 @@ -export class ElectronUpdateWindowService {} +import { BrowserWindow, ipcMain } from 'electron'; +import url from 'url'; +import fse from 'fs-extra'; +import { + ElectronUpdateWindowOptions, + DefaultElectronUpdateWindowOptions +} from '../models/electron-update-window-options'; + +import { Channel } from '../types/channel.type'; + +export class ElectronUpdateWindowService { + private customOptions: ElectronUpdateWindowOptions; + private browserWindow: BrowserWindow; + private templateUrl: string; + + constructor(options: ElectronUpdateWindowOptions) { + this.customOptions = { + ...DefaultElectronUpdateWindowOptions + }; + if (!!options) { + this.customOptions = { + ...this.customOptions, + ...options + }; + } + } + + set options(options: ElectronUpdateWindowOptions) { + if (!!options) { + this.customOptions = { + ...this.customOptions, + ...options + }; + } + } + + get options(): ElectronUpdateWindowOptions { + return this.customOptions; + } + + set templatePath(templatePath: string) { + if (!!templatePath) { + this.customOptions.templatePath = templatePath; + this.updateTemplatePath(); + } + } + + get templatePath(): string { + if (!this.templateUrl) { + this.updateTemplatePath(); + } + return this.templateUrl; + } + + show() { + this.browserWindow = new BrowserWindow(this.customOptions); + this.browserWindow.loadURL(this.templatePath); + + this.browserWindow.on('closed', () => { + this.browserWindow = null; + }); + this.browserWindow.webContents.on('did-finish-load', () => { + if (process.env.NODE_ENV === 'development') { + this.browserWindow.webContents.openDevTools(); + } + if (!!this.customOptions.onReady) { + this.customOptions.onReady(); + } + }); + + ipcMain.on(Channel.acceptUpdate, this._acceptUpdateHandler.bind(this)); + ipcMain.on(Channel.denyUpdate, this._denyUpdateHandler.bind(this)); + ipcMain.on(Channel.cancelDownload, this._cancelDownloadHandler.bind(this)); + } + + setDownloadValue(value: number, total: number) { + this.browserWindow.webContents.send(Channel.downloadProcess, value, total); + } + setDownloadComplete() { + this.browserWindow.webContents.send(Channel.downloadComplete); + } + close() { + if (!this.browserWindow || this.browserWindow.isDestroyed()) { + return; + } + this.browserWindow.destroy(); + } + + _acceptUpdateHandler() { + if (!!this.customOptions.onAcceptUpdate) { + this.customOptions.onAcceptUpdate(); + } + } + _denyUpdateHandler() { + if (!!this.customOptions.onDenyUpdate) { + this.customOptions.onDenyUpdate(); + } + } + _cancelDownloadHandler() { + if (!!this.customOptions.onCancelDownload) { + this.customOptions.onCancelDownload(); + } + } + + private updateTemplatePath() { + try { + fse.statSync(this.customOptions.templatePath).isFile(); + + this.templateUrl = url.format({ + pathname: this.customOptions.templatePath, + protocol: 'file:', + slashes: true + }); + } catch (e) { + console.log( + 'electron-update-window: Could not find template ("' + + this.customOptions.templatePath + + '").' + ); + } + } +} 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 new file mode 100644 index 00000000..e6096c75 --- /dev/null +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/lib/types/channel.type.ts @@ -0,0 +1,8 @@ +export enum Channel { + acceptUpdate = 'UCAP::ElectronUpdateWindow::acceptUpdate', + denyUpdate = 'UCAP::ElectronUpdateWindow::denyUpdate', + cancelDownload = 'UCAP::ElectronUpdateWindow::cancelDownload', + + downloadProcess = 'UCAP::ElectronUpdateWindow::downloadProcess', + downloadComplete = 'UCAP::ElectronUpdateWindow::downloadComplete' +} diff --git a/electron-projects/ucap-webmessenger-electron-update-window/src/public-api.ts b/electron-projects/ucap-webmessenger-electron-update-window/src/public-api.ts index 8efee9e2..792a87f2 100644 --- a/electron-projects/ucap-webmessenger-electron-update-window/src/public-api.ts +++ b/electron-projects/ucap-webmessenger-electron-update-window/src/public-api.ts @@ -1,3 +1,7 @@ /* * Public API Surface of ucap-webmessenger-electron-update-window */ + +export * from './lib/models/electron-update-window-options'; +export * from './lib/services/electron-update-window.service'; +export * from './lib/types/channel.type'; diff --git a/electron-projects/ucap-webmessenger-electron/resources/update-window/images/btnimg_top_close.png b/electron-projects/ucap-webmessenger-electron/resources/update-window/images/btnimg_top_close.png new file mode 100644 index 0000000000000000000000000000000000000000..0ce0aba0c472a7ebac3374d27f50c11740698963 GIT binary patch literal 3585 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 { + 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'); + }); + +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)'; + } +); diff --git a/electron-projects/ucap-webmessenger-electron/resources/update-window/styles/update-window.css b/electron-projects/ucap-webmessenger-electron/resources/update-window/styles/update-window.css new file mode 100644 index 00000000..d40e3fbb --- /dev/null +++ b/electron-projects/ucap-webmessenger-electron/resources/update-window/styles/update-window.css @@ -0,0 +1,230 @@ +@charset "utf-8"; + +html { + height: 100%; + overflow-y: hidden; + -webkit-user-select: none; + -webkit-app-region: drag; +} +body { + position: absolute; + width: 500px; + height: 160px; + padding: 0; + margin: 0; + color: #333; + font-family: '나눔고딕', Malgun Gothic, '맑은고딕', Arial, Dotum, '돋움', + Gulim, '굴림'; + font-size: 12px; + line-height: 18px !important; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +div, +p, +ol, +ul, +li, +h1, +h2, +h3, +h4, +h5, +h6, +form, +iframe, +dl, +dt, +dd, +a { + margin: 0; + padding: 0; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + +::-webkit-scrollbar { + display: none; +} + +.no-drag { + -webkit-app-region: no-drag; +} + +.popup { + border: 1px solid #666; + position: absolute; +} +.popup header { + width: 100%; + height: 36px; + background-image: none; + color: #6f6f6f; + background-color: #fff; + border-bottom: solid 1px #28abdb; +} +.popup header h1 { + width: 100%; + background: none; + text-align: center; + font-size: 16px; + line-height: 50px; + font-size: 14px; + margin: 0; + padding: 0; +} +.popup .btn_close { + position: absolute; + top: 4px; + right: 4px; + width: 20px; + height: 25px; + font-size: 0; + margin-right: 6px; + vertical-align: middle; + background: url(../images/btnimg_top_close.png) no-repeat 50% 50%; +} +.popup .btn_close:hover { + opacity: 0.8; +} +.versionup .btns { + height: 50px; + position: absolute; + bottom: 0; + width: 100%; + text-align: center; + padding: 10px; +} +.btns ul { + list-style: none; +} +.btns li { + display: inline-block; + width: 70px; + height: 30px; + margin: 0 2px; +} +.btns li a { + display: block; + width: 70px; + height: 30px; + border-radius: 3px; + text-align: center; + line-height: 28px; + text-decoration: none; +} +.btnNormal { + background-color: #eee; + color: #333; +} +.btnSpecial { + background-color: #3385bd; + color: #fff; +} +.btns li a:hover { + opacity: 0.8; +} + +#update-window-container { + position: absolute; + width: 1500px; + height: 160px; + overflow: hidden; + margin-top: 0px; + margin-left: 0px; + + -webkit-transition: all 500ms ease-in-out; + -moz-transition: all 500ms ease-in-out; + -o-transition: all 500ms ease-in-out; + transition: all 500ms ease-in-out; +} + +/******************************************************************************************************************************************* +.versionup +*******************************************************************************************************************************************/ +/* .versionup { + position: absolute; + top: 0; + left: 500px; +} +.versionup.on { + position: absolute; + top: 0; + left: 0; +} */ +.versionup { + width: 500px; + height: 160px; + background-color: #fff; +} +.versionup header { + height: 50px !important; + border-bottom: none !important; +} +.versionup header h1 { + font-size: 16px; + line-height: 50px; +} +.versionup .download p { + text-align: center; + margin-bottom: 10px; + font-size: 12px; +} +.versionup .download { + position: relative; + padding: 0 20px; +} +.versionup .btns { + height: 50px; + position: absolute; + bottom: 0; + width: 100%; + text-align: center; +} + +.versionup.step1 { + position: absolute; + top: 0; + left: 0; +} + +.versionup.step2 { + position: absolute; + top: 0; + left: 500; +} + +.versionup.step3 { + position: absolute; + top: 0; + left: 1000; +} + +/******************************************************************************************************************************************* + progress +*******************************************************************************************************************************************/ +.progress { + background-color: #efefef; + height: 12px; + margin: 0 !important; +} +.progress .bar { + width: 0%; + height: 12px; + position: relative; + color: #fff; + font-size: 11px; + text-align: right; + margin: 0 !important; + line-height: 12px; +} + +/*theme별 색상변경*/ +.versionup .download p { + color: #13b7eb; +} +.progress .bar { + background-color: #13b7eb; +} diff --git a/electron-projects/ucap-webmessenger-electron/resources/update-window/template.html b/electron-projects/ucap-webmessenger-electron/resources/update-window/template.html index e69de29b..9e697844 100644 --- a/electron-projects/ucap-webmessenger-electron/resources/update-window/template.html +++ b/electron-projects/ucap-webmessenger-electron/resources/update-window/template.html @@ -0,0 +1,86 @@ + + + + DS Talk Update + + + + + + + +
+ + + + + + + + + +
+ + + diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index 0fb16520..ae04d919 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -1,6 +1,7 @@ import { app, ipcMain, IpcMainEvent, Tray, Menu, shell } from 'electron'; import path from 'path'; import fse from 'fs-extra'; +import semver from 'semver'; import { AppWindow } from './app/AppWindow'; import { now } from './util/now'; @@ -15,6 +16,7 @@ import { MessengerChannel } from '@ucap-webmessenger/native-electron'; import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification'; +import { ElectronUpdateWindowService } from '@ucap-webmessenger/electron-update-window'; import { root } from './util/root'; import { DefaultFolder } from './lib/default-folder'; @@ -48,6 +50,7 @@ let onDidLoadFns: Array | null = []; let preventQuit = false; let notificationService: ElectronNotificationService | null; +let updateWindowService: ElectronUpdateWindowService | null; function handleUncaughtException(error: Error) { preventQuit = true; @@ -242,6 +245,41 @@ app.on(ElectronAppChannel.Ready, () => { 'resources/notification/template.html' ); + updateWindowService = new ElectronUpdateWindowService({ + width: 500, + height: 160, + frame: false, + skipTaskbar: true, + alwaysOnTop: true, + maximizable: false, + onReady: () => {}, + onAcceptUpdate: () => { + log.info('OnAcceptUpdate'); + autoUpdaterCancellationToken = new CancellationToken(); + autoUpdater.downloadUpdate(autoUpdaterCancellationToken); + }, + onDenyUpdate: () => { + log.info('OnDenyUpdate'); + updateWindowService.close(); + }, + onCancelDownload: () => { + autoUpdaterCancellationToken.cancel(); + updateWindowService.close(); + } + }); + + updateWindowService.options.webPreferences.preload = path.join( + __dirname, + 'resources/update-window/preload.js' + ); + + updateWindowService.templatePath = path.join( + __dirname, + 'resources/update-window/template.html' + ); + + // updateWindowService.show(); + ipcMain.on('uncaught-exception', (event: IpcMainEvent, error: Error) => { handleUncaughtException(error); }); @@ -281,7 +319,13 @@ function onDidLoad(fn: OnDidLoadFn) { } ipcMain.on(UpdaterChannel.Check, (event: IpcMainEvent, ...args: any[]) => { - event.returnValue = false; + const ver = args[0]; + if (semver.lt(app.getVersion(), ver)) { + autoUpdater.checkForUpdatesAndNotify(); + return true; + } else { + return false; + } }); ipcMain.on( @@ -443,3 +487,37 @@ ipcMain.on( console.log('Channel.closeAllNotify', args); } ); + +autoUpdater.on('checking-for-update', () => { + log.info('Checking for update...'); +}); +autoUpdater.on('update-available', info => { + log.info(info); + log.info('Update available.'); + + updateWindowService.show(); +}); +autoUpdater.on('update-not-available', info => { + log.info('Update not available.'); +}); +autoUpdater.on('error', err => { + log.info('Error in auto-updater. ' + err); +}); +autoUpdater.on('download-progress', progressObj => { + let logMessage = 'Download speed: ' + progressObj.bytesPerSecond; + logMessage = logMessage + ' - Downloaded ' + progressObj.percent + '%'; + logMessage = + logMessage + ' (' + progressObj.transferred + '/' + progressObj.total + ')'; + log.info(logMessage); + + updateWindowService.setDownloadValue( + progressObj.transferred, + progressObj.total + ); +}); +autoUpdater.on('update-downloaded', info => { + log.info('Update downloaded'); + + updateWindowService.setDownloadComplete(); + autoUpdater.quitAndInstall(true, true); +});