Compare commits
1 commit
main
...
specific-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6410e63734 |
5 changed files with 110 additions and 37 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
import type { Settings } from "@api/Settings";
|
import type { Settings } from "@api/Settings";
|
||||||
import type { CspRequestResult } from "@main/csp/manager";
|
import type { CspRequestResult } from "@main/csp/manager";
|
||||||
import type { PluginIpcMappings } from "@main/ipcPlugins";
|
import type { PluginIpcMappings } from "@main/ipcPlugins";
|
||||||
|
import { NativeSettings } from "@main/settings";
|
||||||
import { UserThemeHeader } from "@main/themes";
|
import { UserThemeHeader } from "@main/themes";
|
||||||
import { IpcEvents } from "@shared/IpcEvents";
|
import { IpcEvents } from "@shared/IpcEvents";
|
||||||
import type { IpcRes } from "@utils/types";
|
import type { IpcRes } from "@utils/types";
|
||||||
|
|
@ -57,6 +58,9 @@ export default {
|
||||||
set: (settings: Settings, pathToNotify?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, pathToNotify),
|
set: (settings: Settings, pathToNotify?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, pathToNotify),
|
||||||
getSettingsDir: () => invoke<string>(IpcEvents.GET_SETTINGS_DIR),
|
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),
|
openFolder: () => invoke<void>(IpcEvents.OPEN_SETTINGS_FOLDER),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { classNameFactory } from "@utils/css";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { isAnyPluginDev } from "@utils/misc";
|
import { isAnyPluginDev } from "@utils/misc";
|
||||||
import { relaunch } from "@utils/native";
|
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 { DonateButtonComponent } from "./DonateButton";
|
||||||
import { MacOSVibrancySettings } from "./MacVibrancySettings";
|
import { MacOSVibrancySettings } from "./MacVibrancySettings";
|
||||||
|
|
@ -48,8 +48,20 @@ type KeysOfType<Object, Type> = {
|
||||||
[K in keyof Object]: Object[K] extends Type ? K : never;
|
[K in keyof Object]: Object[K] extends Type ? K : never;
|
||||||
}[keyof Object];
|
}[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() {
|
function Switches() {
|
||||||
const settings = useSettings(["useQuickCss", "enableReactDevtools", "mainWindowFrameless", "frameless", "winNativeTitleBar", "transparent", "winCtrlQ", "disableMinSize"]);
|
const settings = useSettings(["useQuickCss", "enableReactDevtools", "mainWindowFrameless", "frameless", "winNativeTitleBar", "transparent", "winCtrlQ", "disableMinSize"]);
|
||||||
|
const [separateSettings, setSeparateSettings] = useSeparateSettings();
|
||||||
|
|
||||||
const Switches = [
|
const Switches = [
|
||||||
{
|
{
|
||||||
|
|
@ -112,34 +124,58 @@ function Switches() {
|
||||||
warning?: string;
|
warning?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
return Switches.map(setting => {
|
return (
|
||||||
if (!setting) {
|
<>
|
||||||
return null;
|
{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
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
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({
|
Alerts.show({
|
||||||
title: "Restart Required",
|
title: "Restart Required",
|
||||||
body: "A restart is required to apply this change",
|
body: "A restart is required to apply this change",
|
||||||
|
|
@ -147,12 +183,12 @@ function Switches() {
|
||||||
cancelText: "Later!",
|
cancelText: "Later!",
|
||||||
onConfirm: relaunch
|
onConfirm: relaunch
|
||||||
});
|
});
|
||||||
}
|
}}
|
||||||
}}
|
hideBorder
|
||||||
hideBorder
|
/>
|
||||||
/>
|
)}
|
||||||
);
|
</>
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function EquicordSettings() {
|
function EquicordSettings() {
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,13 @@ export interface NativeSettings {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
customCspRules: Record<string, string[]>;
|
customCspRules: Record<string, string[]>;
|
||||||
|
separateSettings?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultNativeSettings: NativeSettings = {
|
const DefaultNativeSettings: NativeSettings = {
|
||||||
plugins: {},
|
plugins: {},
|
||||||
customCspRules: {}
|
customCspRules: {},
|
||||||
|
separateSettings: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const nativeSettings = readSettings<NativeSettings>("native", NATIVE_SETTINGS_FILE);
|
const nativeSettings = readSettings<NativeSettings>("native", NATIVE_SETTINGS_FILE);
|
||||||
|
|
@ -69,3 +71,9 @@ NativeSettings.addGlobalChangeListener(() => {
|
||||||
console.error("Failed to write native settings", e);
|
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 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 NATIVE_SETTINGS_FILE = join(SETTINGS_DIR, "native-settings.json");
|
||||||
export const DEV_MIGRATED = join(SETTINGS_DIR, "migration");
|
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 = [
|
export const ALLOWED_PROTOCOLS = [
|
||||||
"https:",
|
"https:",
|
||||||
"http:",
|
"http:",
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,7 @@ export const enum IpcEvents {
|
||||||
TRAY_CHECK_UPDATES = "VencordTrayCheckUpdates",
|
TRAY_CHECK_UPDATES = "VencordTrayCheckUpdates",
|
||||||
TRAY_ABOUT = "VencordTrayAbout",
|
TRAY_ABOUT = "VencordTrayAbout",
|
||||||
SUPPORTS_WINDOWS_MATERIAL = "VencordSupportsWindowsMaterial",
|
SUPPORTS_WINDOWS_MATERIAL = "VencordSupportsWindowsMaterial",
|
||||||
|
|
||||||
|
GET_NATIVE_SETTINGS = "VencordGetNativeSettings",
|
||||||
|
SET_NATIVE_SETTINGS = "VencordSetNativeSettings",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue