1 import UAParser from 'ua-parser-js';
3 import type { APP_NAMES } from '../constants';
4 import { APPS } from '../constants';
5 import { isLinux, isMac, isWindows } from './browser';
7 const uaParser = new UAParser();
8 const ua = uaParser.getResult();
10 export const SUPPORTED_ELECTRON_APP: APP_NAMES[] = [APPS.PROTONACCOUNT, APPS.PROTONCALENDAR, APPS.PROTONMAIL];
12 export const isElectronApp = /electron/i.test(ua.ua);
13 export const isElectronOnMac = isElectronApp && isMac();
14 export const isElectronOnWindows = isElectronApp && isWindows();
15 export const isElectronOnLinux = isElectronApp && isLinux();
17 export const isElectronOnSupportedApps = (app: APP_NAMES) => {
18 return isElectronApp && SUPPORTED_ELECTRON_APP.includes(app);
21 export const isElectronOnInboxApps = (app: APP_NAMES) => {
22 return isElectronApp && (app === APPS.PROTONCALENDAR || app === APPS.PROTONMAIL || app === APPS.PROTONACCOUNT);
25 /* Electron apps built with Electron Forge will inject the `productName` and
26 * `version` properties of the app's package.json in the user-agent. */
27 export const isElectronMail = isElectronApp && /ProtonMail/i.test(ua.ua);
28 export const isElectronPass = isElectronApp && /ProtonPass/i.test(ua.ua);
31 * The version of the application is injected in the user-agent by Electron Forge.
32 * This method works if the version uses the following format: `x.y.z`.
34 export const electronAppVersion = ua.ua.match(/((ProtonMail|ProtonPass)\/)(?<version>([0-9][.]).{3})/i)?.groups