Skip to content

Commit

Permalink
Set up autoupdater
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsmid committed Mar 27, 2021
1 parent 8f7f078 commit ef01ef1
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 27 deletions.
113 changes: 109 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand All @@ -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",
Expand Down
40 changes: 39 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 24 additions & 19 deletions src/components/navBar/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="menu">
<Menu isOpen={showMenu} onStateChange={menuState => setShowMenu(menuState.isOpen)}>
{routes.map(route => {
const matchesCurrentPath = (route.path === currentPath);
return (
<Link
key={route.title}
id={route.title}
to={route.linkPath}
onClick={toggleShowMenu}
className={`menu-item ${matchesCurrentPath ? 'current' : ''}`}
>
{route.title}
</Link>
);
})}
</Menu>
<div>
<div className="menu">
<Menu isOpen={showMenu} onStateChange={menuState => setShowMenu(menuState.isOpen)}>
{routes.map(route => {
const matchesCurrentPath = (route.path === currentPath);
return (
<Link
key={route.title}
id={route.title}
to={route.linkPath}
onClick={toggleShowMenu}
className={`menu-item ${matchesCurrentPath ? 'current' : ''}`}
>
{route.title}
</Link>
);
})}
</Menu>
{/* TODO: Remove VERSION */}
<p style={{marginLeft: '100px'}}>Version: {VERSION}</p>
</div>
</div>
);
};
8 changes: 6 additions & 2 deletions src/pages/twitch/TwitchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
Expand Down Expand Up @@ -270,7 +274,7 @@ export default class TwitchPage extends Component {
Name: <input
type="text"
value={name}
onChange={e => setName(e.currentTarget.value)}
onChange={e => setName(e.currentTarget.value)}
onKeyPress={e => e.key === 'Enter' && confirm()} />
</label>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export const splitFirst = (string, separator) => {
return [parts.shift(), parts.join(separator)];
};

export const jsonResponse = res => res.json();
export const jsonResponse = res => res.json();

export const VERSION = "0.2.0";

0 comments on commit ef01ef1

Please sign in to comment.