MCPcopy Create free account
hub / github.com/Kong/insomnia / invokeInPluginWindow

Function invokeInPluginWindow

packages/insomnia/src/main/plugin-window.ts:247–281  ·  view source on GitHub ↗
(method: string, args?: unknown)

Source from the content-addressed store, hash-verified

245}
246
247export async function invokeInPluginWindow(method: string, args?: unknown): Promise<unknown> {
248 if (!pluginWindow || pluginWindow.isDestroyed()) {
249 createPluginWindow();
250 }
251
252 await waitForReady();
253
254 return new Promise((resolve, reject) => {
255 const id = randomUUID();
256 const startedAt = Date.now();
257
258 const timeout = setTimeout(() => {
259 if (pendingRequests.has(id)) {
260 pendingRequests.delete(id);
261 recordInvocation(method, 'timeout', Date.now() - startedAt);
262 reject(new Error(`[plugin-window] timeout invoking ${method}`));
263 }
264 }, 30_000);
265
266 pendingRequests.set(id, {
267 method,
268 startedAt,
269 resolve: v => {
270 clearTimeout(timeout);
271 resolve(v);
272 },
273 reject: e => {
274 clearTimeout(timeout);
275 reject(e);
276 },
277 });
278
279 pluginWindow!.webContents.send('plugins.invoke', { id, method, args });
280 });
281}
282
283export function destroyPluginWindow() {
284 pluginWindow?.destroy();

Callers 1

Calls 7

createPluginWindowFunction · 0.85
waitForReadyFunction · 0.85
recordInvocationFunction · 0.85
sendMethod · 0.80
resolveFunction · 0.70
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected