diff --git a/src/VencordNative.ts b/src/VencordNative.ts index a5ca42366..81258d7b7 100644 --- a/src/VencordNative.ts +++ b/src/VencordNative.ts @@ -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(IpcEvents.SET_SETTINGS, settings, pathToNotify), getSettingsDir: () => invoke(IpcEvents.GET_SETTINGS_DIR), + getNative: () => sendSync(IpcEvents.GET_NATIVE_SETTINGS), + setNative: (settings: NativeSettings) => invoke(IpcEvents.SET_NATIVE_SETTINGS, settings), + openFolder: () => invoke(IpcEvents.OPEN_SETTINGS_FOLDER), }, diff --git a/src/components/settings/tabs/vencord/index.tsx b/src/components/settings/tabs/vencord/index.tsx index 756945d24..ac5fed911 100644 --- a/src/components/settings/tabs/vencord/index.tsx +++ b/src/components/settings/tabs/vencord/index.tsx @@ -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 = { [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 ( - - {description} - - {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 ( + + {description} + + {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 && ( + { + 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() { diff --git a/src/main/settings.ts b/src/main/settings.ts index ed2f48500..fdaba10bb 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -50,11 +50,13 @@ export interface NativeSettings { }; }; customCspRules: Record; + separateSettings?: boolean; } const DefaultNativeSettings: NativeSettings = { plugins: {}, - customCspRules: {} + customCspRules: {}, + separateSettings: false }; const nativeSettings = readSettings("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); +}); diff --git a/src/main/utils/constants.ts b/src/main/utils/constants.ts index 6b28f8339..4238aa7e6 100644 --- a/src/main/utils/constants.ts +++ b/src/main/utils/constants.ts @@ -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:", diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index e1927d735..8d9ce5ee7 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -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", }