Skip to content

Commit 2791715

Browse files
authored
fix: dapp connection event bus (#6589)
1 parent 3157cb9 commit 2791715

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

apps/ext/src/ui/uiJsBridge.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function init() {
3131
if (method === GLOBAL_EVENT_BUS_SYNC_BROADCAST_METHOD_NAME) {
3232
console.log('background event bus sync', params);
3333
const p = params as IGlobalEventBusSyncBroadcastParams;
34-
appEventBus.emitToSelf(p.type as any, p.payload);
34+
appEventBus.emitToSelf({
35+
type: p.type as any,
36+
payload: p.payload,
37+
isRemote: true,
38+
});
3539
}
3640
};
3741
// TODO rename global.$extensionJsBridgeUiToBg

packages/shared/src/eventBus/appEventBus.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ class AppEventBus extends CrossEventEmitter {
349349
type: T,
350350
payload: IAppEventBusPayload[T],
351351
): boolean {
352-
void this.emitToRemote(type, payload);
352+
void this.emitToRemote({ type, payload });
353353
if (this.shouldEmitToSelf) {
354-
this.emitToSelf(type, payload);
354+
this.emitToSelf({ type, payload });
355355
}
356356
return true;
357357
}
@@ -391,15 +391,20 @@ class AppEventBus extends CrossEventEmitter {
391391
return super.removeListener(type, listener);
392392
}
393393

394-
emitToSelf(type: EAppEventBusNames, payload: any) {
394+
emitToSelf(params: {
395+
type: EAppEventBusNames;
396+
payload: any;
397+
isRemote?: boolean;
398+
}) {
399+
const { type, payload, isRemote } = params;
395400
defaultLogger.app.eventBus.emitToSelf({
396401
eventName: type,
397402
});
398403
const payloadCloned = cloneDeep(payload);
399404
try {
400405
// @ts-ignore
401406
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
402-
if (payloadCloned?.$$isRemoteEvent) {
407+
if (payloadCloned?.$$isRemoteEvent && !isRemote) {
403408
// @ts-ignore
404409
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
405410
payloadCloned.$$isRemoteEvent = undefined;
@@ -413,7 +418,8 @@ class AppEventBus extends CrossEventEmitter {
413418

414419
//
415420

416-
async emitToRemote(type: string, payload: any) {
421+
async emitToRemote(params: { type: string; payload: any }) {
422+
const { type, payload } = params;
417423
const convertToRemoteEventPayload = (p: any) => {
418424
const payloadCloned = cloneDeep(p);
419425
try {

packages/shared/src/storage/syncStorage.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { isPlainObject } from 'lodash';
2-
31
import appGlobals from '../appGlobals';
4-
import platformEnv from '../platformEnv';
5-
import { ensureRunOnBackground } from '../utils/assertUtils';
62
import dbPerfMonitor from '../utils/debug/dbPerfMonitor';
73
import resetUtils from '../utils/resetUtils';
84

@@ -31,16 +27,17 @@ export const buildAppStorageFactory = (
3127
const setItem: IAppStorage['setItem'] = (key, value, callback) => {
3228
resetUtils.checkNotInResetting();
3329
dbPerfMonitor.logAppStorageCall('setItem', key);
34-
ensureRunOnBackground();
30+
// ensureRunOnBackground();
3531
return originalSetItem.call(storage, key, value, callback);
3632
};
3733
const getItem: IAppStorage['getItem'] = (key, callback) => {
3834
dbPerfMonitor.logAppStorageCall('getItem', key);
39-
ensureRunOnBackground();
35+
// ensureRunOnBackground();
4036
return originalGetItem.call(storage, key, callback);
4137
};
38+
// eslint-disable-next-line arrow-body-style
4239
const removeItem: IAppStorage['removeItem'] = (key, callback) => {
43-
ensureRunOnBackground();
40+
// ensureRunOnBackground();
4441
return originalRemoveItem.call(storage, key, callback);
4542
};
4643

0 commit comments

Comments
 (0)