Add notifyOnly auto-updater
This commit is contained in:
@@ -2,6 +2,25 @@ const React = require('react');
|
|||||||
const propTypes = require('prop-types');
|
const propTypes = require('prop-types');
|
||||||
const {Button, Navbar} = require('react-bootstrap');
|
const {Button, Navbar} = require('react-bootstrap');
|
||||||
|
|
||||||
|
function InstallButton(props) {
|
||||||
|
if (props.notifyOnly) {
|
||||||
|
return (<Button
|
||||||
|
bsStyle='primary'
|
||||||
|
onClick={props.onClickDownload}
|
||||||
|
>{'Download Update'}</Button>);
|
||||||
|
}
|
||||||
|
return (<Button
|
||||||
|
bsStyle='primary'
|
||||||
|
onClick={props.onClickInstall}
|
||||||
|
>{'Install Update'}</Button>);
|
||||||
|
}
|
||||||
|
|
||||||
|
InstallButton.propTypes = {
|
||||||
|
notifyOnly: propTypes.bool.isRequired,
|
||||||
|
onClickInstall: propTypes.func.isRequired,
|
||||||
|
onClickDownload: propTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
function UpdaterPage(props) {
|
function UpdaterPage(props) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -33,10 +52,11 @@ function UpdaterPage(props) {
|
|||||||
bsStyle='link'
|
bsStyle='link'
|
||||||
onClick={props.onClickRemind}
|
onClick={props.onClickRemind}
|
||||||
>{'Remind me in 2 days'}</Button>
|
>{'Remind me in 2 days'}</Button>
|
||||||
<Button
|
<InstallButton
|
||||||
bsStyle='primary'
|
notifyOnly={props.notifyOnly}
|
||||||
onClick={props.onClickInstall}
|
onClickInstall={props.onClickInstall}
|
||||||
>{'Install Update'}</Button>
|
onClickDownload={props.onClickDownload}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
</div>
|
</div>
|
||||||
@@ -44,7 +64,9 @@ function UpdaterPage(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdaterPage.propTypes = {
|
UpdaterPage.propTypes = {
|
||||||
|
notifyOnly: propTypes.bool.isRequired,
|
||||||
onClickInstall: propTypes.func.isRequired,
|
onClickInstall: propTypes.func.isRequired,
|
||||||
|
onClickDownload: propTypes.func.isRequired,
|
||||||
onClickReleaseNotes: propTypes.func.isRequired,
|
onClickReleaseNotes: propTypes.func.isRequired,
|
||||||
onClickRemind: propTypes.func.isRequired,
|
onClickRemind: propTypes.func.isRequired,
|
||||||
onClickSkip: propTypes.func.isRequired
|
onClickSkip: propTypes.func.isRequired
|
||||||
|
@@ -1,10 +1,15 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactDOM = require('react-dom');
|
const ReactDOM = require('react-dom');
|
||||||
const {ipcRenderer} = require('electron');
|
const {ipcRenderer} = require('electron');
|
||||||
|
const url = require('url');
|
||||||
const UpdaterPage = require('./components/UpdaterPage.jsx');
|
const UpdaterPage = require('./components/UpdaterPage.jsx');
|
||||||
|
|
||||||
|
const thisURL = url.parse(location.href, true);
|
||||||
|
const notifyOnly = thisURL.query.notifyOnly === 'true';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<UpdaterPage
|
<UpdaterPage
|
||||||
|
notifyOnly={notifyOnly}
|
||||||
onClickReleaseNotes={() => {
|
onClickReleaseNotes={() => {
|
||||||
ipcRenderer.send('click-release-notes');
|
ipcRenderer.send('click-release-notes');
|
||||||
}}
|
}}
|
||||||
@@ -17,6 +22,9 @@ ReactDOM.render(
|
|||||||
onClickInstall={() => {
|
onClickInstall={() => {
|
||||||
ipcRenderer.send('click-install');
|
ipcRenderer.send('click-install');
|
||||||
}}
|
}}
|
||||||
|
onClickDownload={() => {
|
||||||
|
ipcRenderer.send('click-download');
|
||||||
|
}}
|
||||||
/>,
|
/>,
|
||||||
document.getElementById('content')
|
document.getElementById('content')
|
||||||
);
|
);
|
||||||
|
@@ -651,7 +651,8 @@ app.on('ready', () => {
|
|||||||
permissionManager = new PermissionManager(permissionFile, trustedURLs);
|
permissionManager = new PermissionManager(permissionFile, trustedURLs);
|
||||||
session.defaultSession.setPermissionRequestHandler(permissionRequestHandler(mainWindow, permissionManager));
|
session.defaultSession.setPermissionRequestHandler(permissionRequestHandler(mainWindow, permissionManager));
|
||||||
|
|
||||||
autoUpdater.initialize(appState, mainWindow);
|
const updaterConfig = autoUpdater.loadConfig(path.resolve(app.getAppPath(), '../app-updater-config.json'));
|
||||||
|
autoUpdater.initialize(appState, mainWindow, updaterConfig.isNotifyOnly());
|
||||||
ipcMain.on('check-for-updates', autoUpdater.checkForUpdates);
|
ipcMain.on('check-for-updates', autoUpdater.checkForUpdates);
|
||||||
mainWindow.once('show', () => {
|
mainWindow.once('show', () => {
|
||||||
if (autoUpdater.shouldCheckForUpdatesOnStart(appState.updateCheckedDate)) {
|
if (autoUpdater.shouldCheckForUpdatesOnStart(appState.updateCheckedDate)) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
const {app, BrowserWindow, dialog, ipcMain, shell} = require('electron');
|
const {app, BrowserWindow, dialog, ipcMain, shell} = require('electron');
|
||||||
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {autoUpdater} = require('electron-updater');
|
const {autoUpdater} = require('electron-updater');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
@@ -37,10 +38,14 @@ function createUpdaterModal(parentWindow, options) {
|
|||||||
modal.once('ready-to-show', () => {
|
modal.once('ready-to-show', () => {
|
||||||
modal.show();
|
modal.show();
|
||||||
});
|
});
|
||||||
const updaterURL = (global.isDev ? 'http://localhost:8080' : `file://${app.getAppPath()}`) + '/browser/updater.html';
|
let updaterURL = (global.isDev ? 'http://localhost:8080' : `file://${app.getAppPath()}`) + '/browser/updater.html';
|
||||||
|
|
||||||
|
if (options.notifyOnly) {
|
||||||
|
updaterURL += '?notifyOnly=true';
|
||||||
|
}
|
||||||
modal.loadURL(updaterURL);
|
modal.loadURL(updaterURL);
|
||||||
|
|
||||||
for (const eventName of ['click-release-notes', 'click-skip', 'click-remind', 'click-install']) {
|
for (const eventName of ['click-release-notes', 'click-skip', 'click-remind', 'click-install', 'click-download']) {
|
||||||
const listener = createEventListener(modal, eventName);
|
const listener = createEventListener(modal, eventName);
|
||||||
ipcMain.on(eventName, listener);
|
ipcMain.on(eventName, listener);
|
||||||
modal.on('closed', () => {
|
modal.on('closed', () => {
|
||||||
@@ -73,13 +78,20 @@ function downloadAndInstall() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize(appState, mainWindow) {
|
function initialize(appState, mainWindow, notifyOnly = false) {
|
||||||
|
autoUpdater.notifyOnly = notifyOnly;
|
||||||
|
if (notifyOnly) {
|
||||||
|
autoUpdater.autoDownload = false;
|
||||||
|
}
|
||||||
const assetsDir = path.resolve(app.getAppPath(), 'assets');
|
const assetsDir = path.resolve(app.getAppPath(), 'assets');
|
||||||
autoUpdater.on('error', (err) => {
|
autoUpdater.on('error', (err) => {
|
||||||
console.error('Error in autoUpdater:', err.message);
|
console.error('Error in autoUpdater:', err.message);
|
||||||
}).on('update-available', (info) => {
|
}).on('update-available', (info) => {
|
||||||
if (isUpdateApplicable(new Date(), appState.skippedVersion, info)) {
|
if (isUpdateApplicable(new Date(), appState.skippedVersion, info)) {
|
||||||
updaterModal = createUpdaterModal(mainWindow, {linuxAppIcon: path.join(assetsDir, 'appicon.png'), nextVersion: '0.0.0'});
|
updaterModal = createUpdaterModal(mainWindow, {
|
||||||
|
linuxAppIcon: path.join(assetsDir, 'appicon.png'),
|
||||||
|
notifyOnly: autoUpdater.notifyOnly
|
||||||
|
});
|
||||||
updaterModal.on('closed', () => {
|
updaterModal.on('closed', () => {
|
||||||
updaterModal = null;
|
updaterModal = null;
|
||||||
});
|
});
|
||||||
@@ -93,6 +105,8 @@ function initialize(appState, mainWindow) {
|
|||||||
}).on('click-install', () => {
|
}).on('click-install', () => {
|
||||||
downloadAndInstall();
|
downloadAndInstall();
|
||||||
updaterModal.close();
|
updaterModal.close();
|
||||||
|
}).on('click-download', () => {
|
||||||
|
shell.openExternal('https://about.mattermost.com/download/#mattermostApps');
|
||||||
}).on('click-release-notes', () => {
|
}).on('click-release-notes', () => {
|
||||||
shell.openExternal(`https://github.com/mattermost/desktop/releases/v${info.version}`);
|
shell.openExternal(`https://github.com/mattermost/desktop/releases/v${info.version}`);
|
||||||
});
|
});
|
||||||
@@ -115,7 +129,7 @@ function initialize(appState, mainWindow) {
|
|||||||
|
|
||||||
function shouldCheckForUpdatesOnStart(updateCheckedDate) {
|
function shouldCheckForUpdatesOnStart(updateCheckedDate) {
|
||||||
if (updateCheckedDate) {
|
if (updateCheckedDate) {
|
||||||
if (Date.now() - updateCheckedDate < INTERVAL_48_HOURS_IN_MS) {
|
if (Date.now() - updateCheckedDate.getTime() < INTERVAL_48_HOURS_IN_MS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,15 +138,36 @@ function shouldCheckForUpdatesOnStart(updateCheckedDate) {
|
|||||||
|
|
||||||
function checkForUpdates(isManual = false) {
|
function checkForUpdates(isManual = false) {
|
||||||
autoUpdater.isManual = isManual;
|
autoUpdater.isManual = isManual;
|
||||||
autoUpdater.autoDownload = false;
|
|
||||||
if (!updaterModal) {
|
if (!updaterModal) {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AutoUpdaterConfig {
|
||||||
|
constructor(file) {
|
||||||
|
try {
|
||||||
|
this.data = JSON.parse(fs.readFileSync(file));
|
||||||
|
} catch (err) {
|
||||||
|
this.data = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isNotifyOnly() {
|
||||||
|
if (this.data.notifyOnly === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadConfig(file) {
|
||||||
|
return new AutoUpdaterConfig(file);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
INTERVAL_48_HOURS_IN_MS,
|
INTERVAL_48_HOURS_IN_MS,
|
||||||
checkForUpdates,
|
checkForUpdates,
|
||||||
shouldCheckForUpdatesOnStart,
|
shouldCheckForUpdatesOnStart,
|
||||||
initialize
|
initialize,
|
||||||
|
loadConfig
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user