Better way of handling autoUpdate and listen for update available event to display update nag.
This commit is contained in:
parent
48c5f58a8e
commit
e1ecf87df7
6 changed files with 21 additions and 16 deletions
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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}
|
||||
|
|
16
ui/index.jsx
16
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) => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,3 +83,5 @@ export const selectHomepageData = createSelector(
|
|||
);
|
||||
|
||||
export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED);
|
||||
|
||||
export const selectDisableAutoUpdates = makeSelectClientSetting(SETTINGS.DISABLE_AUTO_UPDATES);
|
||||
|
|
Loading…
Reference in a new issue