Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
81e2a381d0
14 changed files with 405 additions and 66 deletions
|
|
@ -13,6 +13,18 @@ document.addEventListener(
|
|||
RENDERER_CSS_URL: browser.runtime.getURL("dist/Equicord.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 }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -58,5 +58,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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
browser/service-worker.js
Normal file
11
browser/service-worker.js
Normal file
|
|
@ -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" });
|
||||
}
|
||||
});
|
||||
|
|
@ -8,15 +8,17 @@ export interface UserAndActivity {
|
|||
|
||||
export type DiscordPlatform = "desktop" | "mobile" | "web" | "embedded" | "vr";
|
||||
|
||||
export type ClientStatusMap = Partial<Record<DiscordPlatform, OnlineStatus>>;
|
||||
|
||||
export interface PresenceStoreState {
|
||||
presencesForGuilds: Record<string, Record<string, { status: OnlineStatus; activities: Activity[]; clientStatus: Partial<Record<DiscordPlatform, OnlineStatus>>; }>>;
|
||||
presencesForGuilds: Record<string, Record<string, { status: OnlineStatus; activities: Activity[]; clientStatus: ClientStatusMap; }>>;
|
||||
statuses: Record<string, OnlineStatus>;
|
||||
activities: Record<string, Activity[]>;
|
||||
filteredActivities: Record<string, Activity[]>;
|
||||
hiddenActivities: Record<string, Activity[]>;
|
||||
// TODO: finish typing
|
||||
activityMetadata: Record<string, any>;
|
||||
clientStatuses: Record<string, Partial<Record<DiscordPlatform, OnlineStatus>>>;
|
||||
clientStatuses: Record<string, ClientStatusMap>;
|
||||
}
|
||||
|
||||
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<DiscordPlatform, OnlineStatus>;
|
||||
getClientStatus(userId: string): ClientStatusMap;
|
||||
getHiddenActivities(): Activity[];
|
||||
/** literally just getActivities(...)[0] */
|
||||
getPrimaryActivity(userId: string, guildId?: string): Activity | null;
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ const appendCssRuntime = readFile("dist/Equicord.user.css", "utf-8").then(conten
|
|||
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"]),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -171,6 +171,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" && kind !== "equibop") ||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import { coreStyleRootNode, managedStyleRootNode, userStyleRootNode, vencordRoot
|
|||
let style: HTMLStyleElement;
|
||||
let themesStyle: HTMLStyleElement;
|
||||
|
||||
const themeChangeListeners = new Set<() => void>();
|
||||
|
||||
function getThemeActivationMode(themeId: string) {
|
||||
return Settings.themeActivationModes?.[themeId] ?? "always";
|
||||
}
|
||||
|
|
@ -109,6 +111,7 @@ async function initThemes() {
|
|||
|
||||
themesStyle.textContent = Array.from(links).map(link => `@import url("${link.trim()}");`).join("\n");
|
||||
updatePopoutWindows();
|
||||
themeChangeListeners.forEach(listener => listener());
|
||||
}
|
||||
|
||||
function applyToPopout(popoutWindow: Window | undefined, key: string) {
|
||||
|
|
@ -177,3 +180,11 @@ export function initQuickCssThemeStore(themeStore: ThemeStore) {
|
|||
initThemes();
|
||||
});
|
||||
}
|
||||
|
||||
export function addThemeChangeListener(listener: () => void) {
|
||||
themeChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
export function removeThemeChangeListener(listener: () => void) {
|
||||
themeChangeListeners.delete(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
@ -46,7 +47,7 @@ export default definePlugin({
|
|||
predicate: () => settings.store.disableAnalytics,
|
||||
replacement: {
|
||||
match: /\(0,\i\.analyticsTrackingStoreMaker\)/,
|
||||
replace: "(()=>{})",
|
||||
replace: "$self.analyticsTrackingStoreMaker",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -141,5 +142,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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const { useStatusFillColor } = mapMangledModuleLazy([".5625*", "translate"], {
|
|||
});
|
||||
|
||||
const platformMap = {
|
||||
embedded: "Console",
|
||||
embedded: "Embedded (Console or Game)",
|
||||
vr: "VR"
|
||||
};
|
||||
|
||||
|
|
@ -88,12 +88,11 @@ const PlatformIcon = ({ platform, status, small }) => {
|
|||
};
|
||||
|
||||
function useEnsureOwnStatus(user: User) {
|
||||
if (user.id !== AuthenticationStore.getId()) {
|
||||
return;
|
||||
}
|
||||
if (user.id !== AuthenticationStore.getId()) return;
|
||||
|
||||
const sessions = useStateFromStores([SessionsStore], () => 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;
|
||||
|
|
@ -136,10 +135,7 @@ const PlatformIndicator = ({ user, isProfile, isMessage, isMemberList }: Platfor
|
|||
/>
|
||||
));
|
||||
|
||||
if (!icons.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!icons.length) return null;
|
||||
return (
|
||||
<div
|
||||
className={classes("vc-platform-indicator", isProfile && "vc-platform-indicator-profile", isMessage && "vc-platform-indicator-message")}
|
||||
|
|
|
|||
|
|
@ -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<Record<string, TenorMedia>>;
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,62 +16,60 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 || IS_EQUIBOP,
|
||||
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/Equibop/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 && !IS_EQUIBOP) 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 && !IS_EQUIBOP) 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"));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
204
src/plugins/webPWA.browser/index.tsx
Normal file
204
src/plugins/webPWA.browser/index.tsx
Normal file
|
|
@ -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<string, { onTrigger: () => 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<HTMLLinkElement>('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<string, { onTrigger: () => 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: () => (
|
||||
<div>
|
||||
Custom global Push To X keybinds are supported. Navigate to <a onClick={() => { window.postMessage({ type: "OPEN_SHORTCUTS" }, "*"); }}>about://extensions/shortcuts</a> to change them. Hold To X keybinds are not supported.
|
||||
</div>
|
||||
),
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
21
src/plugins/webPWA.browser/styles.css
Normal file
21
src/plugins/webPWA.browser/styles.css
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -609,6 +609,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
|||
name: "RamziAH",
|
||||
id: 1279957227612147747n
|
||||
},
|
||||
ThaUnknown: {
|
||||
name: "ThaUnknown_",
|
||||
id: 252390917665718273n
|
||||
},
|
||||
SomeAspy: {
|
||||
name: "SomeAspy",
|
||||
id: 516750892372852754n
|
||||
|
|
@ -681,6 +685,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
|||
yuna0x0: {
|
||||
name: "yuna0x0",
|
||||
id: 213656926414831616n
|
||||
},
|
||||
Davri: {
|
||||
name: "Davri",
|
||||
id: 457579346282938368n
|
||||
}
|
||||
} satisfies Record<string, Dev>);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue