From ba53acdca7a5ee30e2241f6e024a994ba2c9a207 Mon Sep 17 00:00:00 2001 From: Lewis Crichton Date: Sat, 28 Oct 2023 12:46:48 +0100 Subject: [PATCH] chore: dedupe platform consts --- src/components/VencordSettings/VencordTab.tsx | 4 +--- src/plugins/experiments/index.tsx | 7 +++---- src/plugins/quickReply/index.ts | 3 +-- src/utils/constants.ts | 7 +++++++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index a8e9ea5b..d368a159 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -21,6 +21,7 @@ import { Settings, useSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import DonateButton from "@components/DonateButton"; import { ErrorCard } from "@components/ErrorCard"; +import { isMac, isWindows } from "@utils/constants"; import { Margins } from "@utils/margins"; import { identity } from "@utils/misc"; import { relaunch, showItemInFolder } from "@utils/native"; @@ -46,9 +47,6 @@ function VencordSettings() { const donateImage = React.useMemo(() => Math.random() > 0.5 ? DEFAULT_DONATE_IMAGE : SHIGGY_DONATE_IMAGE, []); - const isWindows = navigator.platform.toLowerCase().startsWith("win"); - const isMac = navigator.platform.toLowerCase().startsWith("mac"); - const Switches: Array; title: string; diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx index 89fcf33e..1159e92a 100644 --- a/src/plugins/experiments/index.tsx +++ b/src/plugins/experiments/index.tsx @@ -19,7 +19,7 @@ import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { ErrorCard } from "@components/ErrorCard"; -import { Devs } from "@utils/constants"; +import { Devs, isMac } from "@utils/constants"; import { Margins } from "@utils/margins"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; @@ -96,9 +96,8 @@ export default definePlugin({ ], settingsAboutComponent: () => { - const isMacOS = navigator.platform.includes("Mac"); - const modKey = isMacOS ? "cmd" : "ctrl"; - const altKey = isMacOS ? "opt" : "alt"; + const modKey = isMac ? "cmd" : "ctrl"; + const altKey = isMac ? "opt" : "alt"; return ( More Information diff --git a/src/plugins/quickReply/index.ts b/src/plugins/quickReply/index.ts index 118a51be..9771445d 100644 --- a/src/plugins/quickReply/index.ts +++ b/src/plugins/quickReply/index.ts @@ -17,7 +17,7 @@ */ import { definePluginSettings, Settings } from "@api/Settings"; -import { Devs } from "@utils/constants"; +import { Devs, isMac } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common"; @@ -25,7 +25,6 @@ import { Message } from "discord-types/general"; const Kangaroo = findByPropsLazy("jumpToMessage"); -const isMac = navigator.platform.includes("Mac"); // bruh let replyIdx = -1; let editIdx = -1; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index aeadcdbf..65d28951 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -389,3 +389,10 @@ export const DevsById = /* #__PURE__*/ (() => .map(([_, v]) => [v.id, v] as const) )) )() as Record; + + +const { platform } = navigator; + +export const isWindows = platform.startsWith("Win"); +export const isMac = platform.startsWith("Mac"); +export const isLinux = platform.startsWith("Linux");