diff options
Diffstat (limited to 'desktop')
3 files changed, 109 insertions, 41 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/NotificationArea.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/NotificationArea.tsx index 3fabd86320..f6d71fee51 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/NotificationArea.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/NotificationArea.tsx @@ -12,7 +12,6 @@ import { InconsistentVersionNotificationProvider, ReconnectingNotificationProvider, UnsupportedVersionNotificationProvider, - UpdateAvailableNotificationProvider, } from '../../shared/notifications'; import { useAppContext } from '../context'; import { @@ -35,6 +34,7 @@ import { OpenVpnSupportEndingNotificationProvider, UnsupportedWireGuardPortNotificationProvider, } from '../lib/notifications'; +import { AppUpgradeAvailableNotificationProvider } from '../lib/notifications/app-upgrade-available'; import { useTunnelProtocol } from '../lib/relay-settings-hooks'; import { RoutePath } from '../lib/routes'; import accountActions from '../redux/account/actions'; @@ -80,7 +80,7 @@ export default function NotificationArea(props: IProps) { const { hideNewDeviceBanner } = useActions(accountActions); - const { setDisplayedChangelog, appUpgrade } = useAppContext(); + const { setDisplayedChangelog, setDismissedUpgrade, appUpgrade } = useAppContext(); const currentVersion = useSelector((state) => state.version.current); const displayedForVersion = useSelector( @@ -100,6 +100,9 @@ export default function NotificationArea(props: IProps) { await setSplitTunnelingState(false); }, [setSplitTunnelingState]); + const updateDismissedForVersion = useSelector( + (state) => state.settings.guiSettings.updateDismissedForVersion, + ); const hasAppUpgradeError = useHasAppUpgradeError(); const { appUpgradeError } = useAppUpgradeError(); @@ -175,7 +178,13 @@ export default function NotificationArea(props: IProps) { changelog, close, }), - new UpdateAvailableNotificationProvider(version), + new AppUpgradeAvailableNotificationProvider({ + platform: 'linux', + suggestedUpgradeVersion: suggestedUpgrade?.version, + suggestedIsBeta: version.suggestedIsBeta, + updateDismissedForVersion, + close: setDismissedUpgrade, + }), new OpenVpnSupportEndingNotificationProvider({ tunnelProtocol }), ); diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/notifications/app-upgrade-available.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/notifications/app-upgrade-available.ts new file mode 100644 index 0000000000..871bb98b12 --- /dev/null +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/notifications/app-upgrade-available.ts @@ -0,0 +1,96 @@ +import { sprintf } from 'sprintf-js'; + +import { messages } from '../../../shared/gettext'; +import { InAppNotification, InAppNotificationProvider } from '../../../shared/notifications'; +import { getDownloadUrl } from '../../../shared/version'; +import { RoutePath } from '../routes'; + +interface AppUpgradeAvailableNotificationContext { + suggestedUpgradeVersion?: string; + suggestedIsBeta?: boolean; + updateDismissedForVersion?: string; + platform: NodeJS.Platform; + close: () => void; +} + +export class AppUpgradeAvailableNotificationProvider implements InAppNotificationProvider { + public constructor(private context: AppUpgradeAvailableNotificationContext) {} + + public mayDisplay(): boolean { + const { suggestedUpgradeVersion, suggestedIsBeta, updateDismissedForVersion } = this.context; + if (!suggestedUpgradeVersion) { + return false; + } + if (suggestedIsBeta && suggestedUpgradeVersion === updateDismissedForVersion) { + return false; + } + return true; + } + + public getInAppNotification(): InAppNotification { + const { close, platform, suggestedIsBeta } = this.context; + const isLinux = platform === 'linux'; + + return { + indicator: 'warning', + title: suggestedIsBeta + ? messages.pgettext('in-app-notifications', 'BETA UPDATE AVAILABLE') + : messages.pgettext('in-app-notifications', 'UPDATE AVAILABLE'), + subtitle: [ + { + content: this.inAppMessage(), + }, + { + content: + // TRANSLATORS: Link text to go to the app upgrade view + messages.pgettext('in-app-notifications', 'Click here to update'), + action: isLinux + ? { + type: 'navigate-external', + link: { + to: getDownloadUrl(suggestedIsBeta ?? false), + 'aria-label': + // TRANSLATORS: Accessbility label for link to go to download page. + messages.pgettext( + 'accessibility', + 'New version available, click here to go to download page, opens externally', + ), + }, + } + : { + type: 'navigate-internal', + link: { + to: RoutePath.changelog, + // TRANSLATORS: Accessbility label for link to go to upgrade view. + 'aria-label': messages.pgettext( + 'accessibility', + 'New version available, click here to go to update view', + ), + }, + }, + }, + ], + action: suggestedIsBeta ? { type: 'close', close } : undefined, + }; + } + + private inAppMessage(): string { + const { suggestedIsBeta, suggestedUpgradeVersion } = this.context; + if (suggestedIsBeta) { + return sprintf( + // TRANSLATORS: The in-app banner displayed to the user when the app beta update is + // TRANSLATORS: available. + // TRANSLATORS: Available placeholders: + // TRANSLATORS: %(version)s - The version number of the new beta version. + messages.pgettext('in-app-notifications', 'Try out the newest beta version (%(version)s).'), + { version: suggestedUpgradeVersion }, + ); + } else { + // TRANSLATORS: The in-app banner displayed to the user when the app update is available. + return messages.pgettext( + 'in-app-notifications', + 'Install the latest app version to stay up to date.', + ); + } + } +} diff --git a/desktop/packages/mullvad-vpn/src/shared/notifications/update-available.ts b/desktop/packages/mullvad-vpn/src/shared/notifications/update-available.ts index 180fe132f4..70452289c6 100644 --- a/desktop/packages/mullvad-vpn/src/shared/notifications/update-available.ts +++ b/desktop/packages/mullvad-vpn/src/shared/notifications/update-available.ts @@ -4,8 +4,6 @@ import { messages } from '../../shared/gettext'; import { AppVersionInfoSuggestedUpgrade } from '../daemon-rpc-types'; import { getDownloadUrl } from '../version'; import { - InAppNotification, - InAppNotificationProvider, SystemNotification, SystemNotificationCategory, SystemNotificationProvider, @@ -17,29 +15,13 @@ interface UpdateAvailableNotificationContext { suggestedIsBeta?: boolean; } -export class UpdateAvailableNotificationProvider - implements InAppNotificationProvider, SystemNotificationProvider -{ +export class UpdateAvailableNotificationProvider implements SystemNotificationProvider { public constructor(private context: UpdateAvailableNotificationContext) {} public mayDisplay() { return this.context.suggestedUpgrade?.version ? true : false; } - public getInAppNotification(): InAppNotification { - return { - indicator: 'warning', - title: this.context.suggestedIsBeta - ? messages.pgettext('in-app-notifications', 'BETA UPDATE AVAILABLE') - : messages.pgettext('in-app-notifications', 'UPDATE AVAILABLE'), - subtitle: this.inAppMessage(), - action: { - type: 'open-url', - url: getDownloadUrl(this.context.suggestedIsBeta ?? false), - }, - }; - } - public getSystemNotification(): SystemNotification { return { message: this.systemMessage(), @@ -55,25 +37,6 @@ export class UpdateAvailableNotificationProvider }; } - private inAppMessage(): string { - if (this.context.suggestedIsBeta) { - return sprintf( - // TRANSLATORS: The in-app banner displayed to the user when the app beta update is - // TRANSLATORS: available. - // TRANSLATORS: Available placeholders: - // TRANSLATORS: %(version)s - The version number of the new beta version. - messages.pgettext('in-app-notifications', 'Try out the newest beta version (%(version)s).'), - { version: this.context.suggestedUpgrade?.version }, - ); - } else { - // TRANSLATORS: The in-app banner displayed to the user when the app update is available. - return messages.pgettext( - 'in-app-notifications', - 'Install the latest app version to stay up to date.', - ); - } - } - private systemMessage(): string { if (this.context.suggestedIsBeta) { return sprintf( |
