Skip to content

feat: prevent snap to auto update #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/AppUpdateInfoBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MouseEventHandler } from 'react';
import InfoBar from './ui/InfoBar';
import Icon from './ui/icon';

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

const messages = defineMessages({
Expand All @@ -21,6 +21,10 @@ const messages = defineMessages({
id: 'infobar.buttonInstallUpdate',
defaultMessage: 'Restart & install update',
},
isSnapMessage: {
id: 'infobar.isSnapMessage',
defaultMessage: 'Please update via Snap Store.',
},
});

export interface IProps {
Expand All @@ -36,17 +40,21 @@ const AppUpdateInfoBar = (props: IProps) => {
return (
<InfoBar
type="primary"
ctaLabel={intl.formatMessage(messages.buttonInstallUpdate)}
ctaLabel={
isSnap ? undefined : intl.formatMessage(messages.buttonInstallUpdate)
}
onClick={event => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
!isWinPortable && onInstallUpdate(event);
!isWinPortable && !isSnap && onInstallUpdate(event);
}}
onHide={onHide}
>
<Icon icon={mdiInformation} />
<p style={{ padding: '0 0.5rem 0 1rem' }}>
{intl.formatMessage(messages.updateAvailable)}
{isSnap && ` ${intl.formatMessage(messages.isSnapMessage)}`}
</p>

<button
className="info-bar__inline-button"
type="button"
Expand Down
21 changes: 11 additions & 10 deletions src/components/auth/AuthLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { type WrappedComponentProps, injectIntl } from 'react-intl';
import { serverName } from '../../api/apiBase';
import { GITHUB_FERDIUM_URL } from '../../config';
import { isWindows } from '../../environment';
import { isSnap, isWindows } from '../../environment';
import { Component as PublishDebugInfo } from '../../features/publishDebugInfo';
import { updateVersionParse } from '../../helpers/update-helpers';
import globalMessages from '../../i18n/globalMessages';
Expand Down Expand Up @@ -81,15 +81,16 @@ class AuthLayout extends Component<IProps, IState> {
{intl.formatMessage(globalMessages.notConnectedToTheInternet)}
</InfoBar>
)}
{appUpdateIsDownloaded && this.state.shouldShowAppUpdateInfoBar && (
<AppUpdateInfoBar
onInstallUpdate={installAppUpdate}
updateVersionParsed={updateVersionParse(updateVersion)}
onHide={() => {
this.setState({ shouldShowAppUpdateInfoBar: false });
}}
/>
)}
{(appUpdateIsDownloaded || isSnap) &&
this.state.shouldShowAppUpdateInfoBar && (
<AppUpdateInfoBar
onInstallUpdate={installAppUpdate}
updateVersionParsed={updateVersionParse(updateVersion)}
onHide={() => {
this.setState({ shouldShowAppUpdateInfoBar: false });
}}
/>
)}
{isOnline && !isAPIHealthy && (
<InfoBar
type="danger"
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { updateVersionParse } from '../../helpers/update-helpers';
import InfoBar from '../ui/InfoBar';
import ErrorBoundary from '../util/ErrorBoundary';

import { isMac, isWindows } from '../../environment';
import { isMac, isSnap, isWindows } from '../../environment';
import Todos from '../../features/todos/containers/TodosScreen';
import { workspaceStore } from '../../features/workspaces';
import WorkspaceSwitchingIndicator from '../../features/workspaces/components/WorkspaceSwitchingIndicator';
Expand Down Expand Up @@ -204,7 +204,7 @@ class AppLayout extends Component<PropsWithChildren<IProps>, IState> {
</InfoBar>
)}
{automaticUpdates &&
appUpdateIsDownloaded &&
(appUpdateIsDownloaded || isSnap) &&
this.state.shouldShowAppUpdateInfoBar && (
<AppUpdateInfoBar
onInstallUpdate={installAppUpdate}
Expand Down
18 changes: 14 additions & 4 deletions src/components/settings/settings/EditSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../../config';
import {
isMac,
isSnap,
isWinPortable,
isWindows,
lockFerdiumShortcutKey,
Expand Down Expand Up @@ -253,6 +254,10 @@ const messages = defineMessages({
id: 'settings.app.updateStatusAvailable',
defaultMessage: 'Update available, downloading...',
},
updateAvailableSnap: {
id: 'settings.app.updateAvailableSnap',
defaultMessage: 'Update available. Please update via Snap Store.',
},
updateStatusUpToDate: {
id: 'settings.app.updateStatusUpToDate',
defaultMessage: 'You are using the latest version of Ferdium',
Expand Down Expand Up @@ -447,6 +452,10 @@ class EditSettingsForm extends Component<IProps, IState> {
intl,
} = this.props;

const installUpdateMessage = isSnap
? messages.updateAvailableSnap
: messages.buttonInstallUpdate;

let updateButtonLabelMessage = messages.buttonSearchForUpdate;
if (isCheckingForUpdates) {
updateButtonLabelMessage = messages.updateStatusSearching;
Expand Down Expand Up @@ -1262,12 +1271,13 @@ class EditSettingsForm extends Component<IProps, IState> {
<>
<div>
<Toggle {...form.$('beta').bind()} />
{updateIsReadyToInstall ? (
{updateIsReadyToInstall ||
(isSnap && isUpdateAvailable) ? (
<Button
label={intl.formatMessage(
messages.buttonInstallUpdate,
)}
label={intl.formatMessage(installUpdateMessage)}
onClick={installUpdate}
disabled={isSnap}
buttonType={isSnap ? 'secondary' : undefined}
/>
) : (
<Button
Expand Down
10 changes: 10 additions & 0 deletions src/electron/ipc-api/autoUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { BrowserWindow, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
// eslint-disable-next-line import/no-cycle
import { appEvents } from '../..';
import { isSnap } from '../../environment';

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

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

// The following line is a workaround to force the development update. Should only be used for development purposes.
// autoUpdater.forceDevUpdateConfig = true;

if (enableUpdate) {
ipcMain.on('autoUpdate', (event, args) => {
if (enableUpdate) {
Expand All @@ -21,6 +25,12 @@ export default (params: { mainWindow: BrowserWindow; settings: any }) => {
debug('checking for update');
autoUpdater.checkForUpdates();
} else if (args.action === 'install') {
// If the app is a snap, auto-updates are not supported.
// The snap store will handle updates, therefore the user should be prompted to update through snap store.
if (isSnap) {
return;
}

debug('installing update');

appEvents.emit('install-update');
Expand Down
1 change: 1 addition & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const isLinux = process.platform === 'linux';
export const isWinPortable = process.env.PORTABLE_EXECUTABLE_FILE != null;

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

export const electronVersion: string = process.versions.electron ?? '';
export const chromeVersion: string = process.versions.chrome ?? '';
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"infobar.buttonInstallUpdate": "Restart & install update",
"infobar.buttonReloadServices": "Reload services",
"infobar.hide": "Hide",
"infobar.isSnapMessage": "Please update via Snap Store.",
"infobar.requiredRequestsFailed": "Could not load services and user information",
"infobar.servicesUpdated": "Your services have been updated.",
"infobar.updateAvailable": "A new update for Ferdium is available.",
Expand Down Expand Up @@ -327,6 +328,7 @@
"settings.app.todoServerInfo": "This server will be used for the \"Ferdium Todo\" feature.",
"settings.app.translationHelp": "Help us to translate Ferdium into your language.",
"settings.app.universalDarkModeInfo": "Universal Dark Mode tries to dynamically generate dark mode styles for services that are otherwise not currently supported.",
"settings.app.updateAvailableSnap": "Update available. Please update via Snap Store.",
"settings.app.updateStatusAvailable": "Update available, downloading...",
"settings.app.updateStatusSearching": "Searching for updates...",
"settings.app.updateStatusUpToDate": "You are using the latest version of Ferdium",
Expand Down
2 changes: 1 addition & 1 deletion src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default class AppStore extends TypedStore {
this._autoStart();

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

Expand Down