diff --git a/desktop/main.js b/desktop/main.js
index 7a25730a5da7..820c381a059f 100644
--- a/desktop/main.js
+++ b/desktop/main.js
@@ -71,22 +71,36 @@ for (let i = 0; i < process.argv.length; i++) {
// Add the listeners and variables required to ensure that auto-updating
// happens correctly.
let hasUpdate = false;
+let downloadedVersion;
-const quitAndInstallWithUpdate = (version) => {
+const quitAndInstallWithUpdate = () => {
+ if (!downloadedVersion) {
+ return;
+ }
app.relaunch({
- args: [`${EXPECTED_UPDATE_VERSION_FLAG}=${version}`],
+ args: [`${EXPECTED_UPDATE_VERSION_FLAG}=${downloadedVersion}`],
});
hasUpdate = true;
autoUpdater.quitAndInstall();
};
+// Defines the system-level menu item for manually triggering an update after
+const updateAppMenuItem = new MenuItem({
+ label: 'Update Expensify.cash',
+ enabled: false,
+ click: quitAndInstallWithUpdate,
+});
+
+// Actual auto-update listeners
const electronUpdater = browserWindow => ({
init: () => {
autoUpdater.on('update-downloaded', (info) => {
+ downloadedVersion = info.version;
+ updateAppMenuItem.enabled = true;
if (browserWindow.isVisible()) {
browserWindow.webContents.send('update-downloaded', info.version);
} else {
- quitAndInstallWithUpdate(info.version);
+ quitAndInstallWithUpdate();
}
});
@@ -134,6 +148,9 @@ const mainWindow = (() => {
}],
}));
+ const appMenu = systemMenu.items.find(item => item.role === 'appmenu');
+ appMenu.submenu.insert(1, updateAppMenuItem);
+
// On mac, pressing cmd++ actually sends a cmd+=. cmd++ is generally the zoom in shortcut, but this is
// not properly listened for by electron. Adding in an invisible cmd+= listener fixes this.
const viewWindow = systemMenu.items.find(item => item.role === 'viewmenu');
diff --git a/src/Expensify.js b/src/Expensify.js
index 053d9dc09af2..27a2c6c45467 100644
--- a/src/Expensify.js
+++ b/src/Expensify.js
@@ -46,8 +46,8 @@ const propTypes = {
accountID: PropTypes.number,
}),
- // Version of newly downloaded update.
- version: PropTypes.string,
+ // Whether a new update is available and ready to install.
+ updateAvailable: PropTypes.bool,
};
const defaultProps = {
@@ -55,7 +55,7 @@ const defaultProps = {
authToken: null,
accountID: null,
},
- version: '',
+ updateAvailable: false,
};
class Expensify extends PureComponent {
@@ -98,7 +98,7 @@ class Expensify extends PureComponent {
return (
<>
{/* We include the modal for showing a new update at the top level so the option is always present. */}
- {this.props.version ? : null}
+ {this.props.updateAvailable ? : null}
>
);
@@ -111,8 +111,8 @@ export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
- version: {
- key: ONYXKEYS.UPDATE_VERSION,
+ updateAvailable: {
+ key: ONYXKEYS.UPDATE_AVAILABLE,
initWithStoredValues: false,
},
})(Expensify);
diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js
index b9057c941645..8edd302fb8c6 100644
--- a/src/ONYXKEYS.js
+++ b/src/ONYXKEYS.js
@@ -38,8 +38,8 @@ export default {
// Contains the user preference for the LHN priority mode
PRIORITY_MODE: 'priorityMode',
- // Contains the version of the update that has newly been downloaded.
- UPDATE_VERSION: 'updateVersion',
+ // Indicates whether an update is available and ready to beinstalled.
+ UPDATE_AVAILABLE: 'updateAvailable',
// Saves the current country code which is displayed when the user types a phone number without
// an international code
diff --git a/src/components/UpdateAppModal/UpdateAppModalPropTypes.js b/src/components/UpdateAppModal/UpdateAppModalPropTypes.js
index 476cfb15a104..c55209dfc1a2 100644
--- a/src/components/UpdateAppModal/UpdateAppModalPropTypes.js
+++ b/src/components/UpdateAppModal/UpdateAppModalPropTypes.js
@@ -3,15 +3,10 @@ import PropTypes from 'prop-types';
const propTypes = {
// Callback to fire when we want to trigger the update.
onSubmit: PropTypes.func,
-
- // Version string for the app to update to.
- // eslint-disable-next-line react/no-unused-prop-types
- version: PropTypes.string,
};
const defaultProps = {
onSubmit: null,
- version: '',
};
export {propTypes, defaultProps};
diff --git a/src/components/UpdateAppModal/index.desktop.js b/src/components/UpdateAppModal/index.desktop.js
index 3bb08fc5ff58..2b7de124e406 100644
--- a/src/components/UpdateAppModal/index.desktop.js
+++ b/src/components/UpdateAppModal/index.desktop.js
@@ -8,7 +8,7 @@ const UpdateAppModal = (props) => {
if (props.onSubmit) {
props.onSubmit();
}
- ipcRenderer.sendSync('start-update', props.version);
+ ipcRenderer.sendSync('start-update');
};
return ;
};
diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js
index 2fb6932e8232..bb29b96e41f8 100644
--- a/src/libs/Notification/LocalNotification/BrowserNotifications.js
+++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js
@@ -122,17 +122,14 @@ export default {
/**
* Create a notification to indicate that an update is available.
- *
- * @param {Object} params
- * @param {String} params.version
*/
- pushUpdateAvailableNotification({version}) {
+ pushUpdateAvailableNotification() {
push({
title: 'Update available',
body: 'A new version of Expensify.cash is available!',
delay: 0,
onClick: () => {
- Onyx.merge(ONYXKEYS.UPDATE_VERSION, version);
+ Onyx.merge(ONYXKEYS.UPDATE_AVAILABLE, true);
},
});
},
diff --git a/src/libs/Notification/LocalNotification/index.js b/src/libs/Notification/LocalNotification/index.js
index 9dfdd62b3b86..9564b0ef7f26 100644
--- a/src/libs/Notification/LocalNotification/index.js
+++ b/src/libs/Notification/LocalNotification/index.js
@@ -4,8 +4,8 @@ function showCommentNotification({reportAction, onClick}) {
BrowserNotifications.pushReportCommentNotification({reportAction, onClick});
}
-function showUpdateAvailableNotification({version}) {
- BrowserNotifications.pushUpdateAvailableNotification({version});
+function showUpdateAvailableNotification() {
+ BrowserNotifications.pushUpdateAvailableNotification();
}
export default {
diff --git a/src/setup/index.desktop.js b/src/setup/index.desktop.js
index 8864e3c6b396..f1c9364e7ab3 100644
--- a/src/setup/index.desktop.js
+++ b/src/setup/index.desktop.js
@@ -9,7 +9,7 @@ export default function () {
rootTag: document.getElementById('root'),
});
- ipcRenderer.on('update-downloaded', (_, version) => {
- LocalNotification.showUpdateAvailableNotification({version});
+ ipcRenderer.on('update-downloaded', () => {
+ LocalNotification.showUpdateAvailableNotification();
});
}