Skip to content

Commit

Permalink
fix(suite-desktop-core): init connect popup only if really enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Nov 25, 2024
1 parent 990c350 commit b9e9652
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/suite-desktop-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface InvokeChannels {
'app/auto-start/is-enabled': () => InvokeResult<boolean>;
'tray/change-settings': (payload: TraySettings) => InvokeResult;
'tray/get-settings': () => InvokeResult<TraySettings>;
'connect-popup/enabled': () => boolean;
'connect-popup/ready': () => void;
'connect-popup/response': (response: ConnectPopupResponse) => void;
}
Expand Down Expand Up @@ -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'>;
}
1 change: 1 addition & 0 deletions packages/suite-desktop-api/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const factory = <R extends StrictIpcRenderer<any, IpcRendererEvent>>(
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),
};
Expand Down
3 changes: 2 additions & 1 deletion packages/suite-desktop-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
8 changes: 7 additions & 1 deletion packages/suite-desktop-core/src/modules/http-receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
13 changes: 6 additions & 7 deletions suite-common/connect-init/src/connectInitThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
);

0 comments on commit b9e9652

Please sign in to comment.