Skip to content

Commit

Permalink
fix: Alternative fix for is not loading #1322
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Sep 26, 2023
1 parent caf9173 commit a60bbd3
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/chat/events/registerAckMessageEvent.ts
Expand Up @@ -25,7 +25,7 @@ import {
SimpleAckData,
} from '../../whatsapp/functions';

webpack.onReady(registerAckMessageEvent);
webpack.onFullReady(registerAckMessageEvent);

function registerAckMessageEvent() {
MsgStore.on('change:ack', (msg: MsgModel) => {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/events/registerLabelEvent.ts
Expand Up @@ -26,7 +26,7 @@ import {
} from '../../whatsapp/functions';
import { get as getChat } from '../functions/';

webpack.onReady(register);
webpack.onFullReady(register);

function register() {
async function processLabelEvent(event: 'add' | 'remove', ...args: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/events/registerPollEvent.ts
Expand Up @@ -20,7 +20,7 @@ import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { upsertVotes } from '../../whatsapp/functions';
import { getMessageById } from '../functions';

webpack.onReady(register);
webpack.onFullReady(register);

function register() {
wrapModuleFunction(upsertVotes, async (func, ...args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/events/registerReactionsEvent.ts
Expand Up @@ -21,7 +21,7 @@ import { MsgKey } from '../../whatsapp';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { createOrUpdateReactions } from '../../whatsapp/functions';

webpack.onReady(register);
webpack.onFullReady(register);

function register() {
wrapModuleFunction(createOrUpdateReactions, (func, ...args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/prepareLinkPreview.ts
Expand Up @@ -105,7 +105,7 @@ export async function prepareLinkPreview<T extends RawMessage>(
return message;
}

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(getABPropConfigValue, (func, ...args) => {
const [key] = args;
switch (key) {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/prepareMessageButtons.ts
Expand Up @@ -196,7 +196,7 @@ export function prepareMessageButtons<T extends RawMessage>(
return message;
}

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(createMsgProtobuf, (func, ...args) => {
const [message] = args;
const r = func(...args);
Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/sendFileMessage.ts
Expand Up @@ -386,7 +386,7 @@ function generateWhiteThumb(width: number, height: number, maxSize: number) {
};
}

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(generateVideoThumbsAndDuration, async (func, ...args) => {
const [data] = args;

Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/sendListMessage.ts
Expand Up @@ -107,7 +107,7 @@ export async function sendListMessage(
return await sendRawMessage(chatId, message, options);
}

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(typeAttributeFromProtobuf, (func, ...args) => {
const [proto] = args;
if (proto.listMessage) {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/functions/sendLocationMessage.ts
Expand Up @@ -152,7 +152,7 @@ export async function sendLocationMessage(
return await sendRawMessage(chatId, rawMessage, options);
}

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(mediaTypeFromProtobuf, (func, ...args) => {
const [proto] = args;
if (proto.locationMessage) {
Expand Down
2 changes: 1 addition & 1 deletion src/chat/patch.ts
Expand Up @@ -22,7 +22,7 @@ import {
typeAttributeFromProtobuf,
} from '../whatsapp/functions';

webpack.onReady(applyPatch, 1000);
webpack.onFullReady(applyPatch, 1000);

function applyPatch() {
wrapModuleFunction(mediaTypeFromProtobuf, (func, ...args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/conn/functions/setLimit.ts
Expand Up @@ -22,7 +22,7 @@ import { getNumChatsPinned } from '../../whatsapp/functions';

let unlimitedPin: undefined | boolean = undefined;

webpack.onReady(() => {
webpack.onFullReady(() => {
wrapModuleFunction(getNumChatsPinned, (func, ...args) => {
const getNumChatsPinnedOriginal = func(...args);
return unlimitedPin ? 1 : getNumChatsPinnedOriginal;
Expand Down
2 changes: 1 addition & 1 deletion src/group/events/registerParticipantsChangedEvent.ts
Expand Up @@ -20,7 +20,7 @@ import { Wid } from '../../whatsapp';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { updateDBForGroupAction } from '../../whatsapp/functions';

webpack.onReady(register);
webpack.onFullReady(register);

function register() {
const eventTypes = ['add', 'remove', 'demote', 'promote'];
Expand Down
2 changes: 1 addition & 1 deletion src/status/patch.ts
Expand Up @@ -20,7 +20,7 @@ import { UserPrefs } from '../whatsapp';
import { wrapModuleFunction } from '../whatsapp/exportModule';
import { handleSingleMsg } from '../whatsapp/functions';

webpack.onReady(applyPatch);
webpack.onFullReady(applyPatch);

function applyPatch() {
wrapModuleFunction(handleSingleMsg, async (func, ...args) => {
Expand Down
20 changes: 13 additions & 7 deletions src/webpack/index.ts
Expand Up @@ -47,6 +47,12 @@ export function onReady(listener: () => void, delay = 0): void {
});
}

export function onFullReady(listener: () => void, delay = 0): void {
internalEv.on('webpack.full_ready', () => {
setTimeout(listener, delay);
});
}

export type SearchModuleCondition = (module: any, moduleId: string) => boolean;

export let webpackRequire: (<T = any>(moduleId: string) => T) & {
Expand Down Expand Up @@ -89,11 +95,7 @@ export function injectLoader(): void {
debug('injected');
await internalEv.emitAsync('webpack.injected').catch(() => null);

if ((window as any).wppForceMainLoad) {
await new Promise((resolve) => setTimeout(resolve, 5000));
} else {
await internalEv.waitFor('conn.main_loaded');
}
await new Promise((resolve) => setTimeout(resolve, 500));

const allRuntimes = new Array(10000)
.fill(1)
Expand All @@ -110,7 +112,7 @@ export function injectLoader(): void {

const mainRuntimes = allRuntimes.filter((v) => {
const filename = webpackRequire.u(v);
return filename.includes('main');
return filename.includes('main') && !filename.includes('locales');
});

// Use sequential file load
Expand All @@ -126,7 +128,11 @@ export function injectLoader(): void {
debug('ready to use');
await internalEv.emitAsync('webpack.ready').catch(() => null);

await new Promise((resolve) => setTimeout(resolve, 5000));
if ((window as any).wppForceMainLoad) {
await new Promise((resolve) => setTimeout(resolve, 5000));
} else {
await internalEv.waitFor('conn.main_ready');
}

// Use sequential file load
for (const v of allRuntimes) {
Expand Down

0 comments on commit a60bbd3

Please sign in to comment.