Skip to content

Commit

Permalink
fix issues related with multiple events attached (#2376)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Apr 5, 2022
1 parent 9f80a05 commit 26dcdf6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare global {
console.log('[Rocket.Chat Desktop] Injected.ts');

const start = (): void => {
console.log('[Rocket.Chat Desktop] Injected.ts start fired');
if (typeof window.require !== 'function') {
console.log('[Rocket.Chat Desktop] window.require is not defined');
console.log('[Rocket.Chat Desktop] Inject start - retrying in 1 seconds');
Expand All @@ -20,9 +21,12 @@ const start = (): void => {
window.require('/app/utils/rocketchat.info') ?? {};

if (!serverInfo.version) {
console.log('[Rocket.Chat Desktop] serverInfo.version is not defined');
return;
}

console.log('[Rocket.Chat Desktop] Injected.ts serverInfo', serverInfo);

window.RocketChatDesktop.setServerInfo(serverInfo);

const { Meteor } = window.require('meteor/meteor');
Expand Down Expand Up @@ -101,6 +105,8 @@ const start = (): void => {

const destroyPromiseSymbol = Symbol('destroyPromise');

console.log('[Rocket.Chat Desktop] Injected.ts replaced Notification');

window.Notification = class RocketChatDesktopNotification
extends EventTarget
implements Notification
Expand Down Expand Up @@ -229,4 +235,6 @@ const start = (): void => {
};
};

console.log('[Rocket.Chat Desktop] Injected');

start();
5 changes: 5 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ declare global {
contextBridge.exposeInMainWorld('JitsiMeetElectron', JitsiMeetElectron);

const start = async (): Promise<void> => {
console.log('[Rocket.Chat Desktop] preload.ts start');
const serverUrl = await invoke('server-view/get-url');

if (!serverUrl) {
console.log('[Rocket.Chat Desktop] preload.ts serverUrl is not defined');
return;
}

Expand All @@ -41,7 +43,9 @@ const start = async (): Promise<void> => {

await invoke('server-view/ready');

console.log('[Rocket.Chat Desktop] waiting for RocketChatDesktop.onReady');
RocketChatDesktop.onReady(() => {
console.log('[Rocket.Chat Desktop] RocketChatDesktop.onReady fired');
listen(
WEBVIEW_DID_NAVIGATE,
debounce(() => {
Expand All @@ -60,4 +64,5 @@ const start = async (): Promise<void> => {
});
};

console.log('[Rocket.Chat Desktop] waiting for window load');
window.addEventListener('load', start);
3 changes: 3 additions & 0 deletions src/servers/preload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export type RocketChatDesktopAPI = {

export const RocketChatDesktop: RocketChatDesktopAPI = {
onReady: (c) => {
if (serverInfo) {
c(serverInfo);
}
cb = c;
},
setServerInfo: (_serverInfo) => {
Expand Down
7 changes: 4 additions & 3 deletions src/ui/components/ServersView/ServerPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ export const ServerPane: FC<ServerPaneProps> = ({
e: 'did-attach' | 'dom-ready',
cb: () => void
): void => {
webview.addEventListener(e, () => {
const handler = () => {
cb();
webview.removeEventListener(e, cb);
});
webview.removeEventListener(e, handler);
};
webview.addEventListener(e, handler);
};

const handleAttachReady = (): void => {
Expand Down

0 comments on commit 26dcdf6

Please sign in to comment.