From 38f90a5ef7bdf6446bdf87091867d192f6bc83c0 Mon Sep 17 00:00:00 2001 From: Cas_ <6506529+ThaUnknown@users.noreply.github.com> Date: Mon, 10 Aug 2026 23:18:57 +0200 Subject: [PATCH 1/5] new browser plugin WebPWA: install discord website as an app (#4508) --- browser/content.js | 12 ++ browser/manifest.json | 31 ++++ browser/service-worker.js | 11 ++ scripts/build/buildWeb.mjs | 2 +- scripts/build/common.mjs | 1 + scripts/generatePluginList.ts | 4 +- src/api/Themes.ts | 11 ++ src/plugins/webPWA.browser/index.tsx | 204 ++++++++++++++++++++++++++ src/plugins/webPWA.browser/styles.css | 21 +++ src/utils/constants.ts | 4 + 10 files changed, 298 insertions(+), 3 deletions(-) create mode 100644 browser/service-worker.js create mode 100644 src/plugins/webPWA.browser/index.tsx create mode 100644 src/plugins/webPWA.browser/styles.css diff --git a/browser/content.js b/browser/content.js index fff893ba2..fba7beaee 100644 --- a/browser/content.js +++ b/browser/content.js @@ -13,6 +13,18 @@ document.addEventListener( RENDERER_CSS_URL: browser.runtime.getURL("dist/Vencord.css"), } }); + + chrome.runtime.onMessage.addListener(request => { + window.postMessage({ type: "vencord:keybinds", meta: request.command }); + }) + + window.addEventListener('message', function(event) { + if (event.source !== window) return; + + if (event.data.type === 'OPEN_SHORTCUTS') { + chrome.runtime.sendMessage({ action: "openShortcuts" }); + } + }, false); }, { once: true } ); diff --git a/browser/manifest.json b/browser/manifest.json index 3463e46cf..00802eb47 100644 --- a/browser/manifest.json +++ b/browser/manifest.json @@ -49,5 +49,36 @@ "path": "modifyResponseHeaders.json" } ] + }, + + "background": { + "service_worker": "service-worker.js" + }, + + "commands": { + "TOGGLE_MUTE": { + "description": "Toggle Mute — Toggle your microphone's transmission on and off." + }, + "TOGGLE_DEAFEN": { + "description": "Toggle Deafen — Toggle your speaker's playback on and off. Also disables your microphone while deafened." + }, + "TOGGLE_VOICE_MODE": { + "description": "Toggle VAD — Toggle to switch between Push-to-talk and Voice Activity mode." + }, + "TOGGLE_STREAMER_MODE": { + "description": "Toggle Streamer Mode — Toggle to enable/disable Streamer Mode." + }, + "TOGGLE_GO_LIVE_STREAMING": { + "description": "Toggle Screen Share — Toggle to start/stop streaming in your current voice channel. Streams can only be started with this keybind if Discord recognises the game you are currently playing." + }, + "NAVIGATE_BACK": { + "description": "Navigate Back — Might conflict with your browsers native keybinds" + }, + "NAVIGATE_FORWARD": { + "description": "Navigate Forward — Might conflict with your browsers native keybinds" + }, + "SAVE_CLIP": { + "description": "Save Clip — Clips the last 30 seconds to 2 minutes of your stream, depending on your settings." + } } } diff --git a/browser/service-worker.js b/browser/service-worker.js new file mode 100644 index 000000000..98f234657 --- /dev/null +++ b/browser/service-worker.js @@ -0,0 +1,11 @@ +chrome.commands.onCommand.addListener(async (command) => { + const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); + + chrome.tabs.sendMessage(tab.id, { command }); +}); + +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { + if (message.action === "openShortcuts") { + chrome.tabs.create({ url: "about://extensions/shortcuts" }); + } +}); diff --git a/scripts/build/buildWeb.mjs b/scripts/build/buildWeb.mjs index 8fa0c59fe..884188ef2 100644 --- a/scripts/build/buildWeb.mjs +++ b/scripts/build/buildWeb.mjs @@ -184,7 +184,7 @@ const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content if (!process.argv.includes("--skip-extension")) { await Promise.all([ appendCssRuntime, - buildExtension("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png"]), + buildExtension("chromium-unpacked", ["modifyResponseHeaders.json", "content.js", "manifest.json", "icon.png", "service-worker.js"]), buildExtension("firefox-unpacked", ["background.js", "content.js", "manifestv2.json", "icon.png"]), ]); diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 26866558e..4e3083d5b 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -168,6 +168,7 @@ export const globPlugins = kind => ({ const excluded = (target === "dev" && !IS_DEV) || (target === "web" && kind === "discordDesktop") || + (target === "browser" && kind !== "web") || (target === "desktop" && kind === "web") || (target === "discordDesktop" && kind !== "discordDesktop") || (target === "vesktop" && kind !== "vesktop"); diff --git a/scripts/generatePluginList.ts b/scripts/generatePluginList.ts index 92bcba75e..8b40b536e 100644 --- a/scripts/generatePluginList.ts +++ b/scripts/generatePluginList.ts @@ -40,7 +40,7 @@ interface PluginData { hasCommands: boolean; required: boolean; enabledByDefault: boolean; - target: "discordDesktop" | "vesktop" | "desktop" | "web" | "dev"; + target: "discordDesktop" | "vesktop" | "desktop" | "web" | "browser" | "dev"; filePath: string; } @@ -166,7 +166,7 @@ async function parseFile(fileName: string) { const target = getPluginTarget(fileName); if (target) { - if (!["web", "discordDesktop", "vesktop", "desktop", "dev"].includes(target)) throw fail(`invalid target ${target}`); + if (!["web", "browser", "discordDesktop", "vesktop", "desktop", "dev"].includes(target)) throw fail(`invalid target ${target}`); data.target = target as any; } diff --git a/src/api/Themes.ts b/src/api/Themes.ts index 2aadd78e8..9180faabc 100644 --- a/src/api/Themes.ts +++ b/src/api/Themes.ts @@ -27,6 +27,8 @@ import { userStyleRootNode, vencordRootNode } from "./Styles"; let style: HTMLStyleElement; let themesStyle: HTMLStyleElement; +const themeChangeListeners = new Set<() => void>(); + async function toggle(isEnabled: boolean) { if (!style) { if (isEnabled) { @@ -89,6 +91,7 @@ async function initThemes() { themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n"); updatePopoutWindows(); + themeChangeListeners.forEach(listener => listener()); } function applyToPopout(popoutWindow: Window | undefined, key: string) { @@ -147,3 +150,11 @@ export function initQuickCssThemeStore(themeStore: ThemeStore) { initThemes(); }); } + +export function addThemeChangeListener(listener: () => void) { + themeChangeListeners.add(listener); +} + +export function removeThemeChangeListener(listener: () => void) { + themeChangeListeners.delete(listener); +} diff --git a/src/plugins/webPWA.browser/index.tsx b/src/plugins/webPWA.browser/index.tsx new file mode 100644 index 000000000..94ec9d491 --- /dev/null +++ b/src/plugins/webPWA.browser/index.tsx @@ -0,0 +1,204 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addThemeChangeListener, removeThemeChangeListener } from "@api/Themes"; +import { Devs } from "@utils/constants"; +import { sleep } from "@utils/misc"; +import definePlugin from "@utils/types"; +import { FluxStore } from "@vencord/discord-types"; +import { findStoreLazy } from "@webpack"; +import { NotificationSettingsStore, RelationshipStore, ThemeStore } from "@webpack/common"; + +import managedStyle from "./styles.css?managed"; + +const GuildReadStateStore: FluxStore & { getTotalMentionCount: () => number; hasAnyUnread: () => boolean; } = findStoreLazy("GuildReadStateStore"); + +let _keybinds: Record any; }>; + +function colorToHex(color: string) { + const ctx = document.createElement("canvas").getContext("2d"); + if (!ctx) return "#000000"; // no GPU, you'll have bigger issues than a miscolored title bar + ctx.fillStyle = color; + ctx.fillRect(0, 0, 1, 1); + return "#" + [...ctx.getImageData(0, 0, 1, 1).data.slice(0, 3)].map(n => n.toString(16).padStart(2, "0")).join(""); +} + +let linkEl: HTMLLinkElement | undefined; +async function setManifest() { + // need to wait for CSS changes to flush + await sleep(20); + + if (linkEl) { + URL.revokeObjectURL(linkEl.href); + linkEl.remove(); + } + + const endpoint = "https:" + window.GLOBAL_ENV.WEBAPP_ENDPOINT; + const appUrl = endpoint + "/app"; // URL when PWA launches + const icon = document.querySelector('link[rel="icon"]')!.href; + const styles = getComputedStyle(document.body); + const manifest = { + id: appUrl, + name: "Discord", + short_name: "Discord", + start_url: appUrl, + display: "fullscreen", + display_override: ["window-controls-overlay"], + dir: "ltr", + lang: "en-US", + background_color: colorToHex(styles.getPropertyValue("--background-base-lower")), + theme_color: colorToHex(styles.getPropertyValue("--background-base-lowest")), + scope: endpoint + "/", // scope of all possible URL"s + description: "Imagine a place...", + orientation: "any", + categories: ["social"], + shortcuts: [ + { + name: "Friends", + url: appUrl, + icons: [{ src: icon, sizes: "256x256" }] + } + ], + protocol_handlers: [{ protocol: "web+discord", url: endpoint + "/%s" }], + launch_handler: { client_mode: "navigate-existing" }, + // Strange CDN but these links are straight from discord.com + screenshots: [ + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/664723dbe91e5ee8db15cfe7_Discord_Website_Refresh_Activities.webp", sizes: "691x720", type: "image/webp", label: "Activities", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/664723da372be4a12a3dc9df_Discord_Website_Refresh_Hop-In.webp", sizes: "939x639", type: "image/webp", label: "Hop In", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/664723da94dd30e64e74357a_Discord_Website_Refresh_StatusHover.webp", sizes: "904x708", type: "image/webp", label: "Status", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/664723da0a2e6be98fa5216b_Discord_Website_Refresh_Emojis%2BSoundboard-p-1080.webp", sizes: "1080x918", type: "image/webp", label: "Emojis", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/6638bdbd1150b7c8509fb2be_Discord_Website_Refresh_SameRoom.webp", sizes: "796x593", type: "image/webp", label: "Rooms", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/68407334ccf9aeca71903bab_home-new.webp", sizes: "1716×1606", type: "image/webp", label: "Discord", form_factor: "wide" }, + { src: "https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/6638bcb99c2b8dc14e6f67fd_Discord_Website_Refresh_Platforms.webp", sizes: "760x580", type: "image/webp", label: "Platforms", form_factor: "wide" } + ], + icons: [ + { + src: icon, + sizes: "256x256", + type: "image/png" + }, + { + src: icon, + sizes: "256x256", + type: "image/png", + purpose: "maskable" + } + ] + }; + + linkEl = document.createElement("link"); + linkEl.rel = "manifest"; + linkEl.href = URL.createObjectURL(new Blob([JSON.stringify(manifest)], { type: "application/json" })); + document.head.appendChild(linkEl); +} + +export default definePlugin({ + name: "WebPWA", + description: "Makes Discord installable as an App (PWA). Enables notification badges, global key-binds and Discord's custom title bar.", + authors: [Devs.ThaUnknown], + tags: ["Utility"], + managedStyle, + enabledByDefault: true, + + flux: { + KEYBINDS_REGISTER_GLOBAL_KEYBIND_ACTIONS: ({ keybinds }: { keybinds: Record any; }>; }) => { + _keybinds = keybinds; + } + }, + + ctrl: new AbortController(), + start() { + + // installability + setManifest(); + // user might change theme before installing the PWA + ThemeStore.addChangeListener(setManifest); + addThemeChangeListener(setManifest); + + // notifications + NotificationSettingsStore.addChangeListener(this.setBadge); + GuildReadStateStore.addChangeListener(this.setBadge); + RelationshipStore.addChangeListener(this.setBadge); + + if (!IS_USERSCRIPT) { + // keybinds + this.ctrl.abort(); + this.ctrl = new AbortController(); + window.addEventListener("message", ({ data }) => { + if (data?.type === "vencord:keybinds" && _keybinds) { + const { meta } = data; + if (meta in _keybinds) _keybinds[meta].onTrigger(); + } + }, this.ctrl); + } + }, + stop() { + navigator.setAppBadge(0); + this.ctrl.abort(); + + if (linkEl) { + URL.revokeObjectURL(linkEl.href); + linkEl.remove(); + } + ThemeStore.removeChangeListener(setManifest); + removeThemeChangeListener(setManifest); + + NotificationSettingsStore.removeChangeListener(this.setBadge); + GuildReadStateStore.removeChangeListener(this.setBadge); + RelationshipStore.removeChangeListener(this.setBadge); + }, + + patches: [ + // Vesktop/src/renderer/patches/hideDownloadAppsButton.ts + { + find: '"app-download-button"', + replacement: { + match: /return(?=.{0,50}id:"app-download-button")/, + replace: "return null;return" + } + }, + // Vesktop/blob/main/src/renderer/patches/enableNotificationsByDefault.ts + { + find: '"NotificationSettingsStore', + replacement: { + match: /\.isPlatformEmbedded(?=\?\i\.\i\.ALL)/g, + replace: "$&||true" + } + }, + // Vesktop/src/renderer/patches/keybindButton.tsx + { + find: "#{intl::KEYBIND_IN_BROSWER_NOTICE}", + replacement: { + match: /,{type:"info",children:(?=.{0,50}?#{intl::KEYBIND_IN_BROSWER_NOTICE})/, + replace: ',{type:"info",children:$self.renderKeybindsButton(),_children:', + predicate: () => !IS_USERSCRIPT + } + } + ], + + renderKeybindsButton: () => ( +
+ Custom global Push To X keybinds are supported. Navigate to { window.postMessage({ type: "OPEN_SHORTCUTS" }, "*"); }}>about://extensions/shortcuts to change them. Hold To X keybinds are not supported. +
+ ), + + // Vesktop/src/renderer/appBadge.ts + setBadge: () => { + try { + const mentionCount = GuildReadStateStore.getTotalMentionCount(); + const pendingRequests = RelationshipStore.getPendingCount(); + const hasUnread = GuildReadStateStore.hasAnyUnread(); + const disableUnreadBadge = NotificationSettingsStore.getDisableUnreadBadge(); + + let totalCount = mentionCount + pendingRequests; + if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1; + + navigator.setAppBadge(totalCount); + } catch (e) { + console.error(e); + } + } +}); diff --git a/src/plugins/webPWA.browser/styles.css b/src/plugins/webPWA.browser/styles.css new file mode 100644 index 000000000..ae0137363 --- /dev/null +++ b/src/plugins/webPWA.browser/styles.css @@ -0,0 +1,21 @@ +:root { + /* opt out of auto-dark-mode plugins, which break discord css, such as force-dark, dark-reader etc */ + color-scheme: only light; + + /* force title bar to be same as WCO bar height, regardless of zoom, device pixel ratio or OS */ + + /* is only set when WCO is defined, otherwise sets to 0 */ + --custom-app-top-bar-height: env(titlebar-area-height, 0px) !important; +} + +/* position trailing titlebar elements alongside WCO */ +[class*="bar_"] [class*="trailing_"] { + padding-right: calc(100vw - env(titlebar-area-width, 100%) - env(titlebar-area-x, 0px)); +} + +/* force hide trailing icons when standalone so there's no ugly pixel overflow */ +@media all and (display-mode: standalone) { + [class*="bar_"] [class*="trailing_"] { + display: none; + } +} \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 4cd10cf6b..30d5735a4 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -589,6 +589,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, + ThaUnknown: { + name: "ThaUnknown_", + id: 252390917665718273n + }, SomeAspy: { name: "SomeAspy", id: 516750892372852754n, From 72cc4d1110145a9b614e074f11abbf0ae8e34b46 Mon Sep 17 00:00:00 2001 From: Davri <42148912+Davr1@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:31:56 +0200 Subject: [PATCH 2/5] WebKeybinds: restore back/forward buttons & improve mac support (#4506) --- src/plugins/webKeybinds.web/index.ts | 89 ++++++++++++++-------------- src/utils/constants.ts | 4 ++ 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/plugins/webKeybinds.web/index.ts b/src/plugins/webKeybinds.web/index.ts index 74b88d79d..98af85d42 100644 --- a/src/plugins/webKeybinds.web/index.ts +++ b/src/plugins/webKeybinds.web/index.ts @@ -16,62 +16,61 @@ * along with this program. If not, see . */ +import { definePluginSettings } from "@api/Settings"; import { Devs, IS_MAC } from "@utils/constants"; -import definePlugin from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { ComponentDispatch, FluxDispatcher, NavigationRouter, SelectedGuildStore, SettingsRouter } from "@webpack/common"; +import definePlugin, { OptionType } from "@utils/types"; -const KeyBinds = findByPropsLazy("JUMP_TO_GUILD", "SERVER_NEXT"); + +const settings = definePluginSettings({ + showNavigationButtons: { + type: OptionType.BOOLEAN, + description: "Show the back/forward navigation buttons in the title bar.", + default: true, + restartNeeded: true + }, + overrideCommonKeybinds: { + type: OptionType.BOOLEAN, + description: "Allows discord to override the most common tab navigation keybinds (ctrl+t, ctrl+shift+t, ctrl+tab, ctrl+shift+tab, ctrl+n). Only works in a few select browsers that allow website keybinds to take priority over native ones.", + default: IS_VESKTOP, + restartNeeded: true, + } +}); export default definePlugin({ name: "WebKeybinds", - description: "Re-adds keybinds missing in the web version of Discord: ctrl+t, ctrl+shift+t, ctrl+tab, ctrl+shift+tab, ctrl+1-9, ctrl+,. Only works fully on Vesktop/Legcord, not inside your browser", + description: "Re-adds keybinds missing in the web version of Discord. Only works fully on Vesktop/Legcord, not inside your browser", tags: ["Shortcuts"], - authors: [Devs.Ven], + authors: [Devs.Ven, Devs.Davri], enabledByDefault: true, - onKey(e: KeyboardEvent) { - const hasCtrl = e.ctrlKey || (e.metaKey && IS_MAC); + settings, - if (hasCtrl) switch (e.key) { - case "t": - case "T": - if (!IS_VESKTOP) return; - e.preventDefault(); - if (e.shiftKey) { - if (SelectedGuildStore.getGuildId()) NavigationRouter.transitionToGuild("@me"); - ComponentDispatch.safeDispatch("TOGGLE_DM_CREATE"); - } else { - FluxDispatcher.dispatch({ - type: "QUICKSWITCHER_SHOW", - query: "", - queryMode: null - }); - } - break; - case "Tab": - if (!IS_VESKTOP) return; - const handler = e.shiftKey ? KeyBinds.SERVER_PREV : KeyBinds.SERVER_NEXT; - handler.action(e); - break; - case ",": - e.preventDefault(); - SettingsRouter.openUserSettings("my_account_panel"); - break; - default: - if (e.key >= "1" && e.key <= "9") { - e.preventDefault(); - KeyBinds.JUMP_TO_GUILD.action(e, `mod+${e.key}`); - } - break; + patches: [ + { + // Replace the list of blocked keybinds with our own. + find: '"Duplicate keyboard shortcuts defined:"', + replacement: { + match: /\[\.\.\.\i\.\i\.binds,/, + replace: "$self.getBlockedKeybinds()||$&" + } + }, + { + find: '?"BACK_FORWARD_NAVIGATION":', + replacement: { + match: /\({showBackForwardButtons:(\i)/, + replace: "({showBackForwardButtons:($1=true)" + }, + predicate: () => settings.store.showNavigationButtons, } - }, + ], - start() { - document.addEventListener("keydown", this.onKey); - }, + getBlockedKeybinds() { + // Zoom shortcuts, allowing these would cause unpredictable zooming behavior on macos + const blocked: string[] = ["mod+plus", "mod+minus", "mod+0"]; - stop() { - document.removeEventListener("keydown", this.onKey); + if (!settings.store.overrideCommonKeybinds) + blocked.push("ctrl+shift+tab", "ctrl+tab", "mod+n", "mod+t", "mod+shift+t"); + + return blocked.map(k => k.replace("mod", IS_MAC ? "cmd" : "ctrl")); } }); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 30d5735a4..024acfd30 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -665,6 +665,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ yuna0x0: { name: "yuna0x0", id: 213656926414831616n + }, + Davri: { + name: "Davri", + id: 457579346282938368n } } satisfies Record); From 9e75fe9ef4bdbe755bd832f54fd63bbbfa9fae50 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 11 Aug 2026 23:12:39 +0200 Subject: [PATCH 3/5] TenorGifSearch: fix search results being blank on Linux --- src/plugins/tenorGifSearch/index.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/plugins/tenorGifSearch/index.tsx b/src/plugins/tenorGifSearch/index.tsx index ab9befbde..d5499b0f7 100644 --- a/src/plugins/tenorGifSearch/index.tsx +++ b/src/plugins/tenorGifSearch/index.tsx @@ -7,11 +7,14 @@ import { Devs } from "@utils/constants"; import { isNonNullish } from "@utils/guards"; import definePlugin from "@utils/types"; +import { findStoreLazy } from "@webpack"; import { FluxDispatcher, LocaleStore } from "@webpack/common"; // API key is taken from the GBoard app on iOS const TENOR_KEY = "3Z0688EVWYKH"; +const GIFPickerViewStore = findStoreLazy("GIFPickerViewStore"); + let cachedCategories: TrendingCategories | null = null; interface TenorMedia { @@ -21,6 +24,8 @@ interface TenorMedia { } interface TenorResult { id: string; + title: string; + h1_title: string; media: Array>; itemurl: string; } @@ -46,17 +51,23 @@ interface TrendingCategories { } function toDiscordGif(item: TenorResult): DiscordGif | null { - const { gif, webm } = item.media[0]; + // Discord uses tinywebp on Linux, webm on rest (including web Linux). Tenor only has "webp", not "tinywebp" + const format = GIFPickerViewStore.getSelectedFormat() === "tinywebp" + ? "webp" + : "tinywebm"; + + const { title, h1_title, id, itemurl } = item; + const { gif, [format]: mediaItem } = item.media[0]; return { - id: item.id, - title: "", // discord always returns a blank string - url: item.itemurl, + id: id, + title: title || h1_title, + url: itemurl, gif_src: gif.url, - src: webm.url, - width: webm.dims[0], - height: webm.dims[1], - preview: webm.preview + src: mediaItem.url, + width: mediaItem.dims[0], + height: mediaItem.dims[1], + preview: mediaItem.preview }; } From 2f786a2ee5f4183f6b491e580042068cd2e1b27d Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 12 Aug 2026 00:04:25 +0200 Subject: [PATCH 4/5] PlatformIndicators: use better embedded icon --- .../src/stores/PresenceStore.d.ts | 8 +- src/plugins/platformIndicators/index.tsx | 86 ++++++++++--------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/packages/discord-types/src/stores/PresenceStore.d.ts b/packages/discord-types/src/stores/PresenceStore.d.ts index f94df8f49..ff2fdf874 100644 --- a/packages/discord-types/src/stores/PresenceStore.d.ts +++ b/packages/discord-types/src/stores/PresenceStore.d.ts @@ -8,15 +8,17 @@ export interface UserAndActivity { export type DiscordPlatform = "desktop" | "mobile" | "web" | "embedded" | "vr"; +export type ClientStatusMap = Partial>; + export interface PresenceStoreState { - presencesForGuilds: Record>; }>>; + presencesForGuilds: Record>; statuses: Record; activities: Record; filteredActivities: Record; hiddenActivities: Record; // TODO: finish typing activityMetadata: Record; - clientStatuses: Record>>; + clientStatuses: Record; } export class PresenceStore extends FluxStore { @@ -26,7 +28,7 @@ export class PresenceStore extends FluxStore { getActivityMetadata(userId: string): any; getAllApplicationActivities(applicationId: string): UserAndActivity[]; getApplicationActivity(userId: string, applicationId: string, guildId?: string): Activity | null; - getClientStatus(userId: string): Record; + getClientStatus(userId: string): ClientStatusMap; getHiddenActivities(): Activity[]; /** literally just getActivities(...)[0] */ getPrimaryActivity(userId: string, guildId?: string): Activity | null; diff --git a/src/plugins/platformIndicators/index.tsx b/src/plugins/platformIndicators/index.tsx index 4801da0d8..b6fcda42d 100644 --- a/src/plugins/platformIndicators/index.tsx +++ b/src/plugins/platformIndicators/index.tsx @@ -24,7 +24,7 @@ import { addMessageDecoration, removeMessageDecoration } from "@api/MessageDecor import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { DiscordPlatform, OnlineStatus, User } from "@vencord/discord-types"; +import { ClientStatusMap, DiscordPlatform, OnlineStatus, User } from "@vencord/discord-types"; import { filters, findStoreLazy, mapMangledModuleLazy } from "@webpack"; import { AuthenticationStore, PresenceStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; @@ -47,7 +47,7 @@ const { useStatusFillColor } = mapMangledModuleLazy([".5625*", "translate"], { }); const platformMap = { - embedded: "Console", + embedded: "Embedded (Console or Game)", vr: "VR" }; @@ -60,9 +60,7 @@ const badge: ProfileBadge = { const indicatorLocations = { list: { description: "In the member list", - onEnable: () => addMemberListDecorator("platform-indicator", ({ user }) => - user && !user.bot ? : null - ), + onEnable: () => addMemberListDecorator("platform-indicator", ({ user }) => renderPlatformIndicators(user, true)), onDisable: () => removeMemberListDecorator("platform-indicator") }, badges: { @@ -72,10 +70,7 @@ const indicatorLocations = { }, messages: { description: "Inside messages", - onEnable: () => addMessageDecoration("platform-indicator", props => { - const user = props.message?.author; - return user && !user.bot ? : null; - }), + onEnable: () => addMessageDecoration("platform-indicator", props => renderPlatformIndicators(props.message?.author, false)), onDisable: () => removeMessageDecoration("platform-indicator") } }; @@ -84,7 +79,7 @@ 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("M 187 0 L 813 0 C 916.277 0 1000 83.723 1000 187 L 1000 1313 C 1000 1416.277 916.277 1500 813 1500 L 187 1500 C 83.723 1500 0 1416.277 0 1313 L 0 187 C 0 83.723 83.723 0 187 0 Z M 125 1000 L 875 1000 L 875 250 L 125 250 Z M 500 1125 C 430.964 1125 375 1180.964 375 1250 C 375 1319.036 430.964 1375 500 1375 C 569.036 1375 625 1319.036 625 1250 C 625 1180.964 569.036 1125 500 1125 Z", { viewBox: "0 0 1000 1500", height: 17, width: 17 }), - embedded: 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", { viewBox: "0 0 50 50" }), + embedded: Icon("M3.06 20.4q-1.53 0-2.37-1.065T.06 16.74l1.26-9q.27-1.8 1.605-2.97T6.06 3.6h11.88q1.8 0 3.135 1.17t1.605 2.97l1.26 9q.21 1.53-.63 2.595T20.94 20.4q-.63 0-1.17-.225T18.78 19.5l-2.7-2.7H7.92l-2.7 2.7q-.45.45-.99.675t-1.17.225Zm14.94-7.2q.51 0 .855-.345T19.2 12q0-.51-.345-.855T18 10.8q-.51 0-.855.345T16.8 12q0 .51.345 .855T18 13.2Zm-2.4-3.6q.51 0 .855-.345T16.8 8.4q0-.51-.345-.855T15.6 7.2q-.51 0-.855.345T14.4 8.4q0 .51.345 .855T15.6 9.6ZM6.9 13.2h1.8v-2.1h2.1v-1.8h-2.1v-2.1h-1.8v2.1h-2.1v1.8h2.1v2.1Z", { viewBox: "0 0 24 24", height: 20, width: 20 }), vr: Icon("M8.46 8.64a1 1 0 0 1 1 1c0 .44-.3.8-.72.92l-.11.07c-.08.06-.2.19-.2.41a.99.99 0 0 1-.98.86h-.06a1 1 0 0 1-.94-1.05l.02-.32c.05-1.06.92-1.9 1.99-1.9ZM15.55 5a5.5 5.5 0 0 1 5.15 3.67h.3a2 2 0 0 1 2 2v3.18a2 2 0 0 1-2 1.99h-.2A4.54 4.54 0 0 1 16.55 19a4.45 4.45 0 0 1-3.6-1.83 1.2 1.2 0 0 0-1.9 0 4.44 4.44 0 0 1-3.9 1.82 4.54 4.54 0 0 1-3.94-3.15H3a2 2 0 0 1-2-2v-3.18c0-1.1.9-1.99 2-1.99h.3A5.5 5.5 0 0 1 8.46 5h7.09Zm-7.1 2C6.6 7 5.06 8.5 4.97 10.41l-.02.66v3.18c0 1.43 1.05 2.66 2.34 2.74.85.06 1.63-.32 2.14-1.01a3.2 3.2 0 0 1 2.57-1.3c1 0 1.97.48 2.57 1.3.5.69 1.3 1.08 2.14 1.01 1.3-.08 2.34-1.31 2.34-2.74l-.02-3.84a3.54 3.54 0 0 0-3.49-3.43H8.45Z", { viewBox: "0 4 24 16", height: 20, width: 20 }), } satisfies Record; @@ -138,28 +133,24 @@ const PlatformIcon = ({ platform, status, small }: { platform: DiscordPlatform, return ; }; -function ensureOwnStatus(user: User) { - if (user.id === AuthenticationStore.getId()) { - const sessions = SessionsStore.getSessions(); - if (typeof sessions !== "object") return null; - const sortedSessions = Object.values(sessions).sort(({ status: a }, { status: b }) => { - if (a === b) return 0; - if (a === "online") return 1; - if (b === "online") return -1; - if (a === "idle") return 1; - if (b === "idle") return -1; - return 0; - }); +function getOwnStatus() { + const sessions = SessionsStore.getSessions(); + if (typeof sessions !== "object") return null; - const ownStatus = Object.values(sortedSessions).reduce((acc, curr) => { - if (curr.clientInfo.client !== "unknown") - acc[curr.clientInfo.client] = curr.status; - return acc; - }, {}); + const sortedSessions = Object.values(sessions).sort(({ status: a }, { status: b }) => { + if (a === b) return 0; + if (a === "online") return 1; + if (b === "online") return -1; + if (a === "idle") return 1; + if (b === "idle") return -1; + return 0; + }); - const { clientStatuses } = PresenceStore.getState(); - clientStatuses[AuthenticationStore.getId()] = ownStatus; - } + return Object.values(sortedSessions).reduce((acc, curr) => { + if (curr.clientInfo.client !== "unknown") + acc[curr.clientInfo.client] = curr.status; + return acc; + }, {} as ClientStatusMap); } function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] { @@ -167,18 +158,18 @@ function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] { if (!user || user.bot) return []; - ensureOwnStatus(user); + const status = user.id === AuthenticationStore.getId() + ? getOwnStatus() + : PresenceStore.getClientStatus(user.id); - const status = PresenceStore.getClientStatus(user.id); if (!status) return []; return Object.entries(status).map(([platform, status]) => ({ key: `vc-platform-indicator-${platform}`, id: `vc-platform-indicator-${platform}`, component: () => ( - + { - ensureOwnStatus(user); - - const status = useStateFromStores([PresenceStore], () => PresenceStore.getClientStatus(user.id)); - if (!status) return null; - - const icons = Object.entries(status).map(([platform, status]) => ( +function PlatformIndicators({ statusMap, small }: { statusMap: ClientStatusMap; small: boolean; }) { + const icons = Object.entries(statusMap).map(([platform, status]) => ( ); -}; +} + +function renderPlatformIndicators(user: User, small: boolean) { + if (!user || user.bot) return null; + if (user.id === AuthenticationStore.getId()) return ; + return ; +} + +function CurrentUserPlatformIndicators({ small }: { small: boolean; }) { + const statusMap = useStateFromStores([SessionsStore], getOwnStatus); + return statusMap ? : null; +} + +function OtherUserPlatformIndicators({ user, small = false }: { user: User; small?: boolean; }) { + const statusMap = useStateFromStores([PresenceStore], () => PresenceStore.getClientStatus(user.id)); + return statusMap ? : null; +} export default definePlugin({ name: "PlatformIndicators", From 4c7e8cd4cb39bf62948418f62af73d3c1b930306 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 12 Aug 2026 02:01:25 +0200 Subject: [PATCH 5/5] fix Discord invite page crashing in browser version --- src/plugins/_core/noTrack.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/plugins/_core/noTrack.ts b/src/plugins/_core/noTrack.ts index 6fcb4daba..5ba03b466 100644 --- a/src/plugins/_core/noTrack.ts +++ b/src/plugins/_core/noTrack.ts @@ -21,6 +21,7 @@ import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType, StartAt } from "@utils/types"; import { WebpackRequire } from "@vencord/discord-types/webpack"; +import { Flux, FluxDispatcher } from "@webpack/common"; const settings = definePluginSettings({ disableAnalytics: { @@ -45,7 +46,7 @@ export default definePlugin({ predicate: () => settings.store.disableAnalytics, replacement: { match: /\(0,\i\.analyticsTrackingStoreMaker\)/, - replace: "(()=>{})", + replace: "$self.analyticsTrackingStoreMaker", }, }, { @@ -140,5 +141,37 @@ export default definePlugin({ Reflect.deleteProperty(window, "DiscordSentry"); } }); + }, + + analyticsTrackingStoreMaker() { + class AnalyticsTrackingStoreStub extends Flux.Store { + static displayName = "AnalyticsTrackingStore"; + + requestDrain() { } + + async submitEventsImmediately() { + // This is supposed to return a Discord rest response but we can't know what the correct shape would be, because + // 1. It's not used anywhere + // 2. It takes a dynamic url + // Instead we throw an error with the same structure as a Discord rest error which they probably should handle gracefully. + // Discord also throws a plain object instead of Error class + + throw { + ok: false, + status: 500, + body: { + message: "Analytics tracking is disabled by NoTrack", + code: 0 + }, + headers: {}, + text: JSON.stringify({ + message: "Analytics tracking is disabled by NoTrack", + code: 0 + }) + }; + } + } + + return new AnalyticsTrackingStoreStub(FluxDispatcher); } });