refactor platform check utils
This commit is contained in:
parent
a4500609ab
commit
f181865e64
|
@ -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<Uint8Array> {
|
||||
if (!isPlatformMac()) {
|
||||
if (!isPlatform('mac')) {
|
||||
throw Error('native heic conversion only supported on mac');
|
||||
}
|
||||
const convertedFileData = await ipcRenderer.invoke(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<BrowserWindow> {
|
|||
});
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Menu> {
|
||||
let isAutoLaunchEnabled = await autoLauncher.isEnabled();
|
||||
const isMac = isPlatformMac();
|
||||
const isMac = isPlatform('mac');
|
||||
let shouldHideDockIcon = getHideDockIconPreference();
|
||||
const template: MenuItemConstructorOptions[] = [
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue