From ef01ef170a146a7e7ca423edd2bc59ec5ee9e953 Mon Sep 17 00:00:00 2001 From: Justin Smid Date: Sat, 27 Mar 2021 13:19:39 +0100 Subject: [PATCH] Set up autoupdater --- package-lock.json | 113 ++++++++++++++++++++++++- package.json | 8 ++ public/electron.js | 40 ++++++++- src/components/navBar/NavigationBar.js | 43 +++++----- src/pages/twitch/TwitchPage.js | 8 +- src/util/util.js | 4 +- 6 files changed, 189 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c868be..d352b6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1959,6 +1959,11 @@ "@types/react": "*" } }, + "@types/semver": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ==" + }, "@types/stack-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz", @@ -2823,8 +2828,7 @@ "at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" }, "atob": { "version": "2.1.2", @@ -5888,6 +5892,103 @@ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.582.tgz", "integrity": "sha512-0nCJ7cSqnkMC+kUuPs0YgklFHraWGl/xHqtZWWtOeVtyi+YqkoAOMGuZQad43DscXCQI/yizcTa3u6B5r+BLww==" }, + "electron-updater": { + "version": "4.3.8", + "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-4.3.8.tgz", + "integrity": "sha512-/tB82Ogb2LqaXrUzAD8waJC+TZV52Pr0Znfj7w+i4D+jA2GgrKFI3Pxjp+36y9FcBMQz7kYsMHcB6c5zBJao+A==", + "requires": { + "@types/semver": "^7.3.4", + "builder-util-runtime": "8.7.3", + "fs-extra": "^9.1.0", + "js-yaml": "^4.0.0", + "lazy-val": "^1.0.4", + "lodash.isequal": "^4.5.0", + "semver": "^7.3.4" + }, + "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.3", + "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-8.7.3.tgz", + "integrity": "sha512-1Q2ReBqFblimF5g/TLg2+0M5Xzv0Ih5LxJ/BMWXvEy/e6pQKeeEpbkPMGsN6OiQgkygaZo5VXCXIjOkOQG5EoQ==", + "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": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "requires": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "js-yaml": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz", + "integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==", + "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.3", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", @@ -10122,8 +10223,7 @@ "lazy-val": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.4.tgz", - "integrity": "sha512-u93kb2fPbIrfzBuLjZE+w+fJbUUMhNDXxNmMfaqNgpfQf1CO5ZSe2LfsnBqVAk7i/2NF48OSoRj+Xe2VT+lE8Q==", - "dev": true + "integrity": "sha512-u93kb2fPbIrfzBuLjZE+w+fJbUUMhNDXxNmMfaqNgpfQf1CO5ZSe2LfsnBqVAk7i/2NF48OSoRj+Xe2VT+lE8Q==" }, "lcu-connector": { "version": "2.1.3", @@ -10259,6 +10359,11 @@ "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=" }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", diff --git a/package.json b/package.json index a5536bf..889479d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,13 @@ "url": "https://github.com/justinsmid/accept-league-queue.git" }, "build": { + "publish": [ + { + "provider": "github", + "owner": "justinsmid", + "repo": "accept-league-queue" + } + ], "appId": "justinsmid.league-helper.desktop", "files": [ "build/**/*", @@ -24,6 +31,7 @@ "@material-ui/core": "^4.11.0", "buffer": "^5.6.0", "cors": "^2.8.5", + "electron-updater": "^4.3.8", "express": "^4.17.1", "lcu-connector": "^2.1.3", "node-fetch": "^2.6.0", diff --git a/public/electron.js b/public/electron.js index cccc367..7a9fe6d 100644 --- a/public/electron.js +++ b/public/electron.js @@ -1,5 +1,6 @@ const electron = require('electron'); -const {app} = electron; +const {app, webContents} = electron; +const {autoUpdater} = require("electron-updater"); // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; @@ -33,6 +34,11 @@ const jsonResponse = res => res.json(); const LOCAL_STORAGE_PREFIX = './localStorage/'; function onAppReady() { + console.log('App ready!') + // Check for app updates + autoUpdater.checkForUpdates(); + + // Set up localstorage const twitchAuthStorage = new LocalStorage(LOCAL_STORAGE_PREFIX + 'twitch-auth'); const commandsStorage = new LocalStorage(LOCAL_STORAGE_PREFIX + 'commands'); const trustedStorage = new LocalStorage(LOCAL_STORAGE_PREFIX + 'trusted'); @@ -113,6 +119,38 @@ app.on('activate', function () { } }); +const onAutoUpdateEvent = (event, data) => { + console.log(`[AUTO_UPDATE_EVENT]: ${event}`, data); + setTimeout(() => { + mainWindow.webContents.send('AUTO_UPDATER_EVENT', event, data); + }, 10000); +}; + +autoUpdater.on('checking-for-update', () => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: checking-for-update'); +}); + +autoUpdater.on('update-available', (info) => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: update-available', info); +}); + +autoUpdater.on('update-not-available', (info) => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: update-not-available', info); +}); + +autoUpdater.on('error', (err) => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: error', err); +}); + +autoUpdater.on('download-progress', (progressObj) => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: download-progress', progressObj); +}); + +autoUpdater.on('update-downloaded', (info) => { + onAutoUpdateEvent('[AUTO_UPDATE_EVENT]: update-downloaded', info); + autoUpdater.quitAndInstall(); +}); + class ExpressServer { constructor(port) { this.port = port; diff --git a/src/components/navBar/NavigationBar.js b/src/components/navBar/NavigationBar.js index cf9edea..6c97d21 100644 --- a/src/components/navBar/NavigationBar.js +++ b/src/components/navBar/NavigationBar.js @@ -2,30 +2,35 @@ import React, {useState} from 'react'; import {slide as Menu} from 'react-burger-menu'; import {Link} from 'react-router-dom'; import routes from '../../routes'; +import {VERSION} from '../../util/util'; import './menu.sass'; export default ({currentPath}) => { - const [showMenu, setShowMenu] = useState(false); - const toggleShowMenu = () => setShowMenu(!showMenu); + const [showMenu, setShowMenu] = useState(false); + const toggleShowMenu = () => setShowMenu(!showMenu); return ( -
- setShowMenu(menuState.isOpen)}> - {routes.map(route => { - const matchesCurrentPath = (route.path === currentPath); - return ( - - {route.title} - - ); - })} - +
+
+ setShowMenu(menuState.isOpen)}> + {routes.map(route => { + const matchesCurrentPath = (route.path === currentPath); + return ( + + {route.title} + + ); + })} + + {/* TODO: Remove VERSION */} +

Version: {VERSION}

+
); }; \ No newline at end of file diff --git a/src/pages/twitch/TwitchPage.js b/src/pages/twitch/TwitchPage.js index 4bc21b3..5197912 100644 --- a/src/pages/twitch/TwitchPage.js +++ b/src/pages/twitch/TwitchPage.js @@ -23,7 +23,7 @@ let authWindow; export const fetchTwitchApi = (url, accessToken, options) => { accessToken = (accessToken || JSON.parse(getGlobal('twitchAuthStorage').getItem('accessToken'))); - + return fetch(url, { ...options, headers: { @@ -50,6 +50,10 @@ export default class TwitchPage extends Component { this.twitchBot = new TwitchBot(); + ipcRenderer.on('AUTO_UPDATER_EVENT', (event, x, y) => { + console.log(`Received AUTO_UPDATER_EVENT`, event, x, y); + }); + this.startAuthentication = this.startAuthentication.bind(this); this.updateTwitchUserFromToken = this.updateTwitchUserFromToken.bind(this); this.disconnectTwitchBot = this.disconnectTwitchBot.bind(this); @@ -270,7 +274,7 @@ export default class TwitchPage extends Component { Name: setName(e.currentTarget.value)} + onChange={e => setName(e.currentTarget.value)} onKeyPress={e => e.key === 'Enter' && confirm()} />
diff --git a/src/util/util.js b/src/util/util.js index 8dd75fc..dc37757 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -21,4 +21,6 @@ export const splitFirst = (string, separator) => { return [parts.shift(), parts.join(separator)]; }; -export const jsonResponse = res => res.json(); \ No newline at end of file +export const jsonResponse = res => res.json(); + +export const VERSION = "0.2.0"; \ No newline at end of file