1 import { type IconName } from '@proton/components/components/icon/Icon';
2 import { fetchDesktopVersion } from '@proton/shared/lib/apps/desktopVersions';
3 import { DESKTOP_APP_NAMES, DESKTOP_PLATFORMS, RELEASE_CATEGORIES } from '@proton/shared/lib/constants';
4 import { isMac, isWindows } from '@proton/shared/lib/helpers/browser';
6 export type PlatformInfo = {
7 platform: DESKTOP_PLATFORMS;
10 isPreferred: () => boolean;
11 hideIfUnavailable?: boolean;
13 // These are useful in case we ever want to lock downloads to
14 // a specific version or category in the future
16 releaseCategory?: RELEASE_CATEGORIES;
20 * A sorted list of app platforms, in order of preference.
22 * For example, when browsing on macOS, the corresponding platform will be first in the list.
23 * If there is no preferred platform, the default order is used.
25 export const appPlatforms = (
28 platform: DESKTOP_PLATFORMS.WINDOWS,
29 icon: 'brand-windows',
31 isPreferred: isWindows,
34 platform: DESKTOP_PLATFORMS.MACOS,
38 hideIfUnavailable: true,
40 ] satisfies PlatformInfo[] as PlatformInfo[]
41 ).sort((a, b) => Number(b.isPreferred()) - Number(a.isPreferred()));
44 * Fetches download URLs for supported platforms and returns them in a map.
46 export const fetchDesktopDownloads = async () => {
47 let versions: Partial<Record<DESKTOP_PLATFORMS, string>> = {};
50 appPlatforms.map(({ platform, version, releaseCategory }) =>
52 appName: DESKTOP_APP_NAMES.DRIVE,
54 version: version || 'latest',
55 category: releaseCategory || RELEASE_CATEGORIES.STABLE,
59 throw new Error('Undefined response from API');
62 versions = { ...versions, [platform]: meta.url };
64 .catch((reason) => console.warn(`Download link for ${platform} cannot be fetched`, reason))