diff options
author | Nickyux <30734036+nmsturcke@users.noreply.github.com> | 2022-11-21 19:37:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 19:37:16 +0100 |
commit | 3ee41852243484223cfdc12022c4343ce8f367df (patch) | |
tree | d608fd5701ad1785253cd72b64db5fbf12cd7d98 | |
parent | 9831c8d6dadc510302d917015c875944d32dc858 (diff) | |
parent | b5bc88c7d441f8d24df70419d7e8e77eaa7f284e (diff) | |
download | Vencord-3ee41852243484223cfdc12022c4343ce8f367df.tar.gz Vencord-3ee41852243484223cfdc12022c4343ce8f367df.tar.bz2 Vencord-3ee41852243484223cfdc12022c4343ce8f367df.zip |
Merge branch 'main' into patch-5
-rwxr-xr-x | scripts/build/buildWeb.mjs | 2 | ||||
-rw-r--r-- | src/components/PluginSettings/index.tsx | 3 | ||||
-rw-r--r-- | src/components/Settings.tsx | 18 | ||||
-rw-r--r-- | src/plugins/TimeBarAllActivities.ts | 35 | ||||
-rw-r--r-- | src/plugins/arRPC.tsx | 106 | ||||
-rw-r--r-- | src/plugins/fakeNitro.ts | 12 | ||||
-rw-r--r-- | src/plugins/noUnblockToJump.ts | 50 | ||||
-rw-r--r-- | src/plugins/oneko.ts | 40 | ||||
-rw-r--r-- | src/plugins/platformIndicators.tsx | 139 | ||||
-rw-r--r-- | src/plugins/whoReacted.tsx | 4 | ||||
-rw-r--r-- | src/utils/constants.ts | 4 | ||||
-rw-r--r-- | src/utils/settingsSync.ts | 123 | ||||
-rw-r--r-- | src/webpack/common.tsx | 1 |
13 files changed, 530 insertions, 7 deletions
diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index f5be651..a4ad87f 100755 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -62,7 +62,7 @@ await Promise.all( ...commonOptions, outfile: "dist/Vencord.user.js", banner: { - js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", PackageJSON.version) + js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${PackageJSON.version}.${new Date().getTime()}`) }, footer: { // UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index e0f1815..a605d31 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -301,6 +301,7 @@ export default ErrorBoundary.wrap(function Settings() { disabled={plugin.required || !!dependency} plugin={plugin} isNew={newPlugins?.includes(plugin.name)} + key={plugin.name} />; }) : <Text variant="text-md/normal">No plugins meet search criteria.</Text> @@ -319,7 +320,7 @@ export default ErrorBoundary.wrap(function Settings() { const tooltipText = plugin.required ? "This plugin is required for Vencord to function." : makeDependencyList(dependencyCheck(plugin.name, depMap)); - return <Tooltip text={tooltipText}> + return <Tooltip text={tooltipText} key={plugin.name}> {({ onMouseLeave, onMouseEnter }) => ( <PluginCard onMouseLeave={onMouseLeave} diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index fc25901..e2abff2 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -20,6 +20,7 @@ import { useSettings } from "../api/settings"; import { ChangeList } from "../utils/ChangeList"; import IpcEvents from "../utils/IpcEvents"; import { useAwaiter } from "../utils/misc"; +import { downloadSettingsBackup, uploadSettingsBackup } from "../utils/settingsSync"; import { Alerts, Button, Card, Forms, Margins, Parser, React, Switch } from "../webpack/common"; import DonateButton from "./DonateButton"; import ErrorBoundary from "./ErrorBoundary"; @@ -136,6 +137,23 @@ export default ErrorBoundary.wrap(function Settings() { > Get notified about new Updates </Switch>} + + <Forms.FormDivider /> + <Forms.FormTitle tag="h5">Settings Sync</Forms.FormTitle> + <Flex> + <Button + onClick={uploadSettingsBackup} + size={Button.Sizes.SMALL} + > + Import Settings + </Button> + <Button + onClick={downloadSettingsBackup} + size={Button.Sizes.SMALL} + > + Export Settings + </Button> + </Flex> </Forms.FormSection > ); }, { diff --git a/src/plugins/TimeBarAllActivities.ts b/src/plugins/TimeBarAllActivities.ts new file mode 100644 index 0000000..d4fe639 --- /dev/null +++ b/src/plugins/TimeBarAllActivities.ts @@ -0,0 +1,35 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * 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/>. +*/ + +import { Devs } from "../utils/constants"; +import definePlugin from "../utils/types"; + +export default definePlugin({ + name: "TimeBarAllActivities", + description: "Adds the Spotify time bar to all activities if they have start and end timestamps", + authors: [Devs.obscurity], + patches: [ + { + find: "renderTimeBar=function", + replacement: { + match: /renderTimeBar=function\((.{1,3})\){.{0,50}?var/, + replace: "renderTimeBar=function($1){var" + } + } + ], +}); diff --git a/src/plugins/arRPC.tsx b/src/plugins/arRPC.tsx new file mode 100644 index 0000000..a9b2f3c --- /dev/null +++ b/src/plugins/arRPC.tsx @@ -0,0 +1,106 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 OpenAsar + * + * 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/>. +*/ + +import { popNotice, showNotice } from "../api/Notices"; +import { Link } from "../components/Link"; +import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; +import definePlugin from "../utils/types"; +import { filters, mapMangledModuleLazy } from "../webpack"; +import { FluxDispatcher, Forms, Toasts } from "../webpack/common"; + +const assetManager = mapMangledModuleLazy( + "getAssetImage: size must === [number, number] for Twitch", + { + getAsset: filters.byCode("apply("), + } +); + +const rpcManager = lazyWebpack(filters.byCode(".APPLICATION_RPC(")); + +async function lookupAsset(applicationId: string, key: string): Promise<string> { + return (await assetManager.getAsset(applicationId, [key, undefined]))[0]; +} + +const apps: any = {}; +async function lookupApp(applicationId: string): Promise<string> { + const socket: any = {}; + await rpcManager.lookupApp(socket, applicationId); + return socket.application; +} + +let ws: WebSocket; +export default definePlugin({ + name: "WebRichPresence (arRPC)", + description: "Client plugin for arRPC to enable RPC on Discord Web (experimental)", + authors: [Devs.Ducko], + target: "WEB", + + settingsAboutComponent: () => ( + <> + <Forms.FormTitle tag="h3">How to use arRPC</Forms.FormTitle> + <Forms.FormText> + <Link href="https://github.com/OpenAsar/arrpc/tree/main#server">Follow the instructions in the GitHub repo</Link> to get the server running, and then enable the plugin. + </Forms.FormText> + </> + ), + + async start() { + if (ws) ws.close(); + ws = new WebSocket("ws://127.0.0.1:1337"); // try to open WebSocket + + ws.onmessage = async e => { // on message, set status to data + const data = JSON.parse(e.data); + + if (data.activity?.assets?.large_image) data.activity.assets.large_image = await lookupAsset(data.activity.application_id, data.activity.assets.large_image); + if (data.activity?.assets?.small_image) data.activity.assets.small_image = await lookupAsset(data.activity.application_id, data.activity.assets.small_image); + + const appId = data.activity.application_id; + if (!apps[appId]) apps[appId] = await lookupApp(appId); + + const app = apps[appId]; + if (!data.activity.name) data.activity.name = app.name; + + FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...data }); + }; + + const connectionSuccessful = await new Promise(res => setTimeout(() => res(ws.readyState === WebSocket.OPEN), 1000)); // check if open after 1s + if (!connectionSuccessful) { + showNotice("Failed to connect to arRPC, is it running?", "Retry", () => { // show notice about failure to connect, with retry/ignore + popNotice(); + this.start(); + }); + return; + } + + Toasts.show({ // show toast on success + message: "Connected to arRPC", + type: Toasts.Type.SUCCESS, + id: Toasts.genId(), + options: { + duration: 1000, + position: Toasts.Position.BOTTOM + } + }); + }, + + stop() { + FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", activity: null }); // clear status + ws.close(); // close WebSocket + } +}); diff --git a/src/plugins/fakeNitro.ts b/src/plugins/fakeNitro.ts index 3ec8dc5..c682324 100644 --- a/src/plugins/fakeNitro.ts +++ b/src/plugins/fakeNitro.ts @@ -60,7 +60,7 @@ migratePluginSettings("FakeNitro", "NitroBypass"); export default definePlugin({ name: "FakeNitro", - authors: [Devs.Arjix, Devs.D3SOX, Devs.Ven], + authors: [Devs.Arjix, Devs.D3SOX, Devs.Ven, Devs.obscurity], description: "Allows you to stream in nitro quality and send fake emojis/stickers.", dependencies: ["MessageEventsAPI"], @@ -125,6 +125,12 @@ export default definePlugin({ default: true, restartNeeded: true, }, + emojiSize: { + description: "Size of the emojis when sending", + type: OptionType.SLIDER, + default: 48, + markers: [32, 48, 64, 128, 160, 256, 512], + }, enableStickerBypass: { description: "Allow sending fake stickers", type: OptionType.BOOLEAN, @@ -270,7 +276,7 @@ export default definePlugin({ if (emoji.guildId === guildId && !emoji.animated) continue; const emojiString = `<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`; - const url = emoji.url.replace(/\?size=\d+/, "?size=48"); + const url = emoji.url.replace(/\?size=\d+/, `?size=${Settings.plugins.FakeNitro.emojiSize}`); messageObj.content = messageObj.content.replace(emojiString, (match, offset, origStr) => { return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`; }); @@ -289,7 +295,7 @@ export default definePlugin({ if (emoji == null || (emoji.guildId === guildId && !emoji.animated)) continue; if (!emoji.require_colons) continue; - const url = emoji.url.replace(/\?size=\d+/, "?size=48"); + const url = emoji.url.replace(/\?size=\d+/, `?size=${Settings.plugins.FakeNitro.emojiSize}`); messageObj.content = messageObj.content.replace(emojiStr, (match, offset, origStr) => { return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`; }); diff --git a/src/plugins/noUnblockToJump.ts b/src/plugins/noUnblockToJump.ts new file mode 100644 index 0000000..e0194ca --- /dev/null +++ b/src/plugins/noUnblockToJump.ts @@ -0,0 +1,50 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Sofia Lima + * + * 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/>. +*/ + +import { Devs } from "../utils/constants"; +import definePlugin from "../utils/types"; + + +export default definePlugin({ + name: "NoUnblockToJump", + description: "Allows you to jump to messages of blocked users without unblocking them", + authors: [Devs.dzshn], + patches: [ + { + find: '.id,"Search Results"', + replacement: { + match: /if\(.{1,10}\)(.{1,10}\.show\({.{1,50}UNBLOCK_TO_JUMP_TITLE)/, + replace: "if(false)$1" + } + }, + { + find: "renderJumpButton=function()", + replacement: { + match: /if\(.{1,10}\)(.{1,10}\.show\({.{1,50}UNBLOCK_TO_JUMP_TITLE)/, + replace: "if(false)$1" + } + }, + { + find: "flash:!0,returnMessageId", + replacement: { + match: /.\?(.{1,10}\.show\({.{1,50}UNBLOCK_TO_JUMP_TITLE)/, + replace: "false?$1" + } + } + ] +}); diff --git a/src/plugins/oneko.ts b/src/plugins/oneko.ts new file mode 100644 index 0000000..67db2d7 --- /dev/null +++ b/src/plugins/oneko.ts @@ -0,0 +1,40 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * 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/>. +*/ + +import { Devs } from "../utils/constants"; +import definePlugin from "../utils/types"; + +export default definePlugin({ + name: "oneko", + description: "cat follow mouse (real)", + // Listing adryd here because this literally just evals her script + authors: [Devs.Ven, Devs.adryd], + + start() { + fetch("https://raw.githubusercontent.com/adryd325/oneko.js/14bab15a755d0e35cd4ae19c931d96d306f99f42/oneko.js") + .then(x => x.text()) + .then(s => s.replace("./oneko.gif", "https://raw.githubusercontent.com/adryd325/oneko.js/14bab15a755d0e35cd4ae19c931d96d306f99f42/oneko.gif")) + .then(eval); + }, + + stop() { + clearInterval(window.onekoInterval); + delete window.onekoInterval; + document.getElementById("oneko")?.remove(); + } +}); diff --git a/src/plugins/platformIndicators.tsx b/src/plugins/platformIndicators.tsx new file mode 100644 index 0000000..2b44973 --- /dev/null +++ b/src/plugins/platformIndicators.tsx @@ -0,0 +1,139 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * 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/>. +*/ + +import { User } from "discord-types/general"; + +import { Settings } from "../api/settings"; +import ErrorBoundary from "../components/ErrorBoundary"; +import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; +import definePlugin, { OptionType } from "../utils/types"; +import { filters } from "../webpack"; +import { PresenceStore, Tooltip } from "../webpack/common"; + +function Icon(path: string, viewBox = "0 0 24 24") { + return ({ color, tooltip }: { color: string; tooltip: string; }) => ( + <Tooltip text={tooltip} > + {(tooltipProps: any) => ( + <svg + {...tooltipProps} + height="18" + width="18" + viewBox={viewBox} + fill={color} + > + <path d={path} /> + </svg> + )} + </Tooltip> + ); +} + +const Icons = { + desktop: Icon("M4 2.5c-1.103 0-2 .897-2 2v11c0 1.104.897 2 2 2h7v2H7v2h10v-2h-4v-2h7c1.103 0 2-.896 2-2v-11c0-1.103-.897-2-2-2H4Zm16 2v9H4v-9h16Z"), + web: Icon("M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93Zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39Z"), + mobile: Icon("M15.5 1h-8A2.5 2.5 0 0 0 5 3.5v17A2.5 2.5 0 0 0 7.5 23h8a2.5 2.5 0 0 0 2.5-2.5v-17A2.5 2.5 0 0 0 15.5 1zm-4 21c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm4.5-4H7V4h9v14z"), + console: Icon("M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z", "0 0 50 50"), +}; +type Platform = keyof typeof Icons; + +const getStatusColor = lazyWebpack(filters.byCode("STATUS_YELLOW", "TWITCH", "STATUS_GREY")); + +const PlatformIcon = ({ platform, status }: { platform: Platform, status: string; }) => { + const tooltip = platform[0].toUpperCase() + platform.slice(1); + const Icon = Icons[platform] ?? Icons.desktop; + + return <Icon color={getStatusColor(status)} tooltip={tooltip} />; +}; + +const PlatformIndicator = ({ user }: { user: User; }) => { + if (!user || user.bot) return null; + + const status = PresenceStore.getState()?.clientStatuses?.[user.id] as Record<Platform, string>; + if (!status) return null; + + const icons = Object.entries(status).map(([platform, status]) => ( + <PlatformIcon + key={platform} + platform={platform as Platform} + status={status} + /> + )); + + if (!icons.length) return null; + + return ( + <div + className="vc-platform-indicator" + style={{ + display: "flex", alignItems: "center", marginLeft: "4px" + }} + > + {icons} + </div> + ); +}; + +export default definePlugin({ + name: "PlatformIndicators", + description: "Adds platform indicators (Desktop, Mobile, Web...) to users", + authors: [Devs.kemo], + + patches: [ + { + // Server member list decorators + find: "this.renderPremium()", + replacement: { + match: /this.renderPremium\(\)[^\]]*?\]/, + replace: "$&.concat(Vencord.Plugins.plugins.PlatformIndicators.renderPlatformIndicators(this.props))" + } + }, + { + // Dm list decorators + find: "PrivateChannel.renderAvatar", + replacement: { + match: /(subText:(.{1,3})\..+?decorators:)(.+?:null)/, + replace: "$1[$3].concat(Vencord.Plugins.plugins.PlatformIndicators.renderPlatformIndicators($2.props))" + } + }, + { + // User badges + find: "Messages.PROFILE_USER_BADGES", + predicate: () => Settings.plugins.PlatformIndicators.showAsBadges, + replacement: { + match: /(Messages\.PROFILE_USER_BADGES,role:"group",children:)(.+?\.key\)\}\)\))/, + replace: "$1[Vencord.Plugins.plugins.PlatformIndicators.renderPlatformIndicators(e)].concat($2)" + } + } + ], + + renderPlatformIndicators: ({ user }: { user: User; }) => ( + <ErrorBoundary noop> + <PlatformIndicator user={user} /> + </ErrorBoundary> + ), + + options: { + showAsBadges: { + description: "Show platform icons in user badges", + type: OptionType.BOOLEAN, + default: true, + restartNeeded: true, + } + } +}); diff --git a/src/plugins/whoReacted.tsx b/src/plugins/whoReacted.tsx index b94f78e..0079983 100644 --- a/src/plugins/whoReacted.tsx +++ b/src/plugins/whoReacted.tsx @@ -56,8 +56,8 @@ export default definePlugin({ patches: [{ find: ",reactionRef:", replacement: { - match: /(=(.{1,3})\.hideEmoji),(.+?)\?null:\(0,.{1,3}\.jsxs?\)\(.{1,10},\{.{0,20}reactionCount.+?\}\)/, - replace: "$1,whoReactedProps=$2,$3?null:Vencord.Plugins.plugins.WhoReacted.renderUsers(whoReactedProps)" + match: /((.)=(.{1,3})\.hideCount)(,.+?reactionCount.+?\}\))/, + replace: "$1,whoReactedProps=$3$4,$2?null:Vencord.Plugins.plugins.WhoReacted.renderUsers(whoReactedProps)" } }], diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 18aaeb8..7563200 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -144,5 +144,9 @@ export const Devs = Object.freeze({ dzshn: { name: "dzshn", id: 310449948011528192n + }, + Ducko: { + name: "Ducko", + id: 506482395269169153n } }); diff --git a/src/utils/settingsSync.ts b/src/utils/settingsSync.ts new file mode 100644 index 0000000..ecf6665 --- /dev/null +++ b/src/utils/settingsSync.ts @@ -0,0 +1,123 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * 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/>. +*/ + +import { Toasts } from "../webpack/common"; +import IpcEvents from "./IpcEvents"; +import Logger from "./Logger"; + +export async function importSettings(data: string) { + try { + var parsed = JSON.parse(data); + } catch (err) { + console.log(data); + throw new Error("Failed to parse JSON: " + String(err)); + } + + if ("settings" in parsed && "quickCss" in parsed) { + await VencordNative.ipc.invoke(IpcEvents.SET_SETTINGS, JSON.stringify(parsed.settings, null, 4)); + await VencordNative.ipc.invoke(IpcEvents.SET_QUICK_CSS, parsed.quickCss); + } else + throw new Error("Invalid Settings. Is this even a Vencord Settings file?"); +} + +export async function exportSettings() { + const settings = JSON.parse(VencordNative.ipc.sendSync(IpcEvents.GET_SETTINGS)); + const quickCss = await VencordNative.ipc.invoke(IpcEvents.GET_QUICK_CSS); + return JSON.stringify({ settings, quickCss }, null, 4); +} + +export async function downloadSettingsBackup() { + const filename = "vencord-settings-backup.json"; + const backup = await exportSettings(); + const data = new TextEncoder().encode(backup); + + if (IS_WEB) { + const file = new File([data], filename, { type: "application/json" }); + const a = document.createElement("a"); + a.href = URL.createObjectURL(file); + a.download = filename; + + document.body.appendChild(a); + a.click(); + setImmediate(() => { + URL.revokeObjectURL(a.href); + document.body.removeChild(a); + }); + } else { + DiscordNative.fileManager.saveWithDialog(data, filename); + } +} + +const toastSuccess = () => Toasts.show({ + type: Toasts.Type.SUCCESS, + message: "Settings successfully imported. Restart to apply changes!", + id: Toasts.genId() +}); + +const toastFailure = (err: any) => Toasts.show({ + type: Toasts.Type.FAILURE, + message: `Failed to import settings: ${String(err)}`, + id: Toasts.genId() +}); + +export async function uploadSettingsBackup(showToast = true): Promise<void> { + if (IS_WEB) { + const input = document.createElement("input"); + input.type = "file"; + input.style.display = "none"; + input.accept = "application/json"; + input.onchange = async () => { + const file = input.files?.[0]; + if (!file) return; + + const reader = new FileReader(); + reader.onload = async () => { + try { + await importSettings(reader.result as string); + if (showToast) toastSuccess(); + } catch (err) { + new Logger("SettingsSync").error(err); + if (showToast) toastFailure(err); + } + }; + reader.readAsText(file); + }; + + document.body.appendChild(input); + input.click(); + setImmediate(() => document.body.removeChild(input)); + } else { + const [file] = await DiscordNative.fileManager.openFiles({ + filters: [ + { name: "Vencord Settings Backup", extensions: ["json"] }, + { name: "all", extensions: ["*"] } + ] + }); + + if (file) { + try { + console.log(file); + await importSettings(new TextDecoder().decode(file.data)); + if (showToast) toastSuccess(); + } catch (err) { + new Logger("SettingsSync").error(err); + if (showToast) toastFailure(err); + } + } + } +} diff --git a/src/webpack/common.tsx b/src/webpack/common.tsx index 5853e56..c649c19 100644 --- a/src/webpack/common.tsx +++ b/src/webpack/common.tsx @@ -37,6 +37,7 @@ export const PermissionStore = lazyWebpack(filters.byProps("can", "getGuildPermi export const PrivateChannelsStore = lazyWebpack(filters.byProps("openPrivateChannel")); export const GuildChannelStore = lazyWebpack(filters.byProps("getChannels")); export const ReadStateStore = lazyWebpack(filters.byProps("lastMessageId")); +export const PresenceStore = lazyWebpack(filters.byProps("setCurrentUserOnConnectionOpen")); export let GuildStore: Stores.GuildStore; export let UserStore: Stores.UserStore; export let SelectedChannelStore: Stores.SelectedChannelStore; |