Skip to content

Commit f35f231

Browse files
committed
Refactor app updates.
1 parent 6173b44 commit f35f231

File tree

14 files changed

+166
-183
lines changed

14 files changed

+166
-183
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"immutable": "^4.0.0-rc.12",
9393
"lodash": "^4.17.15",
9494
"mime": "^2.4.5",
95+
"node-machine-id": "^1.1.12",
9596
"prop-types": "^15.7.1",
9697
"react": "^16.13.1",
9798
"react-dom": "^16.13.1",
@@ -101,6 +102,7 @@
101102
"react-window": "^1.8.5",
102103
"redux": "^4.0.5",
103104
"redux-thunk": "^2.3.0",
105+
"semver": "^7.3.2",
104106
"three": "^0.116.1",
105107
"tinycolor2": "^1.4.1"
106108
},

src/actions/app.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { createSlice } from '@reduxjs/toolkit';
2-
import { api, events, updater, renderer, stage, logger } from 'view/global';
3-
import menuConfig from 'view/config/menu';
2+
import { api, renderer, stage, logger } from 'view/global';
43
import { loadConfig } from 'actions/config';
54
import { newProject } from 'actions/project';
5+
import { checkForUpdates, updateDownloadProgress } from 'actions/updates';
66
import { raiseError } from 'actions/errors';
7+
import { showModal } from './modals';
78

89
const initialState = {
910
statusText: '',
@@ -58,10 +59,20 @@ export function initApp() {
5859
await dispatch(loadConfig());
5960
await dispatch(newProject());
6061

61-
const { checkForUpdates } = getState().config;
62+
const { config } = getState();
6263

63-
if (checkForUpdates) {
64-
updater.checkForUpdates();
64+
api.on('download-progress', info => {
65+
dispatch(updateDownloadProgress(info));
66+
});
67+
68+
if (config.checkForUpdates) {
69+
await dispatch(checkForUpdates());
70+
71+
const { hasUpdate } = getState().updates;
72+
73+
if (hasUpdate) {
74+
dispatch(showModal('AppUpdates', { title: 'Updates' }));
75+
}
6576
}
6677
};
6778
}

src/actions/updates.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { createSlice } from '@reduxjs/toolkit';
2+
import semver from 'semver';
3+
import { api, env, logger } from 'view/global';
4+
5+
const initialState = {
6+
status: null,
7+
checked: false,
8+
hasUpdate: false,
9+
downloadComplete: false,
10+
downloadProgress: 0,
11+
lastCheck: 0,
12+
updateInfo: null,
13+
};
14+
15+
const appUpdateStore = createSlice({
16+
name: 'updates',
17+
initialState,
18+
reducers: {
19+
updateState(state, action) {
20+
return { ...state, ...action.payload };
21+
},
22+
},
23+
});
24+
25+
const { updateState } = appUpdateStore.actions;
26+
27+
export default appUpdateStore.reducer;
28+
29+
export function updateDownloadProgress(info) {
30+
return dispatch => {
31+
dispatch(updateState({ downloadProgress: info.percent }));
32+
};
33+
}
34+
35+
export function downloadUpdate() {
36+
return async dispatch => {
37+
await dispatch(updateState({ status: 'downloading' }));
38+
39+
const result = await api.invoke('download-update');
40+
41+
logger.log('Update downloaded:', result);
42+
43+
await dispatch(updateState({ downloadComplete: true, status: null }));
44+
};
45+
}
46+
47+
export function quitAndInstall() {
48+
return async (dispatch, getState) => {
49+
const { downloadComplete } = getState().updates;
50+
51+
if (downloadComplete) {
52+
await api.invoke('quit-and-install');
53+
}
54+
};
55+
}
56+
57+
export function checkForUpdates() {
58+
return async (dispatch, getState) => {
59+
await dispatch(updateState({ status: 'checking', lastCheck: Date.now() }));
60+
61+
const { updateInfo } = await api.invoke('check-for-updates');
62+
63+
const hasUpdate = semver.gt(updateInfo.version, env.APP_VERSION);
64+
const { config } = getState();
65+
const status = config.autoUpdate && hasUpdate ? 'downloading' : null;
66+
67+
logger.log('Update check complete:', updateInfo);
68+
69+
await dispatch(updateState({ checked: true, status, updateInfo, hasUpdate }));
70+
71+
if (config.autoUpdate && hasUpdate) {
72+
dispatch(downloadUpdate());
73+
}
74+
};
75+
}

src/core/AppUpdater.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/main/api/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export { send, on, once, off, invoke } from 'main/api/ipc';
44
export { spawnProcess } from 'main/api/process';
55
export { getEnvironment } from 'main/api/remote';
66
export {
7-
getCurrentWindow,
8-
getDialog,
97
maximizeWindow,
108
minimizeWindow,
119
unmaximizeWindow,

src/main/api/window.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import { remote } from 'electron';
33
const win = remote.getCurrentWindow();
44
const { dialog } = remote;
55

6-
export function getCurrentWindow() {
7-
return win;
8-
}
9-
10-
export function getDialog() {
11-
return dialog;
12-
}
13-
146
export function maximizeWindow() {
157
if (win.isMaximized()) {
168
win.unmaximize();

src/main/autoupdate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function init() {
1313
autoUpdater.on('error', error => {
1414
log('update-error');
1515

16-
sendMessage('update-error', error.stack || error.message || error);
16+
sendMessage('update-error', error);
1717
});
1818

1919
autoUpdater.on('checking-for-update', () => {

src/main/environment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import { app } from 'electron';
3+
import { machineIdSync } from 'node-machine-id';
34
import os from 'os';
45

56
const version = app.getVersion();
@@ -20,3 +21,4 @@ export const APP_CONFIG_FILE = path.join(
2021
);
2122
export const LICENSE_FILE = path.join(USER_DATA_PATH, 'license.dat');
2223
export const ELECTRON_VERSION = process.versions.electron;
24+
export const MACHINE_ID = machineIdSync();

src/reducers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import project from 'actions/project';
88
import reactors from 'actions/reactors';
99
import scenes from 'actions/scenes';
1010
import stage from 'actions/stage';
11+
import updates from 'actions/updates';
1112
import video from 'actions/video';
1213

1314
export default combineReducers({
@@ -20,5 +21,6 @@ export default combineReducers({
2021
reactors,
2122
scenes,
2223
stage,
24+
updates,
2325
video,
2426
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export Button from 'components/interface/Button';
2+
export Checkmark from 'components/interface/Checkmark';
3+
export Icon from 'components/interface/Icon';
4+
export Spinner from 'components/interface/Spinner';

0 commit comments

Comments
 (0)