From 00fe005ecc7567c5bc505886cccdb47cda5774a2 Mon Sep 17 00:00:00 2001 From: mediaslav Date: Sat, 4 Mar 2017 17:11:12 +0300 Subject: [PATCH] - handle submodule npm tasks - autoupdate dialog --- war/electron.js | 50 ++++++++++++++++++++++++++++++++++---- war/package.json | 62 ++++++++++++++++++++++++------------------------ 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/war/electron.js b/war/electron.js index ddb3cbc0..8cfdf4f5 100644 --- a/war/electron.js +++ b/war/electron.js @@ -1,11 +1,19 @@ const fs = require('fs') const path = require('path') +const url = require('url') const electron = require('electron') const ipcMain = electron.ipcMain const dialog = electron.dialog const app = electron.app const BrowserWindow = electron.BrowserWindow +const autoUpdater = require('electron-updater').autoUpdater +autoUpdater.logger = require('electron-log') +autoUpdater.logger.transports.file.level = 'info' +autoUpdater.autoDownload = false + +const __DEV__ = process.env.NODE_ENV === 'development' + let windowsRegistry = [] function createWindow (opt = {}) { @@ -13,6 +21,9 @@ function createWindow (opt = {}) { width: 1600, height: 1200, 'web-security': false, + webPreferences: { + // preload: path.resolve('./preload.js'), + }, }, opt) let mainWindow = new BrowserWindow(options) @@ -20,9 +31,27 @@ function createWindow (opt = {}) { console.log('createWindow', opt) + let wurl = url.format({ + pathname: `${__dirname}/index.html`, + protocol: 'file:', + query: { + 'dev': __DEV__ ? 1 : 0, + 'test': '1', + 'db': '0', + 'gapi': '0', + 'od': '0', + 'analytics': '0', + 'picker': '0', + 'mode': 'device', + 'browser': '0', + 'p': 'electron', + }, + slashes: true, + }) + +//`file://${__dirname}/index.html?dev=1&test=1&db=0&gapi=0&od=0&analytics=0&picker=0&mode=device&browser=0&p=electron` // and load the index.html of the app. - mainWindow.loadURL( - `file://${__dirname}/index.html?dev=1&test=1&db=0&gapi=0&od=0&analytics=0&picker=0&mode=device&browser=0&p=electron`) + mainWindow.loadURL(wurl) // Open the DevTools. mainWindow.webContents.openDevTools() @@ -85,6 +114,7 @@ app.on('ready', e => { event.returnValue = 'pong' }) createWindow() + checkUpdate() }) // Quit when all windows are closed. @@ -106,5 +136,17 @@ app.on('activate', function () { } }) -// In this file you can include the rest of your app's specific main process -// code. You can also put them in separate files and require them here. +function checkUpdate () { + autoUpdater.checkForUpdates().then(UpdateCheckResult => { + if (UpdateCheckResult) { + let idx = dialog.showMessageBox({ + type: 'question', + buttons: ['Ok', 'Cancel'], + title: 'Confirm Update', + message: 'Update available.\n\nWould you like to download and install new version?', + detail: 'Application will automatically restart to apply update after download', + }) + if (idx === 0) return autoUpdater.downloadUpdate() + } + }) +} diff --git a/war/package.json b/war/package.json index 71184675..ca144e6f 100644 --- a/war/package.json +++ b/war/package.json @@ -1,32 +1,32 @@ { - "name": "draw.io", - "version": "1.0.0", - "description": "draw.io desktop", - "main": "electron.js", - "scripts": - { - "start": "electron ." - }, - "repository": - { - "type": "git", - "url": "git+https://github.com/jgraph/draw.io.git" - }, - "keywords": [ - "draw.io", - "diagram", - "flowchart", - "UML" - ], - "author": "JGraph", - "license": "GPL-3.0", - "bugs": - { - "url": "https://github.com/jgraph/draw.io/issues" - }, - "homepage": "https://github.com/jgraph/draw.io", - "devDependencies": - { - "electron": "^1.4.13" - } -} + "name": "draw.io", + "version": "6.2.1", + "description": "draw.io desktop", + "main": "electron.js", + "scripts": { + "start": "electron ." + }, + "repository": { + "type": "git", + "url": "git+https://github.com/jgraph/draw.io.git" + }, + "keywords": [ + "draw.io", + "diagram", + "flowchart", + "UML" + ], + "author": "JGraph", + "license": "GPL-3.0", + "bugs": { + "url": "https://github.com/jgraph/draw.io/issues" + }, + "homepage": "https://github.com/jgraph/draw.io", + "dependencies": { + "electron-log": "^1.3.0", + "electron-updater": "^1.8.1" + }, + "devDependencies": { + "electron": "^1.6.2" + } +} \ No newline at end of file