This commit is contained in:
parent
a35bd1a9f8
commit
6410e63734
5 changed files with 110 additions and 37 deletions
|
|
@ -7,6 +7,7 @@
|
|||
import type { Settings } from "@api/Settings";
|
||||
import type { CspRequestResult } from "@main/csp/manager";
|
||||
import type { PluginIpcMappings } from "@main/ipcPlugins";
|
||||
import { NativeSettings } from "@main/settings";
|
||||
import { UserThemeHeader } from "@main/themes";
|
||||
import { IpcEvents } from "@shared/IpcEvents";
|
||||
import type { IpcRes } from "@utils/types";
|
||||
|
|
@ -57,6 +58,9 @@ export default {
|
|||
set: (settings: Settings, pathToNotify?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, pathToNotify),
|
||||
getSettingsDir: () => invoke<string>(IpcEvents.GET_SETTINGS_DIR),
|
||||
|
||||
getNative: () => sendSync<NativeSettings>(IpcEvents.GET_NATIVE_SETTINGS),
|
||||
setNative: (settings: NativeSettings) => invoke<void>(IpcEvents.SET_NATIVE_SETTINGS, settings),
|
||||
|
||||
openFolder: () => invoke<void>(IpcEvents.OPEN_SETTINGS_FOLDER),
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import { classNameFactory } from "@utils/css";
|
|||
import { Margins } from "@utils/margins";
|
||||
import { isAnyPluginDev } from "@utils/misc";
|
||||
import { relaunch } from "@utils/native";
|
||||
import { Alerts, GuildMemberStore, React, useMemo, UserStore } from "@webpack/common";
|
||||
import { Alerts, GuildMemberStore, React, useMemo, UserStore, useState } from "@webpack/common";
|
||||
|
||||
import { DonateButtonComponent } from "./DonateButton";
|
||||
import { MacOSVibrancySettings } from "./MacVibrancySettings";
|
||||
|
|
@ -48,8 +48,20 @@ type KeysOfType<Object, Type> = {
|
|||
[K in keyof Object]: Object[K] extends Type ? K : never;
|
||||
}[keyof Object];
|
||||
|
||||
function useSeparateSettings() {
|
||||
const [value, setValue] = useState(() => VencordNative.settings.getNative().separateSettings ?? false);
|
||||
|
||||
return [value, (v: boolean) => {
|
||||
const native = VencordNative.settings.getNative();
|
||||
native.separateSettings = v;
|
||||
VencordNative.settings.setNative(native);
|
||||
setValue(v);
|
||||
}] as const;
|
||||
}
|
||||
|
||||
function Switches() {
|
||||
const settings = useSettings(["useQuickCss", "enableReactDevtools", "mainWindowFrameless", "frameless", "winNativeTitleBar", "transparent", "winCtrlQ", "disableMinSize"]);
|
||||
const [separateSettings, setSeparateSettings] = useSeparateSettings();
|
||||
|
||||
const Switches = [
|
||||
{
|
||||
|
|
@ -112,34 +124,58 @@ function Switches() {
|
|||
warning?: string;
|
||||
}>;
|
||||
|
||||
return Switches.map(setting => {
|
||||
if (!setting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { key, title, description, restartRequired, warning } = setting;
|
||||
|
||||
return (
|
||||
<FormSwitch
|
||||
key={key}
|
||||
title={title}
|
||||
description={
|
||||
warning ? (
|
||||
<>
|
||||
{description}
|
||||
<Notice.Warning className={Margins.top8} style={{ width: "100%" }}>
|
||||
{warning}
|
||||
</Notice.Warning>
|
||||
</>
|
||||
) : (
|
||||
description
|
||||
)
|
||||
return (
|
||||
<>
|
||||
{Switches.map(setting => {
|
||||
if (!setting) {
|
||||
return null;
|
||||
}
|
||||
value={settings[key]}
|
||||
onChange={v => {
|
||||
settings[key] = v;
|
||||
|
||||
if (restartRequired) {
|
||||
const { key, title, description, restartRequired, warning } = setting;
|
||||
|
||||
return (
|
||||
<FormSwitch
|
||||
key={key}
|
||||
title={title}
|
||||
description={
|
||||
warning ? (
|
||||
<>
|
||||
{description}
|
||||
<Notice.Warning className={Margins.top8} style={{ width: "100%" }}>
|
||||
{warning}
|
||||
</Notice.Warning>
|
||||
</>
|
||||
) : (
|
||||
description
|
||||
)
|
||||
}
|
||||
value={settings[key]}
|
||||
onChange={v => {
|
||||
settings[key] = v;
|
||||
|
||||
if (restartRequired) {
|
||||
Alerts.show({
|
||||
title: "Restart Required",
|
||||
body: "A restart is required to apply this change",
|
||||
confirmText: "Restart now",
|
||||
cancelText: "Later!",
|
||||
onConfirm: relaunch
|
||||
});
|
||||
}
|
||||
}}
|
||||
hideBorder
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{!IS_WEB && (
|
||||
<FormSwitch
|
||||
key="separateSettings"
|
||||
title="Separate Settings Files"
|
||||
description="Keep separate settings for each Discord branch (Stable, PTB, Canary, Development)."
|
||||
value={separateSettings}
|
||||
onChange={v => {
|
||||
setSeparateSettings(v);
|
||||
|
||||
Alerts.show({
|
||||
title: "Restart Required",
|
||||
body: "A restart is required to apply this change",
|
||||
|
|
@ -147,12 +183,12 @@ function Switches() {
|
|||
cancelText: "Later!",
|
||||
onConfirm: relaunch
|
||||
});
|
||||
}
|
||||
}}
|
||||
hideBorder
|
||||
/>
|
||||
);
|
||||
});
|
||||
}}
|
||||
hideBorder
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function EquicordSettings() {
|
||||
|
|
|
|||
|
|
@ -50,11 +50,13 @@ export interface NativeSettings {
|
|||
};
|
||||
};
|
||||
customCspRules: Record<string, string[]>;
|
||||
separateSettings?: boolean;
|
||||
}
|
||||
|
||||
const DefaultNativeSettings: NativeSettings = {
|
||||
plugins: {},
|
||||
customCspRules: {}
|
||||
customCspRules: {},
|
||||
separateSettings: false
|
||||
};
|
||||
|
||||
const nativeSettings = readSettings<NativeSettings>("native", NATIVE_SETTINGS_FILE);
|
||||
|
|
@ -69,3 +71,9 @@ NativeSettings.addGlobalChangeListener(() => {
|
|||
console.error("Failed to write native settings", e);
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(IpcEvents.GET_NATIVE_SETTINGS, e => e.returnValue = NativeSettings.plain);
|
||||
|
||||
ipcMain.handle(IpcEvents.SET_NATIVE_SETTINGS, (_, data: NativeSettings) => {
|
||||
NativeSettings.setData(data);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,11 +29,33 @@ export const DATA_DIR = process.env.EQUICORD_USER_DATA_DIR ?? (
|
|||
);
|
||||
|
||||
export const SETTINGS_DIR = join(DATA_DIR, "settings");
|
||||
export const THEMES_DIR = join(DATA_DIR, "themes");
|
||||
export const QUICK_CSS_PATH = join(SETTINGS_DIR, "quickCss.css");
|
||||
export const SETTINGS_FILE = join(SETTINGS_DIR, "settings.json");
|
||||
export const NATIVE_SETTINGS_FILE = join(SETTINGS_DIR, "native-settings.json");
|
||||
export const DEV_MIGRATED = join(SETTINGS_DIR, "migration");
|
||||
|
||||
function getBranchName(): string {
|
||||
const name = app.getName().toLowerCase();
|
||||
if (name.includes("canary")) return "canary";
|
||||
if (name.includes("ptb")) return "ptb";
|
||||
if (name.includes("development")) return "dev";
|
||||
return "stable";
|
||||
}
|
||||
|
||||
function isSeparateSettingsEnabled(): boolean {
|
||||
try {
|
||||
if (!existsSync(NATIVE_SETTINGS_FILE)) return false;
|
||||
const parsed = JSON.parse(readFileSync(NATIVE_SETTINGS_FILE, "utf-8"));
|
||||
return !!parsed?.separateSettings;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const BRANCH_DIR = isSeparateSettingsEnabled() ? join(DATA_DIR, getBranchName()) : DATA_DIR;
|
||||
|
||||
export const THEMES_DIR = join(BRANCH_DIR, "themes");
|
||||
export const QUICK_CSS_PATH = join(BRANCH_DIR, "settings", "quickCss.css");
|
||||
export const SETTINGS_FILE = join(BRANCH_DIR, "settings", "settings.json");
|
||||
|
||||
export const ALLOWED_PROTOCOLS = [
|
||||
"https:",
|
||||
"http:",
|
||||
|
|
|
|||
|
|
@ -56,4 +56,7 @@ export const enum IpcEvents {
|
|||
TRAY_CHECK_UPDATES = "VencordTrayCheckUpdates",
|
||||
TRAY_ABOUT = "VencordTrayAbout",
|
||||
SUPPORTS_WINDOWS_MATERIAL = "VencordSupportsWindowsMaterial",
|
||||
|
||||
GET_NATIVE_SETTINGS = "VencordGetNativeSettings",
|
||||
SET_NATIVE_SETTINGS = "VencordSetNativeSettings",
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue