diff --git a/electron/index.js b/electron/index.js index 971a2c50e..763206508 100644 --- a/electron/index.js +++ b/electron/index.js @@ -320,13 +320,14 @@ ipcMain.on('upgrade', (event, installerPath) => { app.quit(); }); -ipcMain.on('check-for-updates', () => { +ipcMain.on('check-for-updates', (event, autoDownload) => { // Prevent downloading the same update multiple times. if (!keepCheckingForUpdates) { return; } keepCheckingForUpdates = false; + autoUpdater.autoDownload = autoDownload; autoUpdater.checkForUpdates(); }); diff --git a/ui/component/app/view.jsx b/ui/component/app/view.jsx index 5ee2c452b..6d9eba94c 100644 --- a/ui/component/app/view.jsx +++ b/ui/component/app/view.jsx @@ -129,8 +129,7 @@ function App(props: Props) { const [resolvedSubscriptions, setResolvedSubscriptions] = useState(false); // const [retryingSync, setRetryingSync] = useState(false); const [sidebarOpen] = usePersistedState('sidebar', true); - const showUpgradeButton = - (autoUpdateDownloaded || (process.platform === 'linux' && isUpgradeAvailable)) && !upgradeNagClosed; + const showUpgradeButton = (autoUpdateDownloaded || isUpgradeAvailable) && !upgradeNagClosed; // referral claiming const referredRewardAvailable = rewards && rewards.some((reward) => reward.reward_type === REWARDS.TYPE_REFEREE); const urlParams = new URLSearchParams(search); diff --git a/ui/component/settingDisableAutoUpdates/view.jsx b/ui/component/settingDisableAutoUpdates/view.jsx index 96412c786..d920fc38c 100644 --- a/ui/component/settingDisableAutoUpdates/view.jsx +++ b/ui/component/settingDisableAutoUpdates/view.jsx @@ -1,10 +1,7 @@ // @flow import React from 'react'; -import * as remote from '@electron/remote'; import { FormField } from 'component/common/form'; -const { autoUpdater } = remote.require('electron-updater'); - type Props = { setClientSetting: (boolean) => void, disableAutoUpdates: boolean, @@ -18,7 +15,6 @@ function SettingDisableAutoUpdates(props: Props) { name="autoupdates" onChange={() => { const newDisableAutoUpdates = !disableAutoUpdates; - autoUpdater.autoDownload = !newDisableAutoUpdates; setClientSetting(newDisableAutoUpdates); }} checked={disableAutoUpdates} diff --git a/ui/index.jsx b/ui/index.jsx index 54b2d4aa8..cf1589bc7 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -117,6 +117,16 @@ ipcRenderer.on('open-uri-requested', (event, url, newSession) => { handleError(); }); +autoUpdater.on('update-available', ({ version }) => { + app.store.dispatch({ + type: ACTIONS.CHECK_UPGRADE_SUCCESS, + data: { + upgradeAvailable: true, + remoteVersion: version, + }, + }); +}); + ipcRenderer.on('download-progress-update', (e, p) => { app.store.dispatch(doUpdateDownloadProgress(Math.round(p.percent * 100))); }); @@ -200,12 +210,6 @@ function AppWrapper() { useEffect(() => { // @if TARGET='app' - - // Enable/disable automatic updates download based on user's settings. - const state = store.getState(); - const autoUpdatesDisabled = makeSelectClientSetting(SETTINGS.DISABLE_AUTO_UPDATES)(state); - autoUpdater.autoDownload = !autoUpdatesDisabled; - moment.locale(remote.app.getLocale()); autoUpdater.on('error', (error) => { diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index 93aad6087..69a40a18a 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -37,7 +37,7 @@ import { selectModal, selectAllowAnalytics, } from 'redux/selectors/app'; -import { selectDaemonSettings, makeSelectClientSetting } from 'redux/selectors/settings'; +import { selectDaemonSettings, makeSelectClientSetting, selectDisableAutoUpdates } from 'redux/selectors/settings'; import { selectUser } from 'redux/selectors/user'; import { doSyncLoop, doSetPrefsReady, doPreferenceGet, doPopulateSharedUserState } from 'redux/actions/sync'; import { doAuthenticate } from 'redux/actions/user'; @@ -187,10 +187,13 @@ export function doCheckUpgradeAvailable() { // On Windows, Mac, and AppImage, updates happen silently through // electron-updater. const autoUpdateDeclined = selectAutoUpdateDeclined(state); + const disableAutoUpdate = selectDisableAutoUpdates(state); - if (!autoUpdateDeclined && !isDev) { - ipcRenderer.send('check-for-updates'); + if (autoUpdateDeclined || isDev) { + return; } + + ipcRenderer.send('check-for-updates', !disableAutoUpdate); return; } diff --git a/ui/redux/selectors/settings.js b/ui/redux/selectors/settings.js index 5b759cc5d..ea1900891 100644 --- a/ui/redux/selectors/settings.js +++ b/ui/redux/selectors/settings.js @@ -83,3 +83,5 @@ export const selectHomepageData = createSelector( ); export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED); + +export const selectDisableAutoUpdates = makeSelectClientSetting(SETTINGS.DISABLE_AUTO_UPDATES);