Skip to content

Commit 7098931

Browse files
authored
feat: prevent snap to auto update (#2079)
1 parent 3f4e6c9 commit 7098931

File tree

8 files changed

+52
-20
lines changed

8 files changed

+52
-20
lines changed

src/components/AppUpdateInfoBar.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { MouseEventHandler } from 'react';
55
import InfoBar from './ui/InfoBar';
66
import Icon from './ui/icon';
77

8-
import { isWinPortable } from '../environment';
8+
import { isSnap, isWinPortable } from '../environment';
99
import { onAuthGoToReleaseNotes } from '../helpers/update-helpers';
1010

1111
const messages = defineMessages({
@@ -21,6 +21,10 @@ const messages = defineMessages({
2121
id: 'infobar.buttonInstallUpdate',
2222
defaultMessage: 'Restart & install update',
2323
},
24+
isSnapMessage: {
25+
id: 'infobar.isSnapMessage',
26+
defaultMessage: 'Please update via Snap Store.',
27+
},
2428
});
2529

2630
export interface IProps {
@@ -36,17 +40,21 @@ const AppUpdateInfoBar = (props: IProps) => {
3640
return (
3741
<InfoBar
3842
type="primary"
39-
ctaLabel={intl.formatMessage(messages.buttonInstallUpdate)}
43+
ctaLabel={
44+
isSnap ? undefined : intl.formatMessage(messages.buttonInstallUpdate)
45+
}
4046
onClick={event => {
4147
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
42-
!isWinPortable && onInstallUpdate(event);
48+
!isWinPortable && !isSnap && onInstallUpdate(event);
4349
}}
4450
onHide={onHide}
4551
>
4652
<Icon icon={mdiInformation} />
4753
<p style={{ padding: '0 0.5rem 0 1rem' }}>
4854
{intl.formatMessage(messages.updateAvailable)}
55+
{isSnap && ` ${intl.formatMessage(messages.isSnapMessage)}`}
4956
</p>
57+
5058
<button
5159
className="info-bar__inline-button"
5260
type="button"

src/components/auth/AuthLayout.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { type WrappedComponentProps, injectIntl } from 'react-intl';
1212
import { serverName } from '../../api/apiBase';
1313
import { GITHUB_FERDIUM_URL } from '../../config';
14-
import { isWindows } from '../../environment';
14+
import { isSnap, isWindows } from '../../environment';
1515
import { Component as PublishDebugInfo } from '../../features/publishDebugInfo';
1616
import { updateVersionParse } from '../../helpers/update-helpers';
1717
import globalMessages from '../../i18n/globalMessages';
@@ -81,15 +81,16 @@ class AuthLayout extends Component<IProps, IState> {
8181
{intl.formatMessage(globalMessages.notConnectedToTheInternet)}
8282
</InfoBar>
8383
)}
84-
{appUpdateIsDownloaded && this.state.shouldShowAppUpdateInfoBar && (
85-
<AppUpdateInfoBar
86-
onInstallUpdate={installAppUpdate}
87-
updateVersionParsed={updateVersionParse(updateVersion)}
88-
onHide={() => {
89-
this.setState({ shouldShowAppUpdateInfoBar: false });
90-
}}
91-
/>
92-
)}
84+
{(appUpdateIsDownloaded || isSnap) &&
85+
this.state.shouldShowAppUpdateInfoBar && (
86+
<AppUpdateInfoBar
87+
onInstallUpdate={installAppUpdate}
88+
updateVersionParsed={updateVersionParse(updateVersion)}
89+
onHide={() => {
90+
this.setState({ shouldShowAppUpdateInfoBar: false });
91+
}}
92+
/>
93+
)}
9394
{isOnline && !isAPIHealthy && (
9495
<InfoBar
9596
type="danger"

src/components/layout/AppLayout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { updateVersionParse } from '../../helpers/update-helpers';
1919
import InfoBar from '../ui/InfoBar';
2020
import ErrorBoundary from '../util/ErrorBoundary';
2121

22-
import { isMac, isWindows } from '../../environment';
22+
import { isMac, isSnap, isWindows } from '../../environment';
2323
import Todos from '../../features/todos/containers/TodosScreen';
2424
import { workspaceStore } from '../../features/workspaces';
2525
import WorkspaceSwitchingIndicator from '../../features/workspaces/components/WorkspaceSwitchingIndicator';
@@ -204,7 +204,7 @@ class AppLayout extends Component<PropsWithChildren<IProps>, IState> {
204204
</InfoBar>
205205
)}
206206
{automaticUpdates &&
207-
appUpdateIsDownloaded &&
207+
(appUpdateIsDownloaded || isSnap) &&
208208
this.state.shouldShowAppUpdateInfoBar && (
209209
<AppUpdateInfoBar
210210
onInstallUpdate={installAppUpdate}

src/components/settings/settings/EditSettingsForm.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../../../config';
2222
import {
2323
isMac,
24+
isSnap,
2425
isWinPortable,
2526
isWindows,
2627
lockFerdiumShortcutKey,
@@ -253,6 +254,10 @@ const messages = defineMessages({
253254
id: 'settings.app.updateStatusAvailable',
254255
defaultMessage: 'Update available, downloading...',
255256
},
257+
updateAvailableSnap: {
258+
id: 'settings.app.updateAvailableSnap',
259+
defaultMessage: 'Update available. Please update via Snap Store.',
260+
},
256261
updateStatusUpToDate: {
257262
id: 'settings.app.updateStatusUpToDate',
258263
defaultMessage: 'You are using the latest version of Ferdium',
@@ -447,6 +452,10 @@ class EditSettingsForm extends Component<IProps, IState> {
447452
intl,
448453
} = this.props;
449454

455+
const installUpdateMessage = isSnap
456+
? messages.updateAvailableSnap
457+
: messages.buttonInstallUpdate;
458+
450459
let updateButtonLabelMessage = messages.buttonSearchForUpdate;
451460
if (isCheckingForUpdates) {
452461
updateButtonLabelMessage = messages.updateStatusSearching;
@@ -1262,12 +1271,13 @@ class EditSettingsForm extends Component<IProps, IState> {
12621271
<>
12631272
<div>
12641273
<Toggle {...form.$('beta').bind()} />
1265-
{updateIsReadyToInstall ? (
1274+
{updateIsReadyToInstall ||
1275+
(isSnap && isUpdateAvailable) ? (
12661276
<Button
1267-
label={intl.formatMessage(
1268-
messages.buttonInstallUpdate,
1269-
)}
1277+
label={intl.formatMessage(installUpdateMessage)}
12701278
onClick={installUpdate}
1279+
disabled={isSnap}
1280+
buttonType={isSnap ? 'secondary' : undefined}
12711281
/>
12721282
) : (
12731283
<Button

src/electron/ipc-api/autoUpdate.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { BrowserWindow, ipcMain } from 'electron';
22
import { autoUpdater } from 'electron-updater';
33
// eslint-disable-next-line import/no-cycle
44
import { appEvents } from '../..';
5+
import { isSnap } from '../../environment';
56

67
const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:autoUpdate');
78

89
export default (params: { mainWindow: BrowserWindow; settings: any }) => {
910
const enableUpdate = Boolean(params.settings.app.get('automaticUpdates'));
1011

12+
// The following line is a workaround to force the development update. Should only be used for development purposes.
13+
// autoUpdater.forceDevUpdateConfig = true;
14+
1115
if (enableUpdate) {
1216
ipcMain.on('autoUpdate', (event, args) => {
1317
if (enableUpdate) {
@@ -21,6 +25,12 @@ export default (params: { mainWindow: BrowserWindow; settings: any }) => {
2125
debug('checking for update');
2226
autoUpdater.checkForUpdates();
2327
} else if (args.action === 'install') {
28+
// If the app is a snap, auto-updates are not supported.
29+
// The snap store will handle updates, therefore the user should be prompted to update through snap store.
30+
if (isSnap) {
31+
return;
32+
}
33+
2434
debug('installing update');
2535

2636
appEvents.emit('install-update');

src/environment.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const isLinux = process.platform === 'linux';
88
export const isWinPortable = process.env.PORTABLE_EXECUTABLE_FILE != null;
99

1010
export const isWayland = isLinux && process.env.XDG_SESSION_TYPE === 'wayland';
11+
export const isSnap = isLinux && process.env.SNAP != null;
1112

1213
export const electronVersion: string = process.versions.electron ?? '';
1314
export const chromeVersion: string = process.versions.chrome ?? '';

src/i18n/locales/en-US.json

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"infobar.buttonInstallUpdate": "Restart & install update",
4848
"infobar.buttonReloadServices": "Reload services",
4949
"infobar.hide": "Hide",
50+
"infobar.isSnapMessage": "Please update via Snap Store.",
5051
"infobar.requiredRequestsFailed": "Could not load services and user information",
5152
"infobar.servicesUpdated": "Your services have been updated.",
5253
"infobar.updateAvailable": "A new update for Ferdium is available.",
@@ -327,6 +328,7 @@
327328
"settings.app.todoServerInfo": "This server will be used for the \"Ferdium Todo\" feature.",
328329
"settings.app.translationHelp": "Help us to translate Ferdium into your language.",
329330
"settings.app.universalDarkModeInfo": "Universal Dark Mode tries to dynamically generate dark mode styles for services that are otherwise not currently supported.",
331+
"settings.app.updateAvailableSnap": "Update available. Please update via Snap Store.",
330332
"settings.app.updateStatusAvailable": "Update available, downloading...",
331333
"settings.app.updateStatusSearching": "Searching for updates...",
332334
"settings.app.updateStatusUpToDate": "You are using the latest version of Ferdium",

src/stores/AppStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default class AppStore extends TypedStore {
217217
this._autoStart();
218218

219219
// Check if system is muted
220-
// There are no events to subscribe so we need to poll everey 5s
220+
// There are no events to subscribe so we need to poll every 5s
221221
this._systemDND();
222222
setInterval(() => this._systemDND(), ms('5s'));
223223

0 commit comments

Comments
 (0)