Migrate to @vencord/types package

This commit is contained in:
Vendicated
2023-04-19 22:47:47 +02:00
parent 427fde27ad
commit 0aaddf24c6
10 changed files with 130 additions and 46 deletions

2
src/globals.d.ts vendored
View File

@@ -7,8 +7,6 @@
declare global {
export var VencordDesktopNative: typeof import("preload/VencordDesktopNative").VencordDesktopNative;
export var VencordDesktop: typeof import("renderer/index");
// TODO
export var Vencord: any;
export var vcdLS: typeof localStorage;
export var IS_DEV: boolean;

View File

@@ -6,20 +6,12 @@
import "./settings.css";
import { Margins } from "@vencord/types/utils";
import { Button, Forms, Select, Switch, Text } from "@vencord/types/webpack/common";
import { useSettings } from "renderer/settings";
import { Common, Util } from "../vencord";
const { Margins } = Util;
export default function SettingsUi() {
const Settings = useSettings();
const {
Forms: { FormSection, FormText, FormDivider, FormSwitch, FormTitle },
Text,
Select,
Button
} = Common;
const switches: [keyof typeof Settings, string, string, boolean?, (() => boolean)?][] = [
["tray", "Tray Icon", "Add a tray icon for Vencord Desktop", true],
@@ -43,12 +35,12 @@ export default function SettingsUi() {
];
return (
<FormSection>
<Forms.FormSection>
<Text variant="heading-lg/semibold" style={{ color: "var(--header-primary)" }} tag="h2">
Vencord Desktop Settings
</Text>
<FormTitle className={Margins.top16}>Discord Branch</FormTitle>
<Forms.FormTitle className={Margins.top16}>Discord Branch</Forms.FormTitle>
<Select
placeholder="Stable"
options={[
@@ -62,22 +54,22 @@ export default function SettingsUi() {
serialize={s => s}
/>
<FormDivider className={Margins.top16 + " " + Margins.bottom16} />
<Forms.FormDivider className={Margins.top16 + " " + Margins.bottom16} />
{switches.map(([key, text, note, def, predicate]) => (
<FormSwitch
value={(Settings[key] ?? def ?? false) && (!predicate || predicate())}
<Switch
value={(Settings[key as any] ?? def ?? false) && predicate?.() !== false}
disabled={predicate && !predicate()}
onChange={v => (Settings[key] = v)}
onChange={v => (Settings[key as any] = v)}
note={note}
key={key}
>
{text}
</FormSwitch>
</Switch>
))}
<FormTitle>Vencord Location</FormTitle>
<FormText>
<Forms.FormTitle>Vencord Location</Forms.FormTitle>
<Forms.FormText>
Vencord files are loaded from{" "}
{Settings.vencordDir ? (
<a
@@ -92,7 +84,7 @@ export default function SettingsUi() {
) : (
"the default location"
)}
</FormText>
</Forms.FormText>
<div className="vcd-location-btns">
<Button
size={Button.Sizes.SMALL}
@@ -117,6 +109,6 @@ export default function SettingsUi() {
Reset
</Button>
</div>
</FormSection>
</Forms.FormSection>
);
}

View File

@@ -6,6 +6,8 @@
import "./hideGarbage.css";
import { waitFor } from "@vencord/types/webpack";
import { isFirstRun, localStorage } from "./utils";
// Make clicking Notifications focus the window
@@ -25,7 +27,7 @@ if (isFirstRun) {
// Hide "Download Discord Desktop now!!!!" banner
localStorage.setItem("hideNag", "true");
Vencord.Webpack.waitFor("setDesktopType", m => {
waitFor("setDesktopType", m => {
m.setDesktopType("all");
});
}

View File

@@ -4,17 +4,16 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { useEffect, useReducer } from "@vencord/types/webpack/common";
import { SettingsStore } from "shared/utils/SettingsStore";
import { Common } from "./vencord";
export const Settings = new SettingsStore(VencordDesktopNative.settings.get());
Settings.addGlobalChangeListener((o, p) => VencordDesktopNative.settings.set(o, p));
export function useSettings() {
const [, update] = Common.React.useReducer(x => x + 1, 0);
const [, update] = useReducer(x => x + 1, 0);
Common.React.useEffect(() => {
useEffect(() => {
Settings.addGlobalChangeListener(update);
return () => Settings.removeGlobalChangeListener(update);

View File

@@ -1,13 +0,0 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
// FIXME: this is terrible
const { Webpack, Plugins, Util } = Vencord;
const { Common } = Webpack;
const { plugins } = Plugins;
export { Common, Plugins, plugins, Util, Webpack };