From ddfdbdc91cc1edc518cd1bde26d6695194c3f7a1 Mon Sep 17 00:00:00 2001 From: Lawrence Thorpe Date: Sun, 23 Jul 2017 20:29:03 +0100 Subject: [PATCH] Implement auto update --- README.md | 2 +- main.js | 25 +++++++++++++++++++++++-- package.json | 16 ++++++++++++---- renderer.js | 16 ++++++++-------- yarn.lock | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2a8e410..a58ed7f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![](resources/icon256.png) -ZX Spectrum style text editor +Text editor with ZX Spectrum theme Created with Electron and NodeJS Based on Monaco Code Editor diff --git a/main.js b/main.js index 72f3906..0ab901d 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,6 @@ const { app, BrowserWindow, ipcMain } = require('electron') +const log = require('electron-log') +const { autoUpdater } = require('electron-updater') let win @@ -29,7 +31,26 @@ function createWindow() { }) } -app.on('ready', createWindow) +log.info("App starting...") + +autoUpdater.logger = log +autoUpdater.logger.transports.file.level = 'info' + +autoUpdater.on('download-progress', (progressObj) => { + let log_message = "Download speed: " + progressObj.bytesPerSecond; + log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'; + log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'; + sendStatusToWindow(log_message); +}) + +autoUpdater.on('update-downloaded', (info) => { + autoUpdater.quitAndInstall() +}) + +app.on('ready', () => { + createWindow() + autoUpdater.checkForUpdates() +}) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { @@ -37,7 +58,7 @@ app.on('window-all-closed', () => { } }) -app.on('active', () => { +app.on('activate', () => { if (win === null) { createWindow() } diff --git a/package.json b/package.json index 40505cf..07b299f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spectrum-editor", - "version": "1.0.0", + "version": "1.1.0", "main": "main.js", "scripts": { "start": "electron .", @@ -9,12 +9,14 @@ }, "author": "Lawrence Thorpe", "license": "MIT", - "description": "ZX Spectrum style text editor", + "description": "Text editor with ZX Spectrum theme", "devDependencies": { "electron": "^1.6.11", "electron-builder": "^19.16.0" }, "dependencies": { + "electron-log": "^2.2.7", + "electron-updater": "^2.7.1", "monaco-editor": "^0.9.0", "monaco-loader": "^0.8.2" }, @@ -25,10 +27,16 @@ "category": "public.app-category.developer-tools" }, "linux": { - "target": [ "tar.gz", "AppImage" ] + "target": [ + "tar.gz", + "AppImage" + ] }, "win": { - "target": [ "nsis", "zip" ] + "target": [ + "nsis", + "zip" + ] } }, "repository": { diff --git a/renderer.js b/renderer.js index f1e79d3..f53ac0e 100644 --- a/renderer.js +++ b/renderer.js @@ -86,15 +86,15 @@ loader().then((monaco) => { ipcRenderer.on('open-file', (e, path) => { if (path) { - fs.readFile(path, 'utf8', (err, data) => { - if (err) console.error(err) - if (monaco.editor.getModel(path)) { - editor.setModel(monaco.editor.getModel(path)) - } - else { + if (monaco.editor.getModel(path)) { + editor.setModel(monaco.editor.getModel(path)) + } + else { + fs.readFile(path, 'utf8', (err, data) => { + if (err) console.error(err) editor.setModel(monaco.editor.createModel(data, null, path)) - } - }) + }) + } } }) diff --git a/yarn.lock b/yarn.lock index 820e3c8..550618c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -459,6 +459,14 @@ electron-download@^3.0.1: semver "^5.3.0" sumchecker "^1.2.0" +electron-is-dev@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-0.2.0.tgz#4bd0457a43327266de6fbdf29a5a65852f32bef2" + +electron-log@^2.2.7: + version "2.2.7" + resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-2.2.7.tgz#8da0d2586b53b175392ae6b91dc510a67c195341" + electron-osx-sign@0.4.6: version "0.4.6" resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.6.tgz#2398e2d7cab5c1d8c3eeabb1cd490376528ec39a" @@ -482,6 +490,22 @@ electron-publish@19.16.0: fs-extra-p "^4.3.0" mime "^1.3.6" +electron-updater@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-2.7.1.tgz#ead9f08f38af8983c6f9185a1931dc8582b60187" + dependencies: + bluebird-lst "^1.0.2" + debug "^2.6.8" + electron-builder-http "~19.16.0" + electron-is-dev "^0.2.0" + fs-extra-p "^4.3.0" + js-yaml "^3.9.0" + lodash.isequal "^4.5.0" + semver "^5.3.0" + source-map-support "^0.4.15" + uuid-1345 "^0.99.6" + xelement "^1.0.16" + electron@^1.6.11: version "1.6.11" resolved "https://registry.yarnpkg.com/electron/-/electron-1.6.11.tgz#be79c0ebdcefedb5bf28117409800fa53baceffa" @@ -942,6 +966,10 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + lodash.toarray@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561" @@ -1395,6 +1423,10 @@ sanitize-filename@^1.6.1: dependencies: truncate-utf8-bytes "^1.0.0" +sax@^1.2.1: + version "1.2.4" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" + semver-diff@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-2.1.0.tgz#4bbb8437c8d37e4b0cf1a68fd726ec6d645d6d36" @@ -1746,6 +1778,12 @@ xdg-basedir@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" +xelement@^1.0.16: + version "1.0.16" + resolved "https://registry.yarnpkg.com/xelement/-/xelement-1.0.16.tgz#900bb46c20fc2dffadff778a9d2dc36699d0ff7e" + dependencies: + sax "^1.2.1" + xmlbuilder@8.2.2: version "8.2.2" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"