Skip to content

Commit

Permalink
Autoupdate app when new release is downloaded, and notify user
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsmid committed Mar 27, 2021
1 parent 7db27b8 commit cfc1b71
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "desktop",
"description": "Desktop app for league client helper",
"version": "0.3.0",
"version": "0.3.1",
"author": "Justin Smid",
"private": true,
"main": "public/electron.js",
Expand Down
33 changes: 7 additions & 26 deletions public/electron.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const electron = require('electron');
const {app, webContents} = electron;
const {app} = electron;
const {autoUpdater} = require("electron-updater");
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
Expand Down Expand Up @@ -120,35 +120,16 @@ app.on('activate', function () {
});

const onAutoUpdateEvent = (event, data) => {
console.log(`[AUTO_UPDATE_EVENT]: ${event}`, data);
setTimeout(() => {
mainWindow.webContents.on('did-finish-load', () => {
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();
onAutoUpdateEvent('update-downloaded', info);
setTimeout(() => {
autoUpdater.quitAndInstall();
}, 5000);
});

class ExpressServer {
Expand Down
39 changes: 17 additions & 22 deletions src/components/navBar/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@ 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);

return (
<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 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>
);
};
17 changes: 17 additions & 0 deletions src/entry/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import './App.sass';
import {BrowserRouter as Router, Switch, Route, useLocation} from 'react-router-dom';
import routes from '../routes';
import NavigationBar from '../components/navBar/NavigationBar';
import {useEffectOnce} from '../util/util';
const electron = window.require('electron');
const ipcRenderer = electron.ipcRenderer;
const {dialog} = electron.remote;

function App() {
const [currentPath, setCurrentPath] = useState('/');
Expand All @@ -11,6 +15,19 @@ function App() {
setCurrentPath(location.pathname);
};

useEffectOnce(() => {
ipcRenderer.on('AUTO_UPDATER_EVENT', (event) => {
if (event === 'update-downloaded') {
dialog.showMessageBox(
{
title: 'New version downloaded',
message: 'A new version of the application has been detected and will be installed shortly.'
}
);
}
});
});

return (
<div className="app">
<Router>
Expand Down
4 changes: 0 additions & 4 deletions src/pages/twitch/TwitchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ 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
8 changes: 6 additions & 2 deletions src/util/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React, {useEffect} from "react";

const electron = window.require('electron');

export const getGlobal = electron.remote.getGlobal;
Expand All @@ -21,6 +23,8 @@ export const splitFirst = (string, separator) => {
return [parts.shift(), parts.join(separator)];
};

export const jsonResponse = res => res.json();
export const useEffectOnce = (callback) => {
return useEffect(callback, []);
};

export const VERSION = "0.3.0";
export const jsonResponse = res => res.json();

0 comments on commit cfc1b71

Please sign in to comment.