Skip to content

Commit e34eb35

Browse files
committed
ensures trigger after appReady
1 parent c088e01 commit e34eb35

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/weh-content.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ port.onMessage.addListener((message) => {
4949
weh.rpc.call("appStarted", {
5050
uiName: weh.uiName,
5151
usePrefs: usePrefs
52-
}).then(function () {
5352
}).catch(function (err) {
5453
console.info("appStarted failed", err);
5554
});
@@ -108,11 +107,36 @@ Promise.all(readyPromises)
108107
return weh.rpc.call("appReady",{
109108
uiName: weh.uiName
110109
});
110+
}).then(function () {
111+
if(triggerRequested) {
112+
let result = triggerArgs;
113+
triggerArgs = undefined;
114+
triggerRequested = false;
115+
weh.doTrigger(result);
116+
}
111117
})
112118
.catch((err)=>{
113119
console.error("app not ready:",err);
114120
});
115121

122+
var triggerRequested = false;
123+
var triggerArgs = undefined;
124+
var appStarted = false;
125+
126+
weh.doTrigger = function (result) {
127+
return weh.rpc.call("trigger",weh.uiName,result)
128+
.catch(()=>{});
129+
}
130+
131+
weh.trigger = function (result) {
132+
if(appStarted)
133+
return weh.doTrigger(result);
134+
else {
135+
triggerArgs = result;
136+
triggerRequested = true;
137+
}
138+
}
139+
116140
/* setting up translation */
117141
weh._ = require("weh-i18n").getMessage;
118142

@@ -135,9 +159,4 @@ weh.setPageTitle = function (title) {
135159
titleElement.appendChild(document.createTextNode(title));
136160
};
137161

138-
weh.trigger = function (result) {
139-
return weh.rpc.call("trigger",weh.uiName,result)
140-
.catch(()=>{});
141-
}
142-
143162
module.exports = weh;

0 commit comments

Comments
 (0)