From 02ae523928e9bf579e4196fdc8c910141fbeeda7 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 19 Jan 2025 17:36:30 -0500 Subject: [PATCH] refactor: platform shared util Signed-off-by: Adam Setch --- src/main/first-run.ts | 3 ++- src/main/main.ts | 3 ++- src/main/menu.ts | 4 ++-- src/renderer/components/settings/SystemSettings.tsx | 2 +- src/renderer/utils/notifications.ts | 2 +- src/{renderer/utils => shared}/platform.ts | 0 6 files changed, 8 insertions(+), 6 deletions(-) rename src/{renderer/utils => shared}/platform.ts (100%) diff --git a/src/main/first-run.ts b/src/main/first-run.ts index c119ea37a..a0fbe86d9 100644 --- a/src/main/first-run.ts +++ b/src/main/first-run.ts @@ -3,6 +3,7 @@ import path from 'node:path'; import { app, dialog } from 'electron'; import { logError } from '../shared/logger'; +import { isMacOS } from '../shared/platform'; export async function onFirstRunMaybe() { if (isFirstRun()) { @@ -12,7 +13,7 @@ export async function onFirstRunMaybe() { // Ask user if the app should be moved to the applications folder. async function promptMoveToApplicationsFolder() { - if (process.platform !== 'darwin') return; + if (!isMacOS()) return; const isDevMode = !!process.defaultApp; if (isDevMode || app.isInApplicationsFolder()) return; diff --git a/src/main/main.ts b/src/main/main.ts index eb5ba9d8b..9731e4aae 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -3,6 +3,7 @@ import log from 'electron-log'; import { menubar } from 'menubar'; import { APPLICATION } from '../shared/constants'; +import { isMacOS, isWindows } from '../shared/platform'; import { onFirstRunMaybe } from './first-run'; import { TrayIcons } from './icons'; import MenuBuilder from './menu'; @@ -39,7 +40,7 @@ const contextMenu = menuBuilder.buildMenu(); * Electron Auto Updater only supports macOS and Windows * https://github.com/electron/update-electron-app */ -if (process.platform === 'darwin' || process.platform === 'win32') { +if (isMacOS() || isWindows()) { const updater = new Updater(mb, menuBuilder); updater.initialize(); } diff --git a/src/main/menu.ts b/src/main/menu.ts index 8e1aeb88b..d77f02737 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -1,6 +1,7 @@ import { Menu, MenuItem } from 'electron'; import { autoUpdater } from 'electron-updater'; import type { Menubar } from 'menubar'; +import { isMacOS } from '../shared/platform'; import { openLogsDirectory, resetApp, takeScreenshot } from './utils'; export default class MenuBuilder { @@ -60,8 +61,7 @@ export default class MenuBuilder { }, { role: 'toggleDevTools', - accelerator: - process.platform === 'darwin' ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', + accelerator: isMacOS() ? 'Alt+Cmd+I' : 'Ctrl+Shift+I', }, { label: 'Take Screenshot', diff --git a/src/renderer/components/settings/SystemSettings.tsx b/src/renderer/components/settings/SystemSettings.tsx index b6b5802b9..c02c7173c 100644 --- a/src/renderer/components/settings/SystemSettings.tsx +++ b/src/renderer/components/settings/SystemSettings.tsx @@ -1,9 +1,9 @@ import { DeviceDesktopIcon } from '@primer/octicons-react'; import { type FC, useContext } from 'react'; +import { isLinux, isMacOS } from '../../../shared/platform'; import { AppContext } from '../../context/App'; import { OpenPreference } from '../../types'; import { Constants } from '../../utils/constants'; -import { isLinux, isMacOS } from '../../utils/platform'; import { Checkbox } from '../fields/Checkbox'; import { RadioGroup } from '../fields/RadioGroup'; import { Legend } from './Legend'; diff --git a/src/renderer/utils/notifications.ts b/src/renderer/utils/notifications.ts index 091f988bc..640a67e29 100644 --- a/src/renderer/utils/notifications.ts +++ b/src/renderer/utils/notifications.ts @@ -1,6 +1,7 @@ import path from 'node:path'; import { logError, logWarn } from '../../shared/logger'; +import { isWindows } from '../../shared/platform'; import type { AccountNotifications, GitifyState, @@ -13,7 +14,6 @@ import { getAccountUUID } from './auth/utils'; import { hideWindow, showWindow, updateTrayIcon } from './comms'; import { Constants } from './constants'; import { openNotification } from './links'; -import { isWindows } from './platform'; import { getGitifySubjectDetails } from './subject'; export function setTrayIconColor(notifications: AccountNotifications[]) { diff --git a/src/renderer/utils/platform.ts b/src/shared/platform.ts similarity index 100% rename from src/renderer/utils/platform.ts rename to src/shared/platform.ts