diff options
author | V <vendicated@riseup.net> | 2023-05-02 02:50:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-02 02:50:51 +0200 |
commit | c62d05e1b32361425474928004a92338d98ba200 (patch) | |
tree | 63e2d718807055dbdbbe7d2624270d8aa138fa2d /src/components | |
parent | 6a1cb133cd6cbe2946e4c830291318e873da1d8b (diff) | |
download | Vencord-c62d05e1b32361425474928004a92338d98ba200.tar.gz Vencord-c62d05e1b32361425474928004a92338d98ba200.tar.bz2 Vencord-c62d05e1b32361425474928004a92338d98ba200.zip |
Refactor ipc to be strongly typed and hide impl details (#1018)
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/DonateButton.tsx | 5 | ||||
-rw-r--r-- | src/components/Monaco.ts | 51 | ||||
-rw-r--r-- | src/components/VencordSettings/Updater.tsx | 3 | ||||
-rw-r--r-- | src/components/VencordSettings/VencordTab.tsx | 44 | ||||
-rw-r--r-- | src/components/VencordSettings/settingsStyles.css | 2 |
5 files changed, 22 insertions, 83 deletions
diff --git a/src/components/DonateButton.tsx b/src/components/DonateButton.tsx index 49f079b..c027fcf 100644 --- a/src/components/DonateButton.tsx +++ b/src/components/DonateButton.tsx @@ -16,7 +16,6 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import IpcEvents from "@utils/IpcEvents"; import { Button } from "@webpack/common"; import { Heart } from "./Heart"; @@ -27,9 +26,7 @@ export default function DonateButton(props: any) { {...props} look={Button.Looks.LINK} color={Button.Colors.TRANSPARENT} - onClick={() => - VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated") - } + onClick={() => VencordNative.native.openExternal("https://github.com/sponsors/Vendicated")} > <Heart /> Donate diff --git a/src/components/Monaco.ts b/src/components/Monaco.ts deleted file mode 100644 index 59ed7bb..0000000 --- a/src/components/Monaco.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - -import { debounce } from "@utils/debounce"; -import IpcEvents from "@utils/IpcEvents"; -import { Queue } from "@utils/Queue"; -import { find } from "@webpack"; - -import monacoHtml from "~fileContent/monacoWin.html"; - -const queue = new Queue(); -const setCss = debounce((css: string) => { - queue.push(() => VencordNative.ipc.invoke(IpcEvents.SET_QUICK_CSS, css)); -}); - -export async function launchMonacoEditor() { - const features = `popup,width=${Math.min(window.innerWidth, 1000)},height=${Math.min(window.innerHeight, 1000)}`; - const win = open("about:blank", "VencordQuickCss", features); - if (!win) { - alert("Failed to open QuickCSS popup. Make sure to allow popups!"); - return; - } - - win.setCss = setCss; - win.getCurrentCss = () => VencordNative.ipc.invoke(IpcEvents.GET_QUICK_CSS); - win.getTheme = () => - find(m => - m.ProtoClass?.typeName.endsWith("PreloadedUserSettings") - )?.getCurrentValue()?.appearance?.theme === 2 - ? "vs-light" - : "vs-dark"; - - win.document.write(monacoHtml); - - window.__VENCORD_MONACO_WIN__ = new WeakRef(win); -} diff --git a/src/components/VencordSettings/Updater.tsx b/src/components/VencordSettings/Updater.tsx index 6dffbc8..fb78394 100644 --- a/src/components/VencordSettings/Updater.tsx +++ b/src/components/VencordSettings/Updater.tsx @@ -25,7 +25,7 @@ import { Link } from "@components/Link"; import { Margins } from "@utils/margins"; import { classes, useAwaiter } from "@utils/misc"; import { relaunch } from "@utils/native"; -import { changes, checkForUpdates, getRepo, isNewer, rebuild, update, updateError, UpdateLogger } from "@utils/updater"; +import { changes, checkForUpdates, getRepo, isNewer, update, updateError, UpdateLogger } from "@utils/updater"; import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common"; import gitHash from "~git-hash"; @@ -125,7 +125,6 @@ function Updatable(props: CommonProps) { onClick={withDispatcher(setIsUpdating, async () => { if (await update()) { setUpdates([]); - await rebuild(); await new Promise<void>(r => { Alerts.show({ title: "Update Success!", diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 7512208..672e04e 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -23,7 +23,6 @@ import { classNameFactory } from "@api/Styles"; import DonateButton from "@components/DonateButton"; import ErrorBoundary from "@components/ErrorBoundary"; import { ErrorCard } from "@components/ErrorCard"; -import IpcEvents from "@utils/IpcEvents"; import { Margins } from "@utils/margins"; import { identity, useAwaiter } from "@utils/misc"; import { relaunch, showItemInFolder } from "@utils/native"; @@ -39,7 +38,7 @@ type KeysOfType<Object, Type> = { }[keyof Object]; function VencordSettings() { - const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), { + const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, { fallbackValue: "Loading..." }); const settings = useSettings(); @@ -101,40 +100,35 @@ function VencordSettings() { <DonateCard image={donateImage} /> <Forms.FormSection title="Quick Actions"> <Card className={cl("quick-actions-card")}> - {IS_WEB ? ( - <Button - onClick={() => require("../Monaco").launchMonacoEditor()} - size={Button.Sizes.SMALL} - disabled={settingsDir === "Loading..."}> - Open QuickCSS File - </Button> - ) : ( - <React.Fragment> + <React.Fragment> + {!IS_WEB && ( <Button onClick={relaunch} size={Button.Sizes.SMALL}> Restart Client </Button> - <Button - onClick={() => VencordNative.ipc.invoke(IpcEvents.OPEN_MONACO_EDITOR)} - size={Button.Sizes.SMALL} - disabled={settingsDir === "Loading..."}> - Open QuickCSS File - </Button> + )} + <Button + onClick={() => VencordNative.quickCss.openEditor()} + size={Button.Sizes.SMALL} + disabled={settingsDir === "Loading..."}> + Open QuickCSS File + </Button> + {!IS_WEB && ( <Button onClick={() => showItemInFolder(settingsDir)} size={Button.Sizes.SMALL} disabled={settingsDirPending}> Open Settings Folder </Button> - <Button - onClick={() => VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/Vendicated/Vencord")} - size={Button.Sizes.SMALL} - disabled={settingsDirPending}> - Open in GitHub - </Button> - </React.Fragment> - )} + )} + <Button + onClick={() => VencordNative.native.openExternal("https://github.com/Vendicated/Vencord")} + size={Button.Sizes.SMALL} + disabled={settingsDirPending}> + Open in GitHub + </Button> + </React.Fragment> </Card> </Forms.FormSection> diff --git a/src/components/VencordSettings/settingsStyles.css b/src/components/VencordSettings/settingsStyles.css index c25022a..3652756 100644 --- a/src/components/VencordSettings/settingsStyles.css +++ b/src/components/VencordSettings/settingsStyles.css @@ -15,7 +15,7 @@ display: flex; gap: 1em; align-items: center; - justify-content: space-between; + justify-content: space-evenly; flex-grow: 1; flex-flow: row wrap; margin-bottom: 1em; |