diff --git a/src/api/heicConvert.ts b/src/api/heicConvert.ts index 03179edf1..94797a252 100644 --- a/src/api/heicConvert.ts +++ b/src/api/heicConvert.ts @@ -1,8 +1,8 @@ import { ipcRenderer } from 'electron/renderer'; -import { isPlatformMac } from '../utils/preload'; +import { isPlatform } from '../utils/preload'; export async function convertHEIC(fileData: Uint8Array): Promise { - if (!isPlatformMac()) { + if (!isPlatform('mac')) { throw Error('native heic conversion only supported on mac'); } const convertedFileData = await ipcRenderer.invoke( diff --git a/src/services/appUpdater.ts b/src/services/appUpdater.ts index 7200c91f1..2fd5efd48 100644 --- a/src/services/appUpdater.ts +++ b/src/services/appUpdater.ts @@ -6,9 +6,9 @@ import semVerCmp from 'semver-compare'; import { AppUpdateInfo, GetFeatureFlagResponse } from '../types'; import { getSkipAppVersion, setSkipAppVersion } from './userPreference'; import fetch from 'node-fetch'; -import { isPlatformMac } from '../utils/main'; import { logErrorSentry } from './sentry'; import ElectronLog from 'electron-log'; +import { isPlatform } from 'utils/main'; const FIVE_MIN_IN_MICROSECOND = 5 * 60 * 1000; @@ -43,7 +43,7 @@ export async function checkForUpdateAndNotify(mainWindow: BrowserWindow) { const desktopCutoffVersion = await getDesktopCutoffVersion(); if ( desktopCutoffVersion && - isPlatformMac() && + isPlatform('mac') && semVerCmp( updateCheckResult.updateInfo.version, desktopCutoffVersion diff --git a/src/services/autoLauncher.ts b/src/services/autoLauncher.ts index 80111ea46..c28eb177c 100644 --- a/src/services/autoLauncher.ts +++ b/src/services/autoLauncher.ts @@ -1,12 +1,12 @@ +import { isPlatform } from '../utils/main'; import { AutoLauncherClient } from '../types/autoLauncher'; -import { isPlatformWindows, isPlatformMac } from '../utils/main'; import linuxAutoLauncher from './autoLauncherClients/linuxAutoLauncher'; import macAndWindowsAutoLauncher from './autoLauncherClients/macAndWindowsAutoLauncher'; class AutoLauncher { private client: AutoLauncherClient; init() { - if (isPlatformMac() || isPlatformWindows()) { + if (isPlatform('mac') || isPlatform('windows')) { this.client = macAndWindowsAutoLauncher; } else { this.client = linuxAutoLauncher; diff --git a/src/utils/createWindow.ts b/src/utils/createWindow.ts index 415b2f232..db356d467 100644 --- a/src/utils/createWindow.ts +++ b/src/utils/createWindow.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { isDev } from './common'; import { isAppQuitting } from '../main'; import { PROD_HOST_URL } from '../config'; -import { isPlatformMac } from './main'; +import { isPlatform } from './main'; import { getHideDockIconPreference } from '../services/userPreference'; import autoLauncher from '../services/autoLauncher'; @@ -83,12 +83,12 @@ export async function createWindow(): Promise { }); mainWindow.on('hide', () => { const shouldHideDockIcon = getHideDockIconPreference(); - if (isPlatformMac() && shouldHideDockIcon) { + if (isPlatform('mac') && shouldHideDockIcon) { app.dock.hide(); } }); mainWindow.on('show', () => { - if (isPlatformMac()) { + if (isPlatform('mac')) { app.dock.show(); } }); diff --git a/src/utils/main.ts b/src/utils/main.ts index 2b68d65a5..854b9565b 100644 --- a/src/utils/main.ts +++ b/src/utils/main.ts @@ -84,19 +84,23 @@ export function setupNextElectronServe() { }); } -export function isPlatformMac() { - return process.platform === 'darwin'; -} - -export function isPlatformWindows() { - return process.platform === 'win32'; +export function isPlatform(platform: 'mac' | 'windows' | 'linux') { + if (process.platform === 'darwin') { + return platform === 'mac'; + } else if (process.platform === 'win32') { + return platform === 'windows'; + } else if (process.platform === 'linux') { + return platform === 'linux'; + } else { + return false; + } } export async function handleDockIconHideOnAutoLaunch() { const shouldHideDockIcon = getHideDockIconPreference(); const wasAutoLaunched = await autoLauncher.wasAutoLaunched(); - if (isPlatformMac() && shouldHideDockIcon && wasAutoLaunched) { + if (isPlatform('mac') && shouldHideDockIcon && wasAutoLaunched) { app.dock.hide(); } } diff --git a/src/utils/menu.ts b/src/utils/menu.ts index 0d46bb649..5002a1205 100644 --- a/src/utils/menu.ts +++ b/src/utils/menu.ts @@ -11,7 +11,7 @@ import { } from '../services/userPreference'; import { setIsAppQuitting } from '../main'; import autoLauncher from '../services/autoLauncher'; -import { isPlatformMac } from './main'; +import { isPlatform } from './main'; import ElectronLog from 'electron-log'; export function buildContextMenu( @@ -88,7 +88,7 @@ export function buildContextMenu( export async function buildMenuBar(): Promise { let isAutoLaunchEnabled = await autoLauncher.isEnabled(); - const isMac = isPlatformMac(); + const isMac = isPlatform('mac'); let shouldHideDockIcon = getHideDockIconPreference(); const template: MenuItemConstructorOptions[] = [ { diff --git a/src/utils/preload.ts b/src/utils/preload.ts index 1da5bd833..c8d8173d8 100644 --- a/src/utils/preload.ts +++ b/src/utils/preload.ts @@ -15,10 +15,14 @@ export const fixHotReloadNext12 = () => { });`); }; -export function isPlatformMac() { - return process.platform === 'darwin'; -} - -export function isPlatformWindows() { - return process.platform === 'win32'; +export function isPlatform(platform: 'mac' | 'windows' | 'linux') { + if (process.platform === 'darwin') { + return platform === 'mac'; + } else if (process.platform === 'win32') { + return platform === 'windows'; + } else if (process.platform === 'linux') { + return platform === 'linux'; + } else { + return false; + } }