From 4c68fd359b60dfb2d35c2b93929167a73b2efc18 Mon Sep 17 00:00:00 2001 From: romslf Date: Thu, 9 Sep 2021 02:25:42 +0200 Subject: [PATCH] Adding updater --- components/header.vue | 5 +- main.js | 51 +++++++++++++++++-- package-lock.json | 115 +++++++++++++++++++++++++++++++++++++++++- package.json | 10 +++- pages/docker.vue | 3 -- 5 files changed, 173 insertions(+), 11 deletions(-) diff --git a/components/header.vue b/components/header.vue index 4d97dd3..52d7c11 100644 --- a/components/header.vue +++ b/components/header.vue @@ -51,8 +51,11 @@ +
- + + +
diff --git a/main.js b/main.js index 86fab89..f97ac27 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ /* ** Nuxt */ +const { autoUpdater } = require("electron-updater"); const http = require('http') const { Nuxt, Builder } = require('nuxt') let config = require('./nuxt.config.js') @@ -29,15 +30,55 @@ const electron = require('electron') const path = require('path') const app = electron.app const newWin = () => { + const options = { + type: "question", + buttons: ["No, thanks", "Yes, please"], + defaultId: 1, + title: "Question", + message: "Do you want to do this?" + }; + + autoUpdater.on("update-available", () => { + if (process.platform === "win32" || process.platform === "win64") { + options.title = "Update"; + options.message = "Update available, download it ?"; + dialog.showMessageBox(null, options, (response) => { + if (response === 1) { + autoUpdater.downloadUpdate(); + autoUpdater.on("update-downloaded", () => { + autoUpdater.quitAndInstall(); + }); + } + }); + } else { + options.title = "Update"; + options.message = "Update available, download it ?"; + dialog.showMessageBox(null, options, (response) => { + if (response === 1) { + let child = new BrowserWindow({ modal: false, show: false }); + child.loadURL("https://github.com/romslf/system-companion/releases/latest"); + child.once("ready-to-show", () => { + child.show(); + }); + } + }); + } + }); + + autoUpdater.on("error", (err) => { + console.log(err); + }); + win = new electron.BrowserWindow({ icon: path.join(__dirname, 'static/icons/win-icon.ico'), webPreferences: { - nodeIntegration: true, + nodeIntegration: true, contextIsolation: false, enableRemoteModule: true, - } + }, + autoHideMenuBar: true }) - win.maximize() + //win.maximize() win.on('closed', () => win = null) if (config.dev) { // Install vue dev tool and open chrome dev tools @@ -54,6 +95,10 @@ const newWin = () => { } pollServer() } else { return win.loadURL(_NUXT_URL_) } + //this._create(); + autoUpdater.autoDownload = false; + console.log("Checking updates ...") + autoUpdater.checkForUpdates(); } app.on('ready', newWin) app.on('window-all-closed', () => app.quit()) diff --git a/package-lock.json b/package-lock.json index 4bee46c..f336d77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -291,6 +291,11 @@ "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==" }, + "@types/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-D/2EJvAlCEtYFEYmmlGwbGXuK886HzyCc3nZX/tkFTQdEU8jZDAgiv08P162yB17y4ZXZoq7yFAnW4GDBb9Now==" + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -3741,6 +3746,103 @@ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.833.tgz", "integrity": "sha512-h+9aVaUHjyunLqtCjJF2jrJ73tYcJqo2cCGKtVAXH9WmnBsb8hiChRQ0P1uXjdxR6Wcfxibephy41c1YlZA/pA==" }, + "electron-updater": { + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-4.3.9.tgz", + "integrity": "sha512-LCNfedSwZfS4Hza+pDyPR05LqHtGorCStaBgVpRnfKxOlZcvpYEX0AbMeH5XUtbtGRoH2V8osbbf2qKPNb7AsA==", + "requires": { + "@types/semver": "^7.3.5", + "builder-util-runtime": "8.7.5", + "fs-extra": "^10.0.0", + "js-yaml": "^4.1.0", + "lazy-val": "^1.0.4", + "lodash.escaperegexp": "^4.1.2", + "lodash.isequal": "^4.5.0", + "semver": "^7.3.5" + }, + "dependencies": { + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "builder-util-runtime": { + "version": "8.7.5", + "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-8.7.5.tgz", + "integrity": "sha512-fgUFHKtMNjdvH6PDRFntdIGUPgwZ69sXsAqEulCtoiqgWes5agrMq/Ud274zjJRTbckYh2PHh8/1CpFc6dpsbQ==", + "requires": { + "debug": "^4.3.2", + "sax": "^1.2.4" + } + }, + "debug": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "requires": { + "ms": "2.1.2" + } + }, + "fs-extra": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", + "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "requires": { + "argparse": "^2.0.1" + } + }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, "elliptic": { "version": "6.5.4", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", @@ -5953,8 +6055,7 @@ "lazy-val": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz", - "integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==", - "dev": true + "integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==" }, "lcid": { "version": "1.0.0", @@ -6104,6 +6205,16 @@ "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" }, + "lodash.escaperegexp": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", + "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=" + }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "lodash.isplainobject": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", diff --git a/package.json b/package.json index 9937191..e81003a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,11 @@ "version": "1.0.0", "description": "Nuxt + Electron", "author": "romslf@pm.me", - "private": true, + "private": false, + "repository": { + "type" : "git", + "url" : "https://github.com/romslf/system-companion.git" + }, "main": "main.js", "build": { "appId": "", @@ -17,7 +21,8 @@ }, "scripts": { "dev": "cross-env NODE_ENV=DEV electron .", - "build": "nuxt build && electron-builder --config builder.config.js", + "build": "nuxt build && electron-builder --config builder.config.js --publish never", + "deploy": "nuxt build && electron-builder --config builder.config.js --publish always", "lint": "node_modules/.bin/eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter ./src", "lint:fix": "npm run lint -- --fix" }, @@ -25,6 +30,7 @@ "@fortawesome/fontawesome-free": "^5.15.4", "buefy": "^0.9.10", "electron-data-storage": "^1.1.2", + "electron-updater": "^4.3.9", "node-sass": "^6.0.1", "nuxt": "^1.4.0", "sass": "^1.39.0", diff --git a/pages/docker.vue b/pages/docker.vue index 7f9f56a..124c47c 100644 --- a/pages/docker.vue +++ b/pages/docker.vue @@ -118,9 +118,6 @@ Starting command: {{ props.row.command }} -