Skip to content

Commit ff20437

Browse files
committed
Add auto update app
1 parent 9314962 commit ff20437

11 files changed

Lines changed: 185 additions & 33 deletions

File tree

app/actions/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export function setError(payload) {
1919
};
2020
}
2121

22+
export function setUpdate(payload) {
23+
return {
24+
type: types.UPDATE,
25+
payload
26+
};
27+
}
28+
2229
export function setSettings(payload) {
2330
return {
2431
type: types.SETTINGS,

app/components/main/MainHeader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Button, Input} from 'antd';
77
import moment from 'moment';
88
import MainHeaderControls from './MainHeaderControls';
99
import MainHeaderCapture from './MainHeaderCapture';
10+
import MainUpdateApp from './MainUpdateApp';
1011
import Settings from './../settings/Settings';
1112
import SettingsDataTimeRage from './../settings/SettingsDataTimeRage';
1213
import * as MainActions from './../../actions/main';
@@ -84,6 +85,7 @@ class MainHeader extends Component {
8485
<Settings size={this.size}/>
8586
<MainHeaderControls size={this.size}/>
8687
<MainHeaderCapture size={this.size}/>
88+
<MainUpdateApp/>
8789
</div>
8890
);
8991

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {ipcRenderer} from 'electron';
2+
import React, {Component} from 'react';
3+
import {bindActionCreators} from "redux";
4+
import {connect} from 'react-redux';
5+
import {Modal, Icon, Row, Col} from "antd";
6+
import * as MainActions from "./../../actions/main";
7+
8+
9+
class MainUpdateApp extends Component {
10+
handlerOk = () => {
11+
ipcRenderer.send('installUpdate');
12+
this.handlerCancel();
13+
};
14+
15+
handlerCancel = () => {
16+
this.props.mainActions.setUpdate(null);
17+
};
18+
19+
render() {
20+
const {update} = this.props;
21+
22+
if (update) {
23+
return (
24+
<Modal
25+
title={<span>Update ready for install</span>}
26+
visible={true}
27+
onOk={() => this.handlerOk()}
28+
onCancel={() => this.handlerCancel()}
29+
okText={<span><Icon type="download"/> Install update</span>}
30+
wrapClassName="main-update-app"
31+
maskClosable={false}
32+
>
33+
<Row gutter={50}>
34+
<Col span={2}>
35+
<Icon type="info-circle" style={{fontSize: '300%', color: '#108ee9', padding: '12px 0'}}/>
36+
</Col>
37+
<Col span={10}>
38+
<h1>{update.releaseName}</h1>
39+
<i>{new Date(update.releaseDate).toLocaleString()}</i>
40+
</Col>
41+
</Row>
42+
<Row style={{fontSize: '125%'}}>
43+
<div dangerouslySetInnerHTML={{__html: update.releaseNotes}}/>
44+
</Row>
45+
</Modal>
46+
);
47+
}
48+
49+
return null;
50+
}
51+
}
52+
53+
MainUpdateApp.propTypes = {};
54+
MainUpdateApp.defaultProps = {};
55+
56+
function mapStateToProps(state) {
57+
return {
58+
update: state.main.update
59+
};
60+
}
61+
62+
function mapDispatchToProps(dispatch) {
63+
return {
64+
mainActions: bindActionCreators(MainActions, dispatch),
65+
};
66+
}
67+
68+
export default connect(mapStateToProps, mapDispatchToProps)(MainUpdateApp);

app/constants/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const DB_PATH = 'main/DB_PATH';
22
export const SETTINGS = 'main/SETTINGS';
33
export const ERROR = 'main/ERROR';
4+
export const UPDATE = 'main/UPDATE';

app/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ if (module.hot) {
4343
}
4444

4545
ipcRenderer.on('dispatchFromMain', (event, msg) => {
46-
if (msg.push !== undefined) {
46+
if (msg.push) {
4747
hashHistory.push(msg.push);
48-
} else if (msg.action !== undefined) {
48+
} else if (msg.update) {
49+
store.dispatch(MainActions.setUpdate(msg.update));
50+
} else if (msg.action) {
4951
if (msg.action === 'getLastDataBase') {
5052
store.dispatch(MainActions.getLastDataBase(false));
5153
} else if (msg.action === 'getData') {

app/main.development.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
// @flow
22
import {app, BrowserWindow, ipcMain} from 'electron';
3+
import log from 'electron-log';
4+
import {autoUpdater} from "electron-updater";
35
import MenuBuilder from './menu';
46
import configureStore from './store/configureStore';
57
import appPackage from './package.json';
68

9+
autoUpdater.logger = log;
10+
autoUpdater.logger.transports.file.level = 'info';
11+
log.info('App starting...');
12+
713
const store = configureStore();
814
let mainWindow = null;
915

1016
if (process.env.NODE_ENV === 'development') {
1117
app.setName(appPackage.name);
1218
app.setVersion(appPackage.version);
19+
autoUpdater.updateConfigPath = './dev-app-update.yml';
1320
}
1421

1522
if (process.env.NODE_ENV === 'production') {
@@ -18,18 +25,18 @@ if (process.env.NODE_ENV === 'production') {
1825
}
1926

2027
// if (process.env.NODE_ENV === 'development') {
21-
require('electron-debug')(); // eslint-disable-line global-require
22-
const path = require('path'); // eslint-disable-line
23-
const p = path.join(__dirname, '..', 'app', 'node_modules'); // eslint-disable-line
24-
require('module').globalPaths.push(p); // eslint-disable-line
28+
require('electron-debug')(); // eslint-disable-line global-require
29+
const path = require('path'); // eslint-disable-line
30+
const p = path.join(__dirname, '..', 'app', 'node_modules'); // eslint-disable-line
31+
require('module').globalPaths.push(p); // eslint-disable-line
2532
// }
2633

2734
app.on('window-all-closed', () => {
2835
if (process.platform !== 'darwin') app.quit();
2936
});
3037

3138

32-
const installExtensions = async() => {
39+
const installExtensions = async () => {
3340
if (process.env.NODE_ENV === 'development') {
3441
const installer = require('electron-devtools-installer'); // eslint-disable-line global-require
3542

@@ -49,10 +56,9 @@ const installExtensions = async() => {
4956
}
5057
};
5158

52-
app.on('ready', async() => {
59+
app.on('ready', async () => {
5360
await installExtensions();
5461

55-
5662
mainWindow = new BrowserWindow({
5763
show: false,
5864
width: 1450,
@@ -72,6 +78,8 @@ app.on('ready', async() => {
7278
mainWindow.show();
7379
mainWindow.focus();
7480
mainWindow.maximize();
81+
82+
autoUpdater.checkForUpdates();
7583
});
7684

7785
mainWindow.on('closed', () => {
@@ -84,3 +92,16 @@ app.on('ready', async() => {
8492
const menuBuilder = new MenuBuilder(mainWindow, store);
8593
menuBuilder.buildMenu();
8694
});
95+
96+
97+
autoUpdater.on('download-progress', (progressObj) => {
98+
log.info('Downloaded ' + Math.round(progressObj.percent) + '% (' + progressObj.transferred + "/" + progressObj.total + ')');
99+
});
100+
autoUpdater.on('update-downloaded', (update) => mainWindow.send('dispatchFromMain', {update}));
101+
ipcMain.on('installUpdate', () => {
102+
if (process.env.NODE_ENV === 'development') {
103+
console.log('autoUpdater.quitAndInstall()');
104+
} else {
105+
autoUpdater.quitAndInstall();
106+
}
107+
});

app/menu.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22
import {app, Menu, shell, BrowserWindow, dialog, ipcMain} from 'electron';
33
import {push} from 'react-router-redux';
4+
import {autoUpdater} from "electron-updater";
45

56
export default class MenuBuilder {
67
mainWindow: BrowserWindow;
@@ -265,13 +266,7 @@ export default class MenuBuilder {
265266
{
266267
label: 'About',
267268
click() {
268-
shell.openExternal('http://electron.atom.io');
269-
}
270-
},
271-
{
272-
label: 'Check for updates',
273-
click() {
274-
shell.openExternal('https://github.com/atom/electron/tree/master/docs#readme');
269+
shell.openExternal('https://github.com/sheldhur/Vector/');
275270
}
276271
}
277272
]

app/reducers/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const initialState = {
88
settings: {...DEFAULT_SETTINGS},
99
error: null,
1010
dbPath: null,
11+
update: null
1112
};
1213

1314
export default function main(state = initialState, action) {
@@ -25,6 +26,8 @@ export default function main(state = initialState, action) {
2526
return {...state, settings};
2627
case types.ERROR:
2728
return {...state, error: action.payload};
29+
case types.UPDATE:
30+
return {...state, update: action.payload};
2831
case types.DB_PATH:
2932
return {...state, dbPath: action.payload};
3033
default:

dev-app-update.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
owner: sheldhur
2+
repo: Vector
3+
provider: github

0 commit comments

Comments
 (0)