From 2e1fa633de7002f1e9398ff0921faea84e725466 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Mon, 25 Nov 2024 13:55:43 +0100 Subject: [PATCH] fix(suite-desktop-core): init connect popup only if really enabled --- packages/suite-desktop-api/src/api.ts | 2 ++ packages/suite-desktop-api/src/factory.ts | 1 + packages/suite-desktop-core/src/app.ts | 3 ++- .../suite-desktop-core/src/modules/http-receiver.ts | 8 +++++++- suite-common/connect-init/src/connectInitThunks.ts | 13 ++++++------- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/suite-desktop-api/src/api.ts b/packages/suite-desktop-api/src/api.ts index a00c278cccf..4838d294fec 100644 --- a/packages/suite-desktop-api/src/api.ts +++ b/packages/suite-desktop-api/src/api.ts @@ -104,6 +104,7 @@ export interface InvokeChannels { 'app/auto-start/is-enabled': () => InvokeResult; 'tray/change-settings': (payload: TraySettings) => InvokeResult; 'tray/get-settings': () => InvokeResult; + 'connect-popup/enabled': () => boolean; 'connect-popup/ready': () => void; 'connect-popup/response': (response: ConnectPopupResponse) => void; } @@ -169,6 +170,7 @@ export interface DesktopApi { changeTraySettings: DesktopApiInvoke<'tray/change-settings'>; getTraySettings: DesktopApiInvoke<'tray/get-settings'>; // Connect popup + connectPopupEnabled: DesktopApiInvoke<'connect-popup/enabled'>; connectPopupReady: DesktopApiInvoke<'connect-popup/ready'>; connectPopupResponse: DesktopApiInvoke<'connect-popup/response'>; } diff --git a/packages/suite-desktop-api/src/factory.ts b/packages/suite-desktop-api/src/factory.ts index 82b2925e484..c3f53e49602 100644 --- a/packages/suite-desktop-api/src/factory.ts +++ b/packages/suite-desktop-api/src/factory.ts @@ -179,6 +179,7 @@ export const factory = >( getTraySettings: () => ipcRenderer.invoke('tray/get-settings'), // Connect popup + connectPopupEnabled: () => ipcRenderer.invoke('connect-popup/enabled'), connectPopupReady: () => ipcRenderer.invoke('connect-popup/ready'), connectPopupResponse: response => ipcRenderer.invoke('connect-popup/response', response), }; diff --git a/packages/suite-desktop-core/src/app.ts b/packages/suite-desktop-core/src/app.ts index 019b8d5fb40..ede3f18a8ae 100644 --- a/packages/suite-desktop-core/src/app.ts +++ b/packages/suite-desktop-core/src/app.ts @@ -268,7 +268,8 @@ const init = async () => { const mainWindow = mainWindowProxy.getInstance(); const windowExists = mainWindow && !mainWindow.isDestroyed() && mainWindow.isClosable() && !app.isHidden(); - const autoStartCurrentlyEnabled = isAutoStartEnabled(); + const autoStartCurrentlyEnabled = + isAutoStartEnabled() || app.commandLine.hasSwitch('bridge-test'); logger.info('main', `Before quit, window exists: ${windowExists}`); if ( !stoppingDaemon && diff --git a/packages/suite-desktop-core/src/modules/http-receiver.ts b/packages/suite-desktop-core/src/modules/http-receiver.ts index 53206a24930..e3310fb7690 100644 --- a/packages/suite-desktop-core/src/modules/http-receiver.ts +++ b/packages/suite-desktop-core/src/modules/http-receiver.ts @@ -54,7 +54,13 @@ export const initBackground: ModuleInitBackground = ({ mainWindowProxy, mainThre return receiver.getRouteAddress(pathname); }); - if (app.commandLine.hasSwitch('expose-connect-ws') || isDevEnv) { + const connectPopupEnabled = app.commandLine.hasSwitch('expose-connect-ws') || isDevEnv; + ipcMain.handle('connect-popup/enabled', ipcEvent => { + validateIpcMessage(ipcEvent); + + return connectPopupEnabled; + }); + if (connectPopupEnabled) { exposeConnectWs({ mainThreadEmitter, httpReceiver: receiver, mainWindowProxy }); } diff --git a/suite-common/connect-init/src/connectInitThunks.ts b/suite-common/connect-init/src/connectInitThunks.ts index b5af94e1c4a..674ab9d98fa 100644 --- a/suite-common/connect-init/src/connectInitThunks.ts +++ b/suite-common/connect-init/src/connectInitThunks.ts @@ -251,13 +251,12 @@ export const connectPopupCallThunk = createThunk( export const connectPopupInitThunk = createThunk( `${CONNECT_INIT_MODULE}/initPopupThunk`, - (_, { dispatch }) => { - if (!desktopApi.available) { - return; + async (_, { dispatch }) => { + if (desktopApi.available && (await desktopApi.connectPopupEnabled())) { + desktopApi.on('connect-popup/call', params => { + dispatch(connectPopupCallThunk(params)); + }); + desktopApi.connectPopupReady(); } - desktopApi.on('connect-popup/call', params => { - dispatch(connectPopupCallThunk(params)); - }); - desktopApi.connectPopupReady(); }, );