ipc: fix not waiting for reply
This commit is contained in:
parent
d174fd279f
commit
7aa0c6cf2d
@ -24,6 +24,7 @@ window.Gluon = {
|
|||||||
|
|
||||||
ipc: {
|
ipc: {
|
||||||
send: async (type, data, id = undefined) => {
|
send: async (type, data, id = undefined) => {
|
||||||
|
const isReply = !!id;
|
||||||
id = id ?? Math.random().toString().split('.')[1];
|
id = id ?? Math.random().toString().split('.')[1];
|
||||||
|
|
||||||
window.Gluon.ipc._send(JSON.stringify({
|
window.Gluon.ipc._send(JSON.stringify({
|
||||||
@ -32,7 +33,7 @@ window.Gluon = {
|
|||||||
data
|
data
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (id) return;
|
if (isReply) return;
|
||||||
|
|
||||||
const reply = await new Promise(res => {
|
const reply = await new Promise(res => {
|
||||||
onIPCReply[id] = msg => res(msg);
|
onIPCReply[id] = msg => res(msg);
|
||||||
@ -86,6 +87,7 @@ delete window._gluonSend;
|
|||||||
|
|
||||||
let onIPCReply = {}, ipcListeners = {};
|
let onIPCReply = {}, ipcListeners = {};
|
||||||
const sendToWindow = async (type, data, id = undefined) => {
|
const sendToWindow = async (type, data, id = undefined) => {
|
||||||
|
const isReply = !!id;
|
||||||
id = id ?? Math.random().toString().split('.')[1];
|
id = id ?? Math.random().toString().split('.')[1];
|
||||||
|
|
||||||
await pageLoadPromise; // wait for page to load before sending, otherwise messages won't be heard
|
await pageLoadPromise; // wait for page to load before sending, otherwise messages won't be heard
|
||||||
@ -95,7 +97,7 @@ delete window._gluonSend;
|
|||||||
data
|
data
|
||||||
})})`);
|
})})`);
|
||||||
|
|
||||||
if (id) return; // we are replying, don't expect reply back
|
if (isReply) return; // we are replying, don't expect reply back
|
||||||
|
|
||||||
const reply = await new Promise(res => {
|
const reply = await new Promise(res => {
|
||||||
onIPCReply[id] = msg => res(msg);
|
onIPCReply[id] = msg => res(msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user