From 5b471e41ffd3cbe90573a98eb0e5bd4ec707553d Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 13 Mar 2024 21:59:09 +0100 Subject: [PATCH] refactor shared utils to more obviously separate contexts --- src/VencordNative.ts | 2 +- src/api/Settings.ts | 2 +- src/components/VencordSettings/PatchHelperTab.tsx | 2 +- src/main/ipcMain.ts | 4 ++-- src/main/ipcPlugins.ts | 2 +- src/main/patcher.ts | 2 +- src/main/settings.ts | 2 +- src/main/updater/git.ts | 2 +- src/main/updater/http.ts | 4 ++-- .../decor/lib/stores/UsersDecorationsStore.ts | 2 +- src/plugins/imageZoom/index.tsx | 2 +- src/plugins/pinDms/index.tsx | 2 +- src/plugins/pronoundb/pronoundbUtils.ts | 4 ++-- src/plugins/spotifyControls/PlayerComponent.tsx | 2 +- src/preload.ts | 2 +- src/{utils => shared}/IpcEvents.ts | 0 src/{utils => shared}/debounce.ts | 0 src/{utils => shared}/onceDefined.ts | 0 src/shared/vencordUserAgent.ts | 12 ++++++++++++ src/utils/constants.ts | 13 ------------- src/utils/index.ts | 4 ++-- 21 files changed, 32 insertions(+), 33 deletions(-) rename src/{utils => shared}/IpcEvents.ts (100%) rename src/{utils => shared}/debounce.ts (100%) rename src/{utils => shared}/onceDefined.ts (100%) create mode 100644 src/shared/vencordUserAgent.ts diff --git a/src/VencordNative.ts b/src/VencordNative.ts index 10381c900..42e697452 100644 --- a/src/VencordNative.ts +++ b/src/VencordNative.ts @@ -6,7 +6,7 @@ import { PluginIpcMappings } from "@main/ipcPlugins"; import type { UserThemeHeader } from "@main/themes"; -import { IpcEvents } from "@utils/IpcEvents"; +import { IpcEvents } from "@shared/IpcEvents"; import { IpcRes } from "@utils/types"; import type { Settings } from "api/Settings"; import { ipcRenderer } from "electron"; diff --git a/src/api/Settings.ts b/src/api/Settings.ts index bd4a4e929..0b7975300 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -16,8 +16,8 @@ * along with this program. If not, see . */ +import { debounce } from "@shared/debounce"; import { SettingsStore as SettingsStoreClass } from "@shared/SettingsStore"; -import { debounce } from "@utils/debounce"; import { localStorage } from "@utils/localStorage"; import { Logger } from "@utils/Logger"; import { mergeDefaults } from "@utils/misc"; diff --git a/src/components/VencordSettings/PatchHelperTab.tsx b/src/components/VencordSettings/PatchHelperTab.tsx index 35f46ef50..7e68ec1e7 100644 --- a/src/components/VencordSettings/PatchHelperTab.tsx +++ b/src/components/VencordSettings/PatchHelperTab.tsx @@ -18,7 +18,7 @@ import { CheckedTextInput } from "@components/CheckedTextInput"; import { CodeBlock } from "@components/CodeBlock"; -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; import { Margins } from "@utils/margins"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; import { makeCodeblock } from "@utils/text"; diff --git a/src/main/ipcMain.ts b/src/main/ipcMain.ts index 609a581a7..9c9741db5 100644 --- a/src/main/ipcMain.ts +++ b/src/main/ipcMain.ts @@ -20,8 +20,8 @@ import "./updater"; import "./ipcPlugins"; import "./settings"; -import { debounce } from "@utils/debounce"; -import { IpcEvents } from "@utils/IpcEvents"; +import { debounce } from "@shared/debounce"; +import { IpcEvents } from "@shared/IpcEvents"; import { BrowserWindow, ipcMain, shell, systemPreferences } from "electron"; import { FSWatcher, mkdirSync, watch, writeFileSync } from "fs"; import { open, readdir, readFile } from "fs/promises"; diff --git a/src/main/ipcPlugins.ts b/src/main/ipcPlugins.ts index 5d679fc0b..5236dbec4 100644 --- a/src/main/ipcPlugins.ts +++ b/src/main/ipcPlugins.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { IpcEvents } from "@utils/IpcEvents"; +import { IpcEvents } from "@shared/IpcEvents"; import { ipcMain } from "electron"; import PluginNatives from "~pluginNatives"; diff --git a/src/main/patcher.ts b/src/main/patcher.ts index ff63ec82d..0d79a96f6 100644 --- a/src/main/patcher.ts +++ b/src/main/patcher.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { onceDefined } from "@utils/onceDefined"; +import { onceDefined } from "@shared/onceDefined"; import electron, { app, BrowserWindowConstructorOptions, Menu } from "electron"; import { dirname, join } from "path"; diff --git a/src/main/settings.ts b/src/main/settings.ts index 6fe2c3be7..96efdd672 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -5,8 +5,8 @@ */ import type { Settings } from "@api/Settings"; +import { IpcEvents } from "@shared/IpcEvents"; import { SettingsStore } from "@shared/SettingsStore"; -import { IpcEvents } from "@utils/IpcEvents"; import { ipcMain } from "electron"; import { mkdirSync, readFileSync, writeFileSync } from "fs"; diff --git a/src/main/updater/git.ts b/src/main/updater/git.ts index 20a5d7003..82c38b6bc 100644 --- a/src/main/updater/git.ts +++ b/src/main/updater/git.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { IpcEvents } from "@utils/IpcEvents"; +import { IpcEvents } from "@shared/IpcEvents"; import { execFile as cpExecFile } from "child_process"; import { ipcMain } from "electron"; import { join } from "path"; diff --git a/src/main/updater/http.ts b/src/main/updater/http.ts index 605e8d7cf..9e5a1cef4 100644 --- a/src/main/updater/http.ts +++ b/src/main/updater/http.ts @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { VENCORD_USER_AGENT } from "@utils/constants"; -import { IpcEvents } from "@utils/IpcEvents"; +import { IpcEvents } from "@shared/IpcEvents"; +import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { ipcMain } from "electron"; import { writeFile } from "fs/promises"; import { join } from "path"; diff --git a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts index 7295a3b17..b29945f82 100644 --- a/src/plugins/decor/lib/stores/UsersDecorationsStore.ts +++ b/src/plugins/decor/lib/stores/UsersDecorationsStore.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; import { proxyLazy } from "@utils/lazy"; import { useEffect, useState, zustandCreate } from "@webpack/common"; import { User } from "discord-types/general"; diff --git a/src/plugins/imageZoom/index.tsx b/src/plugins/imageZoom/index.tsx index 048c0ed5b..cbaa07d2a 100644 --- a/src/plugins/imageZoom/index.tsx +++ b/src/plugins/imageZoom/index.tsx @@ -20,8 +20,8 @@ import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { definePluginSettings } from "@api/Settings"; import { disableStyle, enableStyle } from "@api/Styles"; import { makeRange } from "@components/PluginSettings/components"; +import { debounce } from "@shared/debounce"; import { Devs } from "@utils/constants"; -import { debounce } from "@utils/debounce"; import definePlugin, { OptionType } from "@utils/types"; import { Menu, React, ReactDOM } from "@webpack/common"; import type { Root } from "react-dom/client"; diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index 943f0f1b1..45172328e 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -26,7 +26,7 @@ import { getPinAt, isPinned, settings, snapshotArray, sortedSnapshot, usePinnedD export default definePlugin({ name: "PinDMs", description: "Allows you to pin private channels to the top of your DM list. To pin/unpin or reorder pins, right click DMs", - authors: [Devs.Ven, Devs.Strencher], + authors: [Devs.Ven], settings, contextMenus, diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts index eac204b7d..6373c56a0 100644 --- a/src/plugins/pronoundb/pronoundbUtils.ts +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -17,8 +17,8 @@ */ import { Settings } from "@api/Settings"; -import { VENCORD_USER_AGENT } from "@utils/constants"; -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; +import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { getCurrentChannel } from "@utils/discord"; import { useAwaiter } from "@utils/react"; import { UserProfileStore, UserStore } from "@webpack/common"; diff --git a/src/plugins/spotifyControls/PlayerComponent.tsx b/src/plugins/spotifyControls/PlayerComponent.tsx index 8b3f04bf2..ae28631c9 100644 --- a/src/plugins/spotifyControls/PlayerComponent.tsx +++ b/src/plugins/spotifyControls/PlayerComponent.tsx @@ -21,7 +21,7 @@ import "./spotifyStyles.css"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons"; -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; import { openImageModal } from "@utils/discord"; import { classes, copyWithToast } from "@utils/misc"; import { ContextMenuApi, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common"; diff --git a/src/preload.ts b/src/preload.ts index 08243000d..e79eb02cc 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { debounce } from "@utils/debounce"; +import { debounce } from "@shared/debounce"; import { contextBridge, webFrame } from "electron"; import { readFileSync, watch } from "fs"; import { join } from "path"; diff --git a/src/utils/IpcEvents.ts b/src/shared/IpcEvents.ts similarity index 100% rename from src/utils/IpcEvents.ts rename to src/shared/IpcEvents.ts diff --git a/src/utils/debounce.ts b/src/shared/debounce.ts similarity index 100% rename from src/utils/debounce.ts rename to src/shared/debounce.ts diff --git a/src/utils/onceDefined.ts b/src/shared/onceDefined.ts similarity index 100% rename from src/utils/onceDefined.ts rename to src/shared/onceDefined.ts diff --git a/src/shared/vencordUserAgent.ts b/src/shared/vencordUserAgent.ts new file mode 100644 index 000000000..0cb1882bf --- /dev/null +++ b/src/shared/vencordUserAgent.ts @@ -0,0 +1,12 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import gitHash from "~git-hash"; +import gitRemote from "~git-remote"; + +export { gitHash, gitRemote }; + +export const VENCORD_USER_AGENT = `Vencord/${gitHash}${gitRemote ? ` (https://github.com/${gitRemote})` : ""}`; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 40965d08c..f609fa644 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -16,17 +16,8 @@ * along with this program. If not, see . */ -import gitHash from "~git-hash"; -import gitRemote from "~git-remote"; - -export { - gitHash, - gitRemote -}; - export const WEBPACK_CHUNK = "webpackChunkdiscord_app"; export const REACT_GLOBAL = "Vencord.Webpack.Common.React"; -export const VENCORD_USER_AGENT = `Vencord/${gitHash}${gitRemote ? ` (https://github.com/${gitRemote})` : ""}`; export const SUPPORT_CHANNEL_ID = "1026515880080842772"; export interface Dev { @@ -291,10 +282,6 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RyanCaoDev", id: 952235800110694471n, }, - Strencher: { - name: "Strencher", - id: 415849376598982656n - }, FieryFlames: { name: "Fiery", id: 890228870559698955n diff --git a/src/utils/index.ts b/src/utils/index.ts index 90bf86082..ea4adce4a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -16,9 +16,10 @@ * along with this program. If not, see . */ +export * from "../shared/debounce"; +export * from "../shared/onceDefined"; export * from "./ChangeList"; export * from "./constants"; -export * from "./debounce"; export * from "./discord"; export * from "./guards"; export * from "./lazy"; @@ -27,7 +28,6 @@ export * from "./Logger"; export * from "./margins"; export * from "./misc"; export * from "./modal"; -export * from "./onceDefined"; export * from "./onlyOnce"; export * from "./patches"; export * from "./Queue";