diff --git a/lib/shared/version-utils.js b/lib/shared/version-utils.js --- a/lib/shared/version-utils.js +++ b/lib/shared/version-utils.js @@ -1,6 +1,10 @@ // @flow -import { type PlatformDetails, isWebPlatform } from '../types/device-types.js'; +import { + type PlatformDetails, + isWebPlatform, + isDesktopPlatform, +} from '../types/device-types.js'; /** * A code version used for features that are waiting to be released @@ -16,16 +20,25 @@ function hasMinCodeVersion( platformDetails: ?PlatformDetails, - minCodeVersion: $Shape<{ +native: number, +web: number }>, + minCodeVersion: $Shape<{ + +native: number, + +web: number, + +majorDesktop: number, + }>, ): boolean { if (!platformDetails) { return true; } - const { codeVersion } = platformDetails; + + const { codeVersion, majorDesktopVersion } = platformDetails; const minVersion = isWebPlatform(platformDetails.platform) ? minCodeVersion.web : minCodeVersion.native; + const minMajorDesktopVersion = isDesktopPlatform(platformDetails.platform) + ? minCodeVersion.majorDesktop + : undefined; + if (!minVersion) { return true; } @@ -33,6 +46,18 @@ return false; } + if (!minMajorDesktopVersion) { + return true; + } + + if (!majorDesktopVersion) { + return false; + } + + if (majorDesktopVersion < minMajorDesktopVersion) { + return false; + } + return true; } @@ -58,9 +83,14 @@ return true; } +function extractMajorDesktopVersion(desktopVersion: string): number { + return desktopVersion.split('.').map(Number).shift(); +} + export { FUTURE_CODE_VERSION, NEXT_CODE_VERSION, hasMinCodeVersion, hasMinStateVersion, + extractMajorDesktopVersion, }; diff --git a/lib/types/device-types.js b/lib/types/device-types.js --- a/lib/types/device-types.js +++ b/lib/types/device-types.js @@ -29,6 +29,10 @@ return platform === 'web' || platform === 'windows' || platform === 'macos'; } +export function isDesktopPlatform(platform: ?string): boolean { + return platform === 'macos' || platform === 'windows'; +} + export type DeviceTokenUpdateRequest = { +deviceToken: string, +deviceType?: DeviceType, @@ -39,6 +43,7 @@ +platform: Platform, +codeVersion?: number, +stateVersion?: number, + +majorDesktopVersion?: ?number, }; export type LastCommunicatedPlatformDetails = { diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -70,6 +70,7 @@ platform: tPlatform, codeVersion: t.maybe(t.Number), stateVersion: t.maybe(t.Number), + majorDesktopVersion: t.maybe(t.Number), }); const tPassword: TRefinement = t.refinement( t.String, diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -26,6 +26,7 @@ combineLoadingStatuses, } from 'lib/selectors/loading-selectors.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; +import { extractMajorDesktopVersion } from 'lib/shared/version-utils.js'; import { TunnelbrokerProvider } from 'lib/tunnelbroker/tunnelbroker-context.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; @@ -93,6 +94,9 @@ platform: electron?.platform ?? 'web', codeVersion: 42, stateVersion: persistConfig.version, + majorDesktopVersion: electron?.version + ? extractMajorDesktopVersion(electron?.version) + : null, }, });