From 4495a846921cbb95fe695e8b756fe7bc814eb44e Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 13 Nov 2020 15:51:05 -0500 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20ipc=20mocks=20whe?= =?UTF-8?q?n=20not=20in=20electron=20environment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/mirage/config.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ui/desktop/mirage/config.js b/ui/desktop/mirage/config.js index 475ff24eb..df5618c17 100644 --- a/ui/desktop/mirage/config.js +++ b/ui/desktop/mirage/config.js @@ -6,6 +6,38 @@ import { Response } from 'miragejs'; export default function() { + if (!config.isElectron) { + class MockIPC { + invoke(method, payload) { + console.log('MockIPC:', method, payload); + return this[method](payload); + } + + origin = null; + + getOrigin() { + return this.origin; + } + + setOrigin(origin) { + this.origin = origin; + return this.origin; + } + } + + const mockIPC = new MockIPC(); + + window.addEventListener('message', async function (event) { + if (event.origin !== window.location.origin) return; + const { method, payload } = event.data; + if (method) { + const response = + await mockIPC.invoke(method, payload); + event.ports[0].postMessage(response); + } + }); + } + // make this `http://localhost:8080`, for example, if your API is on a different server // this.urlPrefix = ''; // make this `/api`, for example, if your API is namespaced