2022-10-21 19:17:06 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
2022-10-23 17:23:52 -04:00
|
|
|
* Copyright (c) 2022 Vendicated and Megumin
|
2022-10-21 19:17:06 -04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2023-04-14 20:27:11 -04:00
|
|
|
import { addContextMenuPatch } from "@api/ContextMenu";
|
2023-05-05 19:36:00 -04:00
|
|
|
import { Settings } from "@api/Settings";
|
2022-11-28 07:37:55 -05:00
|
|
|
import { Devs } from "@utils/constants";
|
2023-05-05 19:36:00 -04:00
|
|
|
import { Logger } from "@utils/Logger";
|
2022-11-30 21:38:17 -05:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2023-05-11 19:40:43 -04:00
|
|
|
import { React, SettingsRouter } from "@webpack/common";
|
2022-10-17 15:18:25 -04:00
|
|
|
|
2022-11-28 07:37:55 -05:00
|
|
|
import gitHash from "~git-hash";
|
2022-08-29 19:42:47 -04:00
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "Settings",
|
|
|
|
description: "Adds Settings UI and debug info",
|
2022-10-17 15:18:25 -04:00
|
|
|
authors: [Devs.Ven, Devs.Megu],
|
2022-08-30 22:07:16 -04:00
|
|
|
required: true,
|
2023-04-14 20:27:11 -04:00
|
|
|
|
|
|
|
start() {
|
|
|
|
// The settings shortcuts in the user settings cog context menu
|
|
|
|
// read the elements from a hardcoded map which for obvious reason
|
|
|
|
// doesn't contain our sections. This patches the actions of our
|
|
|
|
// sections to manually use SettingsRouter (which only works on desktop
|
|
|
|
// but the context menu is usually not available on mobile anyway)
|
2023-04-14 20:47:03 -04:00
|
|
|
addContextMenuPatch("user-settings-cog", children => () => {
|
2023-04-14 20:27:11 -04:00
|
|
|
const section = children.find(c => Array.isArray(c) && c.some(it => it?.props?.id === "VencordSettings")) as any;
|
|
|
|
section?.forEach(c => {
|
|
|
|
if (c?.props?.id?.startsWith("Vencord")) {
|
|
|
|
c.props.action = () => SettingsRouter.open(c.props.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-08-29 19:42:47 -04:00
|
|
|
patches: [{
|
2023-01-06 21:19:28 -05:00
|
|
|
find: ".versionHash",
|
2022-08-29 19:42:47 -04:00
|
|
|
replacement: [
|
|
|
|
{
|
2023-01-06 21:19:28 -05:00
|
|
|
match: /\[\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/,
|
2022-11-10 18:11:44 -05:00
|
|
|
replace: (m, component, props) => {
|
|
|
|
props = props.replace(/children:\[.+\]/, "");
|
|
|
|
return `${m},Vencord.Plugins.plugins.Settings.makeInfoElements(${component}, ${props})`;
|
2022-08-29 19:42:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}, {
|
|
|
|
find: "Messages.ACTIVITY_SETTINGS",
|
|
|
|
replacement: {
|
2022-11-30 21:38:17 -05:00
|
|
|
get match() {
|
|
|
|
switch (Settings.plugins.Settings.settingsLocation) {
|
|
|
|
case "top": return /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.USER_SETTINGS\}/;
|
|
|
|
case "aboveNitro": return /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.BILLING_SETTINGS\}/;
|
|
|
|
case "belowNitro": return /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.APP_SETTINGS\}/;
|
|
|
|
case "aboveActivity": return /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.ACTIVITY_SETTINGS\}/;
|
|
|
|
case "belowActivity": return /(?<=\{section:(.{1,2})\.ID\.DIVIDER},)\{section:"changelog"/;
|
|
|
|
case "bottom": return /\{section:(.{1,2})\.ID\.CUSTOM,\s*element:.+?}/;
|
|
|
|
default: {
|
|
|
|
new Logger("Settings").error(
|
|
|
|
new Error("No switch case matched????? Don't mess with the settings, silly")
|
|
|
|
);
|
|
|
|
// matches nothing
|
|
|
|
return /(?!a)a/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-01-21 22:26:33 -05:00
|
|
|
replace: "...$self.makeSettingsCategories($1),$&"
|
2022-08-29 19:42:47 -04:00
|
|
|
}
|
2022-11-10 18:11:44 -05:00
|
|
|
}],
|
|
|
|
|
2023-01-21 22:26:33 -05:00
|
|
|
makeSettingsCategories({ ID }: { ID: Record<string, unknown>; }) {
|
2023-04-08 22:04:02 -04:00
|
|
|
return [
|
2023-01-21 22:26:33 -05:00
|
|
|
{
|
|
|
|
section: ID.HEADER,
|
|
|
|
label: "Vencord"
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
{
|
2023-01-21 22:26:33 -05:00
|
|
|
section: "VencordSettings",
|
|
|
|
label: "Vencord",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/VencordTab").default
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
{
|
2023-01-21 22:26:33 -05:00
|
|
|
section: "VencordPlugins",
|
|
|
|
label: "Plugins",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/PluginsTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
{
|
2023-01-21 22:26:33 -05:00
|
|
|
section: "VencordThemes",
|
|
|
|
label: "Themes",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/ThemesTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
!IS_WEB && {
|
2023-01-21 22:26:33 -05:00
|
|
|
section: "VencordUpdater",
|
|
|
|
label: "Updater",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/UpdaterTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
section: "VencordCloud",
|
|
|
|
label: "Cloud",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/CloudTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
section: "VencordSettingsSync",
|
|
|
|
label: "Backup & Restore",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/BackupAndRestoreTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
IS_DEV && {
|
2023-01-21 22:26:33 -05:00
|
|
|
section: "VencordPatchHelper",
|
|
|
|
label: "Patch Helper",
|
2023-05-11 19:40:43 -04:00
|
|
|
element: require("@components/VencordSettings/PatchHelperTab").default,
|
2023-04-08 22:04:02 -04:00
|
|
|
},
|
|
|
|
IS_VENCORD_DESKTOP && {
|
|
|
|
section: "VencordDesktop",
|
|
|
|
label: "Desktop Settings",
|
|
|
|
element: VencordDesktop.Components.Settings,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: ID.DIVIDER
|
|
|
|
}
|
|
|
|
].filter(Boolean);
|
2023-01-21 22:26:33 -05:00
|
|
|
},
|
|
|
|
|
2022-11-30 21:38:17 -05:00
|
|
|
options: {
|
|
|
|
settingsLocation: {
|
|
|
|
type: OptionType.SELECT,
|
|
|
|
description: "Where to put the Vencord settings section",
|
|
|
|
options: [
|
|
|
|
{ label: "At the very top", value: "top" },
|
|
|
|
{ label: "Above the Nitro section", value: "aboveNitro" },
|
|
|
|
{ label: "Below the Nitro section", value: "belowNitro" },
|
|
|
|
{ label: "Above Activity Settings", value: "aboveActivity", default: true },
|
|
|
|
{ label: "Below Activity Settings", value: "belowActivity" },
|
|
|
|
{ label: "At the very bottom", value: "bottom" },
|
|
|
|
],
|
|
|
|
restartNeeded: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-11-17 07:49:51 -05:00
|
|
|
get electronVersion() {
|
2023-05-01 20:50:51 -04:00
|
|
|
return VencordNative.native.getVersions().electron || window.armcord?.electron || null;
|
2022-11-17 07:49:51 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
get chromiumVersion() {
|
|
|
|
try {
|
2023-05-01 20:50:51 -04:00
|
|
|
return VencordNative.native.getVersions().chrome
|
2022-11-17 07:49:51 -05:00
|
|
|
// @ts-ignore Typescript will add userAgentData IMMEDIATELY
|
|
|
|
|| navigator.userAgentData?.brands?.find(b => b.brand === "Chromium" || b.brand === "Google Chrome")?.version
|
|
|
|
|| null;
|
|
|
|
} catch { // inb4 some stupid browser throws unsupported error for navigator.userAgentData, it's only in chromium
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get additionalInfo() {
|
|
|
|
if (IS_DEV) return " (Dev)";
|
|
|
|
if (IS_WEB) return " (Web)";
|
2023-04-08 22:04:02 -04:00
|
|
|
if (IS_VENCORD_DESKTOP) return ` (VencordDesktop v${VencordDesktopNative.app.getVersion()})`;
|
2022-11-17 07:49:51 -05:00
|
|
|
if (IS_STANDALONE) return " (Standalone)";
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
2022-11-10 18:11:44 -05:00
|
|
|
makeInfoElements(Component: React.ComponentType<React.PropsWithChildren>, props: React.PropsWithChildren) {
|
2022-11-17 07:49:51 -05:00
|
|
|
const { electronVersion, chromiumVersion, additionalInfo } = this;
|
|
|
|
|
2022-11-10 18:11:44 -05:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Component {...props}>Vencord {gitHash}{additionalInfo}</Component>
|
2022-11-17 07:49:51 -05:00
|
|
|
{electronVersion && <Component {...props}>Electron {electronVersion}</Component>}
|
|
|
|
{chromiumVersion && <Component {...props}>Chromium {chromiumVersion}</Component>}
|
2022-11-10 18:11:44 -05:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2022-09-16 16:59:34 -04:00
|
|
|
});
|