Skip to content

Commit 195bf58

Browse files
committed
All around fixes
1 parent fc934ca commit 195bf58

File tree

7 files changed

+59
-42
lines changed

7 files changed

+59
-42
lines changed

injections/vars.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const request: FetchRequest = async (input, init) => {
1919
return electron.session.defaultSession.fetch(isURL(input) ? input.href : input, init);
2020
}
2121

22-
if (!document.body) {
22+
if (typeof document === "object" && !document.body) {
2323
await new Promise(r => document.addEventListener("readystatechange", () => { r(true); }))
2424
}
25-
return fetch.call(window, input, init);
25+
return fetch.call(globalThis, input, init);
2626
}
2727

2828
request.text = async (input, init) => {

packages/mod/src/dashboard/pages/community/themes/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Messages } from "vx:i18n";
55
import {className, InternalStore, suffixNumber} from "../../../../util";
66
import { NO_RESULTS, NO_RESULTS_ALT, NoAddons, queryStore } from "../../addons/shared";
77
import { useInternalStore } from "../../../../hooks";
8-
import { openInviteModal } from "../../../../api/modals";
8+
import { openImageModal, openInviteModal } from "../../../../api/modals";
99
import { closeMenu, MenuComponents, MenuRenderProps, openMenu } from "../../../../api/menu";
1010
import { addons } from "../../../../native";
1111
import { themeStore } from "../../../../addons/themes";
@@ -212,7 +212,7 @@ function CommunityAddonCard({ addon }: { addon: Addon }) {
212212
<div className="vx-community-card" onContextMenu={(event) => openMenu(event, (props) => <CommunityAddonMenu props={props} addon={addon} />)}>
213213
<div className="vx-community-card-splash">
214214
<div className="vx-community-card-preview">
215-
<img src={addon.getSplashImage()} className="vx-community-card-preview-img" loading="lazy" />
215+
<img src={addon.getSplashImage()} className="vx-community-card-preview-img" loading="lazy" onClick={() => openImageModal(addon.getSplashImage(), { scale: 5 })} />
216216
</div>
217217
<Tooltip text={addon.author}>
218218
{(props) => (

packages/mod/src/dashboard/pages/index.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ button.vx-community-card-button {
462462
top: 50%;
463463
transform: translate(-50%, -50%);
464464
}
465-
465+
.vx-community-addons-tags-icon > :last-child {
466+
transition: color .2s linear;
467+
}
466468
.vx-community-addons-tags-notice > :last-child {
467469
color: var(--status-danger);
468470
}

packages/mod/src/plugins/favorite-images/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { bySource, getLazy } from "@webpack";
22
import { definePlugin } from "..";
33
import { Developers } from "../../constants";
4-
import { createAbort } from "../../util";
4+
import { createAbort, focusStore } from "../../util";
55
import { Injector } from "../../patcher";
66
import { isValidElement } from "react";
77

@@ -44,12 +44,10 @@ const plugin = definePlugin({
4444

4545
if (signal.aborted) return;
4646

47-
injector.after(ImageModule.default.prototype, "render", (that, args, res) => {
48-
if (that.props.animated && isValidElement(res)) {
49-
res.props.renderAccessory = function() {
50-
if (that.state.hasMouseOver || that.state.hasFocus) {
51-
return that.props.renderAccessory();
52-
}
47+
injector.after(ImageModule.default.prototype, "render", (that, args, res) => {
48+
if (!that.props.animated && isValidElement(res)) {
49+
res.props.renderAccessory = function() {
50+
return that.props.renderAccessory?.();
5351
}
5452
}
5553
});

packages/web/mv3/src/service-worker/assets.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { browser } from "vx:self";
22
import { Connection } from "./connection";
33
import { VXMessageEvent, ipc } from "./events";
4+
import { logger } from "vx:logger";
45

56
let release: Promise<Git.Release>;
67
async function getRelease(): Promise<Git.Release> {
8+
logger.log(`Getting release is-using-cache(${Boolean(release)})`);
9+
710
if (release) return release;
811

9-
return release = request("https://api.github.com/repos/doggybootsy/vx/releases/latest", { cache: "no-cache" }).then(r => r.json());
12+
return release = request.json<Git.Release>("https://api.github.com/repos/doggybootsy/vx/releases/latest", { cache: "no-cache" }).then(r => r.json);
1013
}
1114

1215
async function getAsset(type: "js" | "css", release: Promise<Git.Release> | Git.Release = getRelease()) {
16+
logger.log(`Fetching asset '${type}'`);
17+
1318
release = release instanceof Promise ? await release : release;
1419

1520
const asset = release.assets.find((asset) => asset.name.endsWith(`.${type}`))!;
@@ -19,26 +24,31 @@ async function getAsset(type: "js" | "css", release: Promise<Git.Release> | Git.
1924
}
2025

2126
export async function install() {
27+
logger.log("Starting install process");
28+
2229
const data = await browser.storage.local.get([ "js", "css" ]);
2330

2431
let didChangeAnything = false;
2532
if (!data.js) {
2633
didChangeAnything = true;
2734
data.js = await getAsset("js");
2835
}
29-
if (!data.js) {
36+
if (!data.css) {
3037
didChangeAnything = true;
3138
data.css = await getAsset("css");
3239
}
3340

41+
logger.log(`Did make any changes '${didChangeAnything}'`);
42+
3443
if (didChangeAnything) await browser.storage.local.set(data);
3544

3645
ipc.dispatchEvent(new VXMessageEvent("code-ready", data));
37-
46+
3847
browser.tabs.query({ url: "*://*.discord.com/*" }, (tabs: { id: number }[]) => {
3948
for (const tab of tabs) {
4049
if (Connection.conections.has(tab.id)) continue;
4150
browser.tabs.reload(tab.id);
51+
logger.log(`Reloading tab id ${tab.id}`);
4252
}
4353
});
4454
}

packages/web/mv3/src/service-worker/connection.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ interface BrowserEventTarget<T extends (...args: any[]) => void> {
1010
dispatch(...args: unknown[]): unknown
1111
}
1212

13-
function native(id: string) {
14-
window.VXExtension = {
15-
id,
16-
update(release) {
17-
postMessage({
18-
type: "update",
19-
from: "vx",
20-
release
21-
});
22-
}
23-
};
24-
}
25-
2613
let js: string;
2714
let css: string;
2815
ipc.addEventListener("code-ready", (event) => {
@@ -41,19 +28,35 @@ function executeScript(connection: Connection) {
4128
return;
4229
}
4330

44-
connection.eval(native, { id: browser.runtime.id });
31+
logger.log(`Injecting script on tab id '${connection.tabId}'`);
32+
33+
connection.eval((id: string, js: string) => {
34+
(globalThis as typeof window).VXExtension = {
35+
id,
36+
update(release) {
37+
postMessage({
38+
type: "update",
39+
from: "vx",
40+
release
41+
});
42+
}
43+
};
4544

46-
connection.eval(`
47-
if (location.pathname === "/popout") {
48-
console.log("VX Skipping, is a popout");
49-
return;
50-
}
51-
if (typeof webpackChunkdiscord_app === "object") {
52-
console.log("VX loaded to late aborting!");
53-
console.log(Array.from(webpackChunkdiscord_app));
54-
return;
55-
}
56-
${js}`);
45+
if (location.pathname.startsWith("/vx")) {
46+
location.replace(`/channels/@me?__vx_dashboard_path__=${encodeURIComponent(location.pathname)}`);
47+
return;
48+
}
49+
if (location.pathname === "/popout") {
50+
console.log("VX Skipping, is a popout");
51+
return;
52+
}
53+
if (typeof (globalThis as typeof window).webpackChunkdiscord_app === "object") {
54+
console.log("VX loaded to late aborting!");
55+
return;
56+
}
57+
58+
(0, eval)(js);
59+
}, { id: browser.runtime.id, js });
5760

5861
connection.insertCSS(css);
5962
}
@@ -77,7 +80,9 @@ export class Connection {
7780
Connection.conections.delete(this.tabId);
7881
});
7982

80-
executeScript(this);
83+
queueMicrotask(() => {
84+
executeScript(this);
85+
});
8186
}
8287

8388
private readonly logger: Logger;

packages/web/mv3/src/service-worker/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ browser.runtime.onConnect.addListener((_connection: any) => {
1414
});
1515
});
1616

17-
browser.runtime.onInstalled.addListener(install);
17+
browser.runtime.onInstalled.addListener(() => {
18+
install();
19+
});

0 commit comments

Comments
 (0)