Merge remote-tracking branch 'upstream/dev' into dev
Some checks are pending
Release / Build Equicord (push) Waiting to run
Test / Test (push) Waiting to run

This commit is contained in:
thororen1234 2025-05-14 19:40:37 -04:00
commit be9657269c
No known key found for this signature in database
14 changed files with 98 additions and 45 deletions

View file

@ -261,7 +261,7 @@ page.on("console", async e => {
const [, tag, message, otherMessage] = args as Array<string>;
switch (tag) {
case "WebpackInterceptor:":
case "WebpackPatcher:":
const patchFailMatch = message.match(/Patch by (.+?) (had no effect|errored|found no module) \(Module id is (.+?)\): (.+)/);
const patchSlowMatch = message.match(/Patch by (.+?) (took [\d.]+?ms) \(Module id is (.+?)\): (.+)/);
const match = patchFailMatch ?? patchSlowMatch;

View file

@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { LazyComponent, LazyComponentWrapper } from "@utils/lazyReact";
import { Logger } from "@utils/Logger";
import { Margins } from "@utils/margins";
import { LazyComponent, LazyComponentWrapper } from "@utils/react";
import { React } from "@webpack/common";
import type { React } from "@webpack/common";
import { ErrorCard } from "./ErrorCard";
@ -46,7 +46,9 @@ const NO_ERROR = {};
// We might want to import this in a place where React isn't ready yet.
// Thus, wrap in a LazyComponent
const ErrorBoundary = LazyComponent(() => {
return class ErrorBoundary extends React.PureComponent<React.PropsWithChildren<Props>> {
// This component is used in a lot of files which end up importing other Webpack commons and causing circular imports.
// For this reason, use a non import access here.
return class ErrorBoundary extends Vencord.Webpack.Common.React.PureComponent<React.PropsWithChildren<Props>> {
state = {
error: NO_ERROR as any,
stack: "",

View file

@ -48,7 +48,7 @@ async function runReporter() {
for (const patch of patches) {
if (!patch.all) {
new Logger("WebpackInterceptor").warn(`Patch by ${patch.plugin} found no module (Module id is -): ${patch.find}`);
new Logger("WebpackPatcher").warn(`Patch by ${patch.plugin} found no module (Module id is -): ${patch.find}`);
if (IS_COMPANION_TEST)
reporterData.failedPatches.foundNoModule.push(patch);
}
@ -56,7 +56,7 @@ async function runReporter() {
for (const [plugin, moduleId, match, totalTime] of patchTimings) {
if (totalTime > 5) {
new Logger("WebpackInterceptor").warn(`Patch by ${plugin} took ${Math.round(totalTime * 100) / 100}ms (Module id is ${String(moduleId)}): ${match}`);
new Logger("WebpackPatcher").warn(`Patch by ${plugin} took ${Math.round(totalTime * 100) / 100}ms (Module id is ${String(moduleId)}): ${match}`);
}
}

View file

@ -72,7 +72,7 @@ export default definePlugin({
group: true,
replacement: [
{
match: /let{ref:\i/,
match: /let{ref:\i,speaking:\i/,
replace: "$self.useAccountPanelRef();$&"
},
{

View file

@ -7,7 +7,7 @@
import { proxyLazy } from "@utils/lazy";
import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue";
import { Flux, FluxDispatcher, GuildChannelStore, PrivateChannelsStore } from "@webpack/common";
import { ChannelActionCreators, Flux, FluxDispatcher, GuildChannelStore } from "@webpack/common";
export const OnlineMemberCountStore = proxyLazy(() => {
const preloadQueue = new Queue();
@ -22,7 +22,7 @@ export const OnlineMemberCountStore = proxyLazy(() => {
async _ensureCount(guildId: string) {
if (onlineMemberMap.has(guildId)) return;
await PrivateChannelsStore.preload(guildId, GuildChannelStore.getDefaultChannel(guildId).id);
await ChannelActionCreators.preload(guildId, GuildChannelStore.getDefaultChannel(guildId).id);
}
ensureCount(guildId?: string) {

View file

@ -19,7 +19,7 @@
import { ILanguageRegistration } from "@vap/shiki";
export const VPC_REPO = "Vap0r1ze/vapcord";
export const VPC_REPO_COMMIT = "88a7032a59cca40da170926651b08201ea3b965a";
export const VPC_REPO_COMMIT = "4d0e4b420fb1e4358852bbd18c804a6f5e54c0d7";
export const vpcRepoAssets = `https://raw.githubusercontent.com/${VPC_REPO}/${VPC_REPO_COMMIT}/assets/shiki-codeblocks`;
export const vpcRepoGrammar = (fileName: string) => `${vpcRepoAssets}/${fileName}`;
export const vpcRepoLanguages = `${vpcRepoAssets}/languages.json`;
@ -46,7 +46,7 @@ export interface LanguageJson {
export const languages: Record<string, Language> = {};
export const loadLanguages = async () => {
const langsJson: LanguageJson[] = await fetch(vpcRepoLanguages).then(res => res.json());
const langsJson: LanguageJson[] = await fetch(vpcRepoLanguages).then(res => res.ok ? res.json() : []);
const loadedLanguages = Object.fromEntries(
langsJson.map(lang => [lang.id, {
...lang,

View file

@ -17,7 +17,7 @@
*/
import { MessageObject } from "@api/MessageEvents";
import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, IconUtils, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { ChannelActionCreators, ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, IconUtils, InviteActions, MessageActions, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { Channel, Guild, Message, User } from "discord-types/general";
import { Except } from "type-fest";
@ -91,7 +91,7 @@ export function getCurrentGuild(): Guild | undefined {
}
export function openPrivateChannel(userId: string) {
PrivateChannelsStore.openPrivateChannel(userId);
ChannelActionCreators.openPrivateChannel(userId);
}
export const enum Theme {

View file

@ -17,7 +17,7 @@
*/
import { Settings, SettingsStore } from "@api/Settings";
import { findByCodeLazy } from "@webpack";
import { ThemeStore } from "@webpack/common";
let style: HTMLStyleElement;
let themesStyle: HTMLStyleElement;
@ -61,8 +61,10 @@ async function initThemes() {
const enabledlinks: string[] = [...enabledThemeLinks];
// "darker" and "midnight" both count as dark
const ThemeStore = findByCodeLazy("ThemeStore");
const activeTheme = ThemeStore.theme === "light" ? "light" : "dark";
// This function is first called on DOMContentLoaded, so ThemeStore may not have been loaded yet
const activeTheme = ThemeStore == null
? undefined
: ThemeStore.theme === "light" ? "light" : "dark";
const links = enabledlinks
.map(rawLink => {
@ -91,7 +93,6 @@ async function initThemes() {
document.addEventListener("DOMContentLoaded", () => {
initSystemValues();
initThemes();
toggle(Settings.useQuickCss);
SettingsStore.addChangeListener("useQuickCss", toggle);
@ -99,6 +100,21 @@ document.addEventListener("DOMContentLoaded", () => {
SettingsStore.addChangeListener("enabledThemeLinks", initThemes);
SettingsStore.addChangeListener("enabledThemes", initThemes);
if (!IS_WEB)
if (!IS_WEB) {
VencordNative.quickCss.addThemeChangeListener(initThemes);
}
initThemes();
});
export function initQuickCssThemeStore() {
initThemes();
let currentTheme = ThemeStore.theme;
ThemeStore.addChangeListener(() => {
if (currentTheme === ThemeStore.theme) return;
currentTheme = ThemeStore.theme;
initThemes();
});
}

View file

@ -17,8 +17,7 @@
*/
import { LazyComponent, LazyComponentWrapper } from "@utils/react";
import { FilterFn, filters, lazyWebpackSearchHistory, waitFor } from "../webpack";
import { FilterFn, filters, lazyWebpackSearchHistory, waitFor } from "@webpack";
export function waitForComponent<T extends React.ComponentType<any> = React.ComponentType<any> & Record<string, any>>(name: string, filter: FilterFn | string | string[]) {
if (IS_REPORTER) lazyWebpackSearchHistory.push(["waitForComponent", Array.isArray(filter) ? filter : [filter]]);

View file

@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { filters, mapMangledModuleLazy, waitFor, wreq } from "../webpack";
import { filters, mapMangledModuleLazy, waitFor, wreq } from "@webpack";
import type * as t from "./types/menu";
export const Menu = {} as t.Menu;

View file

@ -32,7 +32,7 @@ export let MessageStore: Omit<Stores.MessageStore, "getMessages"> & GenericStore
getMessages(chanId: string): any;
};
// this is not actually a FluxStore
// TODO: The correct name for this is ChannelActionCreators and it has already been exported again from utils. Remove this export once enough time has passed
export const PrivateChannelsStore = findByPropsLazy("openPrivateChannel");
export let PermissionStore: GenericStore;
export let GuildChannelStore: GenericStore;
@ -89,4 +89,8 @@ waitForStore("WindowStore", m => WindowStore = m);
waitForStore("EmojiStore", m => EmojiStore = m);
waitForStore("StickersStore", m => StickersStore = m);
waitForStore("TypingStore", m => TypingStore = m);
waitForStore("ThemeStore", m => ThemeStore = m);
waitForStore("ThemeStore", m => {
ThemeStore = m;
// Importing this directly can easily cause circular imports. For this reason, use a non import access here.
Vencord.QuickCss.initQuickCssThemeStore();
});

View file

@ -16,15 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "@webpack";
import type { Channel } from "discord-types/general";
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
import type * as t from "./types/utils";
export let FluxDispatcher: t.FluxDispatcher;
waitFor(["dispatch", "subscribe"], m => {
FluxDispatcher = m;
// Non import call to avoid circular dependency
// Non import access to avoid circular dependency
Vencord.Plugins.subscribeAllPluginsFluxEvents(m);
const cb = () => {
@ -34,7 +34,7 @@ waitFor(["dispatch", "subscribe"], m => {
m.subscribe("CONNECTION_OPEN", cb);
});
export let ComponentDispatch;
export let ComponentDispatch: any;
waitFor(["dispatchToLastSubscribed"], m => ComponentDispatch = m);
export const Constants: t.Constants = mapMangledModuleLazy('ME:"/users/@me"', {
@ -179,6 +179,7 @@ export const MessageActions = findByPropsLazy("editMessage", "sendMessage");
export const MessageCache = findByPropsLazy("clearCache", "_channelMessages");
export const UserProfileActions = findByPropsLazy("openUserProfileModal", "closeUserProfileModal");
export const InviteActions = findByPropsLazy("resolveInvite");
export const ChannelActionCreators = findByPropsLazy("openPrivateChannel");
export const IconUtils: t.IconUtils = findByPropsLazy("getGuildBannerURL", "getUserAvatarURL");

View file

@ -60,7 +60,7 @@ export function getFactoryPatchedBy(moduleId: PropertyKey, webpackRequire = wreq
return webpackRequire.m[moduleId]?.[SYM_PATCHED_BY];
}
const logger = new Logger("WebpackInterceptor", "#8caaee");
const logger = new Logger("WebpackPatcher", "#8caaee");
/** Whether we tried to fallback to the WebpackRequire of the factory, or disabled patches */
let wreqFallbackApplied = false;
@ -436,12 +436,21 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno
callback(exports, module.id);
continue;
}
} catch (err) {
logger.error(
"Error while filtering or firing callback for Webpack waitFor subscription:\n", err,
"\n\nModule exports:", exports,
"\n\nFilter:", filter,
"\n\nCallback:", callback
);
}
if (typeof exports !== "object") {
continue;
}
if (typeof exports !== "object") {
continue;
}
for (const exportKey in exports) {
for (const exportKey in exports) {
try {
// Some exports might have not been initialized yet due to circular imports, so try catch it.
try {
var exportValue = exports[exportKey];
@ -454,9 +463,14 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno
callback(exportValue, module.id);
break;
}
} catch (err) {
logger.error(
"Error while filtering or firing callback for Webpack waitFor subscription:\n", err,
"\n\nExport value:", exports,
"\n\nFilter:", filter,
"\n\nCallback:", callback
);
}
} catch (err) {
logger.error("Error while firing callback for Webpack waitFor subscription:\n", err, filter, callback);
}
}

View file

@ -145,9 +145,17 @@ function makePropertyNonEnumerable(target: Record<PropertyKey, any>, key: Proper
}
export function _blacklistBadModules(requireCache: NonNullable<AnyWebpackRequire["c"]>, exports: ModuleExports, moduleId: PropertyKey) {
if (shouldIgnoreValue(exports)) {
makePropertyNonEnumerable(requireCache, moduleId);
return true;
try {
if (shouldIgnoreValue(exports)) {
makePropertyNonEnumerable(requireCache, moduleId);
return true;
}
} catch (err) {
logger.error(
"Error while blacklisting module:\n", err,
"\n\nModule id:", moduleId,
"\n\nModule exports:", exports,
);
}
if (typeof exports !== "object") {
@ -156,17 +164,25 @@ export function _blacklistBadModules(requireCache: NonNullable<AnyWebpackRequire
let hasOnlyBadProperties = true;
for (const exportKey in exports) {
// Some exports might have not been initialized yet due to circular imports, so try catch it.
try {
var exportValue = exports[exportKey];
} catch {
continue;
}
// Some exports might have not been initialized yet due to circular imports, so try catch it.
try {
var exportValue = exports[exportKey];
} catch {
continue;
}
if (shouldIgnoreValue(exportValue)) {
makePropertyNonEnumerable(exports, exportKey);
} else {
hasOnlyBadProperties = false;
if (shouldIgnoreValue(exportValue)) {
makePropertyNonEnumerable(exports, exportKey);
} else {
hasOnlyBadProperties = false;
}
} catch (err) {
logger.error(
"Error while blacklistng module:\n", err,
"\n\nModule id:", moduleId,
"\n\nExport value:", exportValue,
);
}
}