From 8b0bc61e4f1dff58eca88e80aab767a97d59b52d Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Fri, 29 Jul 2022 17:59:27 +0200 Subject: [PATCH] feat: add wrapper around IPC protocol it allows to unwrap errors and not get all the time Error invoking remote method: : rootCause Change-Id: I1da39e5dc928cccddf263ee506cc62a5163f2188 Signed-off-by: Florent Benoit --- packages/main/src/plugin/index.ts | 127 +++++++++++++++++------------- packages/preload/src/index.ts | 117 ++++++++++++++++----------- 2 files changed, 143 insertions(+), 101 deletions(-) diff --git a/packages/main/src/plugin/index.ts b/packages/main/src/plugin/index.ts index bf9482215743..f2804bede538 100644 --- a/packages/main/src/plugin/index.ts +++ b/packages/main/src/plugin/index.ts @@ -52,6 +52,7 @@ import { Telemetry } from './telemetry/telemetry'; import { NotificationImpl } from './notification-impl'; import { StatusBarRegistry } from './statusbar/statusbar-registry'; import type { StatusBarEntryDescriptor } from './statusbar/statusbar-registry'; +import type { IpcMainInvokeEvent } from 'electron/main'; export class PluginSystem { constructor(private trayMenu: TrayMenu) {} @@ -64,6 +65,31 @@ export class PluginSystem { return window.webContents; } + // encode the error to be sent over IPC + // this is needed because on the client it will display + // a generic error message 'Error invoking remote method' and + // it's not useful for end user + encodeIpcError(e: unknown) { + let builtError; + if (e instanceof Error) { + builtError = { name: e.name, message: e.message, extra: { ...e } }; + } else { + builtError = { message: e }; + } + return builtError; + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ipcHandle(channel: string, listener: (event: IpcMainInvokeEvent, ...args: any[]) => Promise | any) { + ipcMain.handle(channel, async (...args) => { + try { + return { result: await Promise.resolve(listener(...args)) }; + } catch (e) { + return { error: this.encodeIpcError(e) }; + } + }); + } + // initialize extension loader mechanism async initExtensions(): Promise { const eventEmitter = new EventEmitter(); @@ -122,57 +148,57 @@ export class PluginSystem { ); const contributionManager = new ContributionManager(apiSender); - ipcMain.handle('container-provider-registry:listContainers', async (): Promise => { + this.ipcHandle('container-provider-registry:listContainers', async (): Promise => { return containerProviderRegistry.listContainers(); }); - ipcMain.handle('container-provider-registry:listImages', async (): Promise => { + this.ipcHandle('container-provider-registry:listImages', async (): Promise => { return containerProviderRegistry.listImages(); }); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:startContainer', async (_listener, engine: string, containerId: string): Promise => { return containerProviderRegistry.startContainer(engine, containerId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:stopContainer', async (_listener, engine: string, containerId: string): Promise => { return containerProviderRegistry.stopContainer(engine, containerId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:deleteContainer', async (_listener, engine: string, containerId: string): Promise => { return containerProviderRegistry.deleteContainer(engine, containerId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:deleteImage', async (_listener, engine: string, imageId: string): Promise => { return containerProviderRegistry.deleteImage(engine, imageId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:getImageInspect', async (_listener, engine: string, imageId: string): Promise => { return containerProviderRegistry.getImageInspect(engine, imageId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:restartContainer', async (_listener, engine: string, containerId: string): Promise => { return containerProviderRegistry.restartContainer(engine, containerId); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:createAndStartContainer', async (_listener, engine: string, options: ContainerCreateOptions): Promise => { return containerProviderRegistry.createAndStartContainer(engine, options); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:pullImage', async ( _listener, @@ -185,7 +211,7 @@ export class PluginSystem { }); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:pushImage', async (_listener, engine: string, imageId: string, callbackId: number): Promise => { return containerProviderRegistry.pushImage(engine, imageId, (name: string, data: string) => { @@ -193,7 +219,7 @@ export class PluginSystem { }); }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:logsContainer', async (_listener, engine: string, containerId: string, onDataId: number): Promise => { return containerProviderRegistry.logsContainer(engine, containerId, (name: string, data: string) => { @@ -203,7 +229,7 @@ export class PluginSystem { ); const containerProviderRegistryShellInContainerSendCallback = new Map void>(); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:shellInContainer', async (_listener, engine: string, containerId: string, onDataId: number): Promise => { // provide the data content to the remote side @@ -220,7 +246,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:shellInContainerSend', async (_listener, onDataId: number, content: string): Promise => { const callback = containerProviderRegistryShellInContainerSendCallback.get(onDataId); @@ -230,7 +256,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'container-provider-registry:buildImage', async ( _listener, @@ -257,11 +283,11 @@ export class PluginSystem { }, ); - ipcMain.handle('status-bar:getStatusBarEntries', async (): Promise => { + this.ipcHandle('status-bar:getStatusBarEntries', async (): Promise => { return statusBarRegistry.getStatusBarEntries(); }); - ipcMain.handle( + this.ipcHandle( 'status-bar:executeStatusBarEntryCommand', async ( _, @@ -273,38 +299,38 @@ export class PluginSystem { }, ); - ipcMain.handle('provider-registry:getProviderInfos', async (): Promise => { + this.ipcHandle('provider-registry:getProviderInfos', async (): Promise => { return providerRegistry.getProviderInfos(); }); - ipcMain.handle( + this.ipcHandle( 'provider-registry:getProviderDetectionChecks', async (_, providerInternalId: string): Promise => { return providerRegistry.getProviderDetectionChecks(providerInternalId); }, ); - ipcMain.handle('provider-registry:updateProvider', async (_, providerInternalId: string): Promise => { + this.ipcHandle('provider-registry:updateProvider', async (_, providerInternalId: string): Promise => { return providerRegistry.updateProvider(providerInternalId); }); - ipcMain.handle('provider-registry:installProvider', async (_, providerInternalId: string): Promise => { + this.ipcHandle('provider-registry:installProvider', async (_, providerInternalId: string): Promise => { return providerRegistry.installProvider(providerInternalId); }); - ipcMain.handle('provider-registry:startProvider', async (_, providerInternalId: string): Promise => { + this.ipcHandle('provider-registry:startProvider', async (_, providerInternalId: string): Promise => { return providerRegistry.startProvider(providerInternalId); }); - ipcMain.handle('provider-registry:initializeProvider', async (_, providerInternalId: string): Promise => { + this.ipcHandle('provider-registry:initializeProvider', async (_, providerInternalId: string): Promise => { return providerRegistry.initializeProvider(providerInternalId); }); - ipcMain.handle('system:get-free-port', async (_, port: number): Promise => { + this.ipcHandle('system:get-free-port', async (_, port: number): Promise => { return getFreePort(port); }); - ipcMain.handle( + this.ipcHandle( 'provider-registry:startReceiveLogs', async ( _listener, @@ -332,7 +358,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:stopReceiveLogs', async ( _listener, @@ -349,11 +375,11 @@ export class PluginSystem { }, ); - ipcMain.handle('image-registry:getRegistries', async (): Promise => { + this.ipcHandle('image-registry:getRegistries', async (): Promise => { return imageRegistry.getRegistries(); }); - ipcMain.handle('image-registry:hasAuthconfigForImage', async (_listener, imageName: string): Promise => { + this.ipcHandle('image-registry:hasAuthconfigForImage', async (_listener, imageName: string): Promise => { if (imageName.indexOf(',') !== -1) { const allImageNames = imageName.split(','); let hasAuth = false; @@ -366,25 +392,18 @@ export class PluginSystem { return authconfig !== undefined; }); - ipcMain.handle('image-registry:getProviderNames', async (): Promise => { + this.ipcHandle('image-registry:getProviderNames', async (): Promise => { return imageRegistry.getProviderNames(); }); - ipcMain.handle( + this.ipcHandle( 'image-registry:unregisterRegistry', async (_listener, registry: containerDesktopAPI.Registry): Promise => { return imageRegistry.unregisterRegistry(registry); }, ); - ipcMain.handle( - 'image-registry:registerRegistry', - async (_listener, registry: containerDesktopAPI.Registry): Promise => { - await imageRegistry.registerRegistry(registry); - }, - ); - - ipcMain.handle( + this.ipcHandle( 'image-registry:createRegistry', async ( _listener, @@ -395,20 +414,20 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'image-registry:updateRegistry', async (_listener, registryUrl: string, registry: containerDesktopAPI.Registry): Promise => { await imageRegistry.updateRegistry(registryUrl, registry); }, ); - ipcMain.handle( + this.ipcHandle( 'configuration-registry:getConfigurationProperties', async (): Promise> => { return configurationRegistry.getConfigurationProperties(); }, ); - ipcMain.handle( + this.ipcHandle( 'configuration-registry:getConfigurationValue', async ( _listener: Electron.IpcMainInvokeEvent, @@ -423,7 +442,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'configuration-registry:updateConfigurationValue', async ( _listener: Electron.IpcMainInvokeEvent, @@ -435,49 +454,49 @@ export class PluginSystem { }, ); - ipcMain.handle('contributions:listContributions', async (): Promise => { + this.ipcHandle('contributions:listContributions', async (): Promise => { return contributionManager.listContributions(); }); - ipcMain.handle('extension-loader:listExtensions', async (): Promise => { + this.ipcHandle('extension-loader:listExtensions', async (): Promise => { return extensionLoader.listExtensions(); }); - ipcMain.handle( + this.ipcHandle( 'extension-loader:deactivateExtension', async (_listener: Electron.IpcMainInvokeEvent, extensionId: string): Promise => { return extensionLoader.deactivateExtension(extensionId); }, ); - ipcMain.handle( + this.ipcHandle( 'extension-loader:startExtension', async (_listener: Electron.IpcMainInvokeEvent, extensionId: string): Promise => { return extensionLoader.startExtension(extensionId); }, ); - ipcMain.handle( + this.ipcHandle( 'shell:openExternal', async (_listener: Electron.IpcMainInvokeEvent, link: string): Promise => { shell.openExternal(link); }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:startProviderLifecycle', async (_listener: Electron.IpcMainInvokeEvent, providerId: string): Promise => { return providerRegistry.startProviderLifecycle(providerId); }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:stopProviderLifecycle', async (_listener: Electron.IpcMainInvokeEvent, providerId: string): Promise => { return providerRegistry.stopProviderLifecycle(providerId); }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:updateProxySettings', async ( _listener: Electron.IpcMainInvokeEvent, @@ -488,7 +507,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:startProviderConnectionLifecycle', async ( _listener: Electron.IpcMainInvokeEvent, @@ -499,7 +518,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:stopProviderConnectionLifecycle', async ( _listener: Electron.IpcMainInvokeEvent, @@ -510,7 +529,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:deleteProviderConnectionLifecycle', async ( _listener: Electron.IpcMainInvokeEvent, @@ -521,7 +540,7 @@ export class PluginSystem { }, ); - ipcMain.handle( + this.ipcHandle( 'provider-registry:createProviderConnection', async ( _listener: Electron.IpcMainInvokeEvent, diff --git a/packages/preload/src/index.ts b/packages/preload/src/index.ts index 594721e64fb0..2d58299caedd 100644 --- a/packages/preload/src/index.ts +++ b/packages/preload/src/index.ts @@ -52,21 +52,44 @@ function initExposure(): void { }, }; + interface ErrorMessage { + name: string; + message: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + extra: any; + } + + function decodeError(error: ErrorMessage) { + const e = new Error(error.message); + e.name = error.name; + Object.assign(e, error.extra); + return e; + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async function ipcInvoke(channel: string, ...args: any) { + const { error, result } = await ipcRenderer.invoke(channel, ...args); + if (error) { + throw decodeError(error); + } + return result; + } + contextBridge.exposeInMainWorld('events', apiSender); ipcRenderer.on('api-sender', (_, channel, data) => { apiSender.send(channel, data); }); contextBridge.exposeInMainWorld('listContainers', async (): Promise => { - return ipcRenderer.invoke('container-provider-registry:listContainers'); + return ipcInvoke('container-provider-registry:listContainers'); }); contextBridge.exposeInMainWorld('listImages', async (): Promise => { - return ipcRenderer.invoke('container-provider-registry:listImages'); + return ipcInvoke('container-provider-registry:listImages'); }); contextBridge.exposeInMainWorld('startContainer', async (engine: string, containerId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:startContainer', engine, containerId); + return ipcInvoke('container-provider-registry:startContainer', engine, containerId); }); let onDataCallbacksPullImageId = 0; @@ -80,7 +103,7 @@ function initExposure(): void { ): Promise => { onDataCallbacksPullImageId++; onDataCallbacksPullImage.set(onDataCallbacksPullImageId, callback); - return ipcRenderer.invoke( + return ipcInvoke( 'container-provider-registry:pullImage', providerContainerConnectionInfo, imageName, @@ -106,7 +129,7 @@ function initExposure(): void { async (engine: string, imageId: string, callback: (name: string, data: string) => void): Promise => { onDataCallbacksPushImageId++; onDataCallbacksPushImage.set(onDataCallbacksPushImageId, callback); - return ipcRenderer.invoke('container-provider-registry:pushImage', engine, imageId, onDataCallbacksPushImageId); + return ipcInvoke('container-provider-registry:pushImage', engine, imageId, onDataCallbacksPushImageId); }, ); ipcRenderer.on( @@ -121,21 +144,21 @@ function initExposure(): void { ); contextBridge.exposeInMainWorld('restartContainer', async (engine: string, containerId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:restartContainer', engine, containerId); + return ipcInvoke('container-provider-registry:restartContainer', engine, containerId); }); contextBridge.exposeInMainWorld( 'createAndStartContainer', async (engine: string, options: ContainerCreateOptions): Promise => { - return ipcRenderer.invoke('container-provider-registry:createAndStartContainer', engine, options); + return ipcInvoke('container-provider-registry:createAndStartContainer', engine, options); }, ); contextBridge.exposeInMainWorld('stopContainer', async (engine: string, containerId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:stopContainer', engine, containerId); + return ipcInvoke('container-provider-registry:stopContainer', engine, containerId); }); contextBridge.exposeInMainWorld('deleteContainer', async (engine: string, containerId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:deleteContainer', engine, containerId); + return ipcInvoke('container-provider-registry:deleteContainer', engine, containerId); }); let onDataCallbacksLogsContainerId = 0; @@ -146,7 +169,7 @@ function initExposure(): void { async (engine: string, containerId: string, callback: (name: string, data: string) => void): Promise => { onDataCallbacksLogsContainerId++; onDataCallbacksLogsContainer.set(onDataCallbacksLogsContainerId, callback); - return ipcRenderer.invoke( + return ipcInvoke( 'container-provider-registry:logsContainer', engine, containerId, @@ -173,7 +196,7 @@ function initExposure(): void { async (engine: string, containerId: string, onData: (data: Buffer) => void): Promise => { onDataCallbacksShellInContainerId++; onDataCallbacksShellInContainer.set(onDataCallbacksShellInContainerId, onData); - return ipcRenderer.invoke( + return ipcInvoke( 'container-provider-registry:shellInContainer', engine, containerId, @@ -183,7 +206,7 @@ function initExposure(): void { ); contextBridge.exposeInMainWorld('shellInContainerSend', async (dataId: number, content: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:shellInContainerSend', dataId, content); + return ipcInvoke('container-provider-registry:shellInContainerSend', dataId, content); }); ipcRenderer.on( @@ -200,61 +223,61 @@ function initExposure(): void { contextBridge.exposeInMainWorld( 'getImageInspect', async (engine: string, imageId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:getImageInspect', engine, imageId); + return ipcInvoke('container-provider-registry:getImageInspect', engine, imageId); }, ); contextBridge.exposeInMainWorld('deleteImage', async (engine: string, imageId: string): Promise => { - return ipcRenderer.invoke('container-provider-registry:deleteImage', engine, imageId); + return ipcInvoke('container-provider-registry:deleteImage', engine, imageId); }); contextBridge.exposeInMainWorld('startProviderLifecycle', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:startProviderLifecycle', providerId); + return ipcInvoke('provider-registry:startProviderLifecycle', providerId); }); contextBridge.exposeInMainWorld('stopProviderLifecycle', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:stopProviderLifecycle', providerId); + return ipcInvoke('provider-registry:stopProviderLifecycle', providerId); }); contextBridge.exposeInMainWorld( 'updateProviderProxySettings', async (providerId: string, proxySettings: containerDesktopAPI.ProviderProxySettings): Promise => { - return ipcRenderer.invoke('provider-registry:updateProxySettings', providerId, proxySettings); + return ipcInvoke('provider-registry:updateProxySettings', providerId, proxySettings); }, ); contextBridge.exposeInMainWorld( 'getProviderDetectionChecks', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:getProviderDetectionChecks', providerId); + return ipcInvoke('provider-registry:getProviderDetectionChecks', providerId); }, ); contextBridge.exposeInMainWorld( 'installProvider', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:installProvider', providerId); + return ipcInvoke('provider-registry:installProvider', providerId); }, ); contextBridge.exposeInMainWorld( 'updateProvider', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:updateProvider', providerId); + return ipcInvoke('provider-registry:updateProvider', providerId); }, ); contextBridge.exposeInMainWorld( 'initializeProvider', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:initializeProvider', providerId); + return ipcInvoke('provider-registry:initializeProvider', providerId); }, ); contextBridge.exposeInMainWorld( 'startProvider', async (providerId: string): Promise => { - return ipcRenderer.invoke('provider-registry:startProvider', providerId); + return ipcInvoke('provider-registry:startProvider', providerId); }, ); @@ -262,14 +285,14 @@ function initExposure(): void { 'createProviderConnection', // eslint-disable-next-line @typescript-eslint/no-explicit-any async (internalProviderId: string, params: { [key: string]: any }): Promise => { - return ipcRenderer.invoke('provider-registry:createProviderConnection', internalProviderId, params); + return ipcInvoke('provider-registry:createProviderConnection', internalProviderId, params); }, ); contextBridge.exposeInMainWorld( 'startProviderConnectionLifecycle', async (providerId: string, providerContainerConnectionInfo: ProviderContainerConnectionInfo): Promise => { - return ipcRenderer.invoke( + return ipcInvoke( 'provider-registry:startProviderConnectionLifecycle', providerId, providerContainerConnectionInfo, @@ -280,7 +303,7 @@ function initExposure(): void { contextBridge.exposeInMainWorld( 'stopProviderConnectionLifecycle', async (providerId: string, providerContainerConnectionInfo: ProviderContainerConnectionInfo): Promise => { - return ipcRenderer.invoke( + return ipcInvoke( 'provider-registry:stopProviderConnectionLifecycle', providerId, providerContainerConnectionInfo, @@ -291,7 +314,7 @@ function initExposure(): void { contextBridge.exposeInMainWorld( 'deleteProviderConnectionLifecycle', async (providerId: string, providerContainerConnectionInfo: ProviderContainerConnectionInfo): Promise => { - return ipcRenderer.invoke( + return ipcInvoke( 'provider-registry:deleteProviderConnectionLifecycle', providerId, providerContainerConnectionInfo, @@ -313,7 +336,7 @@ function initExposure(): void { ): Promise => { onDataCallbacksBuildImageId++; onDataCallbacksBuildImage.set(onDataCallbacksBuildImageId, eventCollect); - return ipcRenderer.invoke( + return ipcInvoke( 'container-provider-registry:buildImage', containerBuildContextDirectory, relativeContainerfilePath, @@ -335,57 +358,57 @@ function initExposure(): void { ); contextBridge.exposeInMainWorld('getStatusBarEntries', async (): Promise => { - return ipcRenderer.invoke('status-bar:getStatusBarEntries'); + return ipcInvoke('status-bar:getStatusBarEntries'); }); contextBridge.exposeInMainWorld( 'executeStatusBarEntryCommand', // eslint-disable-next-line @typescript-eslint/no-explicit-any async (command: string, args: any[]): Promise => { - return ipcRenderer.invoke('status-bar:executeStatusBarEntryCommand', command, args); + return ipcInvoke('status-bar:executeStatusBarEntryCommand', command, args); }, ); contextBridge.exposeInMainWorld('getProviderInfos', async (): Promise => { - return ipcRenderer.invoke('provider-registry:getProviderInfos'); + return ipcInvoke('provider-registry:getProviderInfos'); }); contextBridge.exposeInMainWorld('getImageRegistries', async (): Promise => { - return ipcRenderer.invoke('image-registry:getRegistries'); + return ipcInvoke('image-registry:getRegistries'); }); contextBridge.exposeInMainWorld('getImageRegistryProviderNames', async (): Promise => { - return ipcRenderer.invoke('image-registry:getProviderNames'); + return ipcInvoke('image-registry:getProviderNames'); }); contextBridge.exposeInMainWorld('hasAuthconfigForImage', async (imageName: string): Promise => { - return ipcRenderer.invoke('image-registry:hasAuthconfigForImage', imageName); + return ipcInvoke('image-registry:hasAuthconfigForImage', imageName); }); contextBridge.exposeInMainWorld( 'createImageRegistry', async (providerName: string, registryCreateOptions: containerDesktopAPI.RegistryCreateOptions): Promise => { - return ipcRenderer.invoke('image-registry:createRegistry', providerName, registryCreateOptions); + return ipcInvoke('image-registry:createRegistry', providerName, registryCreateOptions); }, ); contextBridge.exposeInMainWorld( 'updateImageRegistry', async (registryUrl: string, registry: containerDesktopAPI.Registry): Promise => { - return ipcRenderer.invoke('image-registry:updateRegistry', registryUrl, registry); + return ipcInvoke('image-registry:updateRegistry', registryUrl, registry); }, ); contextBridge.exposeInMainWorld( 'unregisterImageRegistry', async (registry: containerDesktopAPI.Registry): Promise => { - return ipcRenderer.invoke('image-registry:unregisterRegistry', registry); + return ipcInvoke('image-registry:unregisterRegistry', registry); }, ); contextBridge.exposeInMainWorld( 'getConfigurationProperties', async (): Promise> => { - return ipcRenderer.invoke('configuration-registry:getConfigurationProperties'); + return ipcInvoke('configuration-registry:getConfigurationProperties'); }, ); @@ -394,7 +417,7 @@ function initExposure(): void { contextBridge.exposeInMainWorld( 'getConfigurationValue', (key: string, scope?: containerDesktopAPI.ConfigurationScope): Promise => { - return ipcRenderer.invoke('configuration-registry:getConfigurationValue', key, scope); + return ipcInvoke('configuration-registry:getConfigurationValue', key, scope); }, ); @@ -402,28 +425,28 @@ function initExposure(): void { 'updateConfigurationValue', // eslint-disable-next-line @typescript-eslint/no-explicit-any async (key: string, value: any, scope?: containerDesktopAPI.ConfigurationScope): Promise => { - return ipcRenderer.invoke('configuration-registry:updateConfigurationValue', key, value, scope); + return ipcInvoke('configuration-registry:updateConfigurationValue', key, value, scope); }, ); contextBridge.exposeInMainWorld('listExtensions', async (): Promise => { - return ipcRenderer.invoke('extension-loader:listExtensions'); + return ipcInvoke('extension-loader:listExtensions'); }); contextBridge.exposeInMainWorld('stopExtension', async (extensionId: string): Promise => { - return ipcRenderer.invoke('extension-loader:deactivateExtension', extensionId); + return ipcInvoke('extension-loader:deactivateExtension', extensionId); }); contextBridge.exposeInMainWorld('startExtension', async (extensionId: string): Promise => { - return ipcRenderer.invoke('extension-loader:startExtension', extensionId); + return ipcInvoke('extension-loader:startExtension', extensionId); }); contextBridge.exposeInMainWorld('openExternal', async (link: string): Promise => { - return ipcRenderer.invoke('shell:openExternal', link); + return ipcInvoke('shell:openExternal', link); }); contextBridge.exposeInMainWorld('listContributions', async (): Promise => { - return ipcRenderer.invoke('contributions:listContributions'); + return ipcInvoke('contributions:listContributions'); }); // Handle callback on dialog file/folder by calling the callback once we get the answer @@ -494,7 +517,7 @@ function initExposure(): void { }); contextBridge.exposeInMainWorld('getFreePort', async (port: number): Promise => { - return ipcRenderer.invoke('system:get-free-port', port); + return ipcInvoke('system:get-free-port', port); }); type LogFunction = (...data: unknown[]) => void; @@ -518,7 +541,7 @@ function initExposure(): void { error, }; onDataCallbacksStartReceiveLogs.set(onDataCallbacksStartReceiveLogsId, logger); - return ipcRenderer.invoke( + return ipcInvoke( 'provider-registry:startReceiveLogs', providerId, onDataCallbacksStartReceiveLogsId, @@ -546,7 +569,7 @@ function initExposure(): void { contextBridge.exposeInMainWorld( 'stopReceiveLogs', async (providerId: string, containerConnectionInfo?: ProviderContainerConnectionInfo): Promise => { - return ipcRenderer.invoke('provider-registry:stopReceiveLogs', providerId, containerConnectionInfo); + return ipcInvoke('provider-registry:stopReceiveLogs', providerId, containerConnectionInfo); }, );