Auto Update with electron-updater (WIP) #808

Merged
alexliebowitz merged 36 commits from auto-update into master 2018-01-24 23:51:49 +01:00
3 changed files with 24 additions and 1 deletions
Showing only changes of commit 24ced8ede7 - Show all commits

View file

@ -19,6 +19,7 @@ export const DOWNLOAD_UPGRADE = 'DOWNLOAD_UPGRADE';
export const UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED'; export const UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED';
export const UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED'; export const UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED';
export const UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED'; export const UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED';
export const AUTO_UPDATE_DOWNLOAD_COMPLETED = "AUTO_UPDATE_DOWNLOAD_COMPLETED";
export const CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE'; export const CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE';
export const CHECK_UPGRADE_START = 'CHECK_UPGRADE_START'; export const CHECK_UPGRADE_START = 'CHECK_UPGRADE_START';
export const CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS'; export const CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS';

View file

@ -9,7 +9,7 @@ import lbry from 'lbry';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { doConditionalAuthNavigate, doDaemonReady, doShowSnackBar } from 'redux/actions/app'; import { doConditionalAuthNavigate, doDaemonReady, doShowSnackBar, doAutoUpdate } from 'redux/actions/app';
import { doNavigate } from 'redux/actions/navigation'; import { doNavigate } from 'redux/actions/navigation';
import { doDownloadLanguages } from 'redux/actions/settings'; import { doDownloadLanguages } from 'redux/actions/settings';
import { doUserEmailVerify } from 'redux/actions/user'; import { doUserEmailVerify } from 'redux/actions/user';
@ -17,6 +17,7 @@ import 'scss/all.scss';
import store from 'store'; import store from 'store';
import app from './app'; import app from './app';
const { autoUpdater } = remote.require('electron-updater');
const { contextMenu } = remote.require('./main.js'); const { contextMenu } = remote.require('./main.js');
window.addEventListener('contextmenu', event => { window.addEventListener('contextmenu', event => {
@ -97,6 +98,10 @@ document.addEventListener('click', event => {
}); });
const init = () => { const init = () => {
autoUpdater.on("update-downloaded", () => {
app.store.dispatch(doAutoUpdate());
});
app.store.dispatch(doDownloadLanguages()); app.store.dispatch(doDownloadLanguages());
function onDaemonReady() { function onDaemonReady() {

View file

@ -20,6 +20,7 @@ import {
selectUpgradeFilename, selectUpgradeFilename,
} from 'redux/selectors/app'; } from 'redux/selectors/app';
const { autoUpdater } = remote.require('electron-updater');
const { download } = remote.require('electron-dl'); const { download } = remote.require('electron-dl');
const Fs = remote.require('fs'); const Fs = remote.require('fs');
const { lbrySettings: config } = require('package.json'); const { lbrySettings: config } = require('package.json');
@ -105,6 +106,16 @@ export function doDownloadUpgrade() {
}; };
} }
export function doAutoUpdate() {
return function(dispatch, getState) {
const state = getState();
dispatch({
type: types.OPEN_MODAL,
data: modals.AUTO_UPDATE_DOWNLOADED,
});
};
}
export function doCancelUpgrade() { export function doCancelUpgrade() {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
@ -135,6 +146,12 @@ export function doCheckUpgradeAvailable() {
type: ACTIONS.CHECK_UPGRADE_START, type: ACTIONS.CHECK_UPGRADE_START,
}); });
if (["win32", "darwin"].includes(process.platform)) {
// On Windows and Mac, updates happen silently
autoUpdater.checkForUpdates();
return;
}
const success = ({ remoteVersion, upgradeAvailable }) => { const success = ({ remoteVersion, upgradeAvailable }) => {
dispatch({ dispatch({
type: ACTIONS.CHECK_UPGRADE_SUCCESS, type: ACTIONS.CHECK_UPGRADE_SUCCESS,