Skip to content

Commit

Permalink
fixed handling init data
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-g committed Apr 28, 2018
1 parent a8a1022 commit 84db697
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
10 changes: 6 additions & 4 deletions src/weh-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ browser.runtime.onConnect.addListener((port) => {
Object.assign(appOptions,message._args[0],{ port: port });
if(message._method=="appReady") {
appOptions.ready = true;
if(appOptions.initData)
setTimeout(()=>{
weh.rpc.call(app,"wehInitData",appOptions.initData);
},0);
var wait = waiting[app];
if(wait && wait.timer) {
clearTimeout(wait.timer);
Expand All @@ -75,12 +79,10 @@ browser.runtime.onConnect.addListener((port) => {
});
});

weh.__declareAppTab = function(app,tabId) {
weh.__declareAppTab = function(app,data) {
if(!apps[app])
apps[app] = {};
Object.assign(apps[app],{
tab: tabId
});
Object.assign(apps[app],data);
}

weh.__closeByTab = function(tabId) {
Expand Down
18 changes: 2 additions & 16 deletions src/weh-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,12 @@ function OpenTab(name,options) {
url: url,
})
.then(function(tab) {
weh.__declareAppTab(name,tab.id);
weh.__declareAppTab(name,{tab:tab.id,initData:options.initData});
panels[name] = {
type: "tab",
tabId: tab.id
}
tabs[tab.id] = name;
if(options.initData) {
return new Promise((resolve, reject) => {
const onUpdated = (tabId,changeInfo) => {
if(tabId==tab.id && changeInfo.status=="complete") {
weh.rpc.call(name,"wehInitData",options.initData)
.then(resolve,reject);
browser.tabs.onUpdated.removeListener(onUpdated);
}
}
browser.tabs.onUpdated.addListener(onUpdated);
})
}
});
})
.then(resolve)
Expand Down Expand Up @@ -154,10 +142,8 @@ function CreatePanel(name,options) {
return tab;
})
.then((tab)=>{
weh.__declareAppTab(name,tab.id);
weh.__declareAppTab(name,{tab:tab.id,initData:options.initData});
tabs[tab.id] = name;
if(options.initData)
return weh.rpc.call(name,"wehInitData",options.initData);
}).then(resolve)
.catch(reject);

Expand Down

0 comments on commit 84db697

Please sign in to comment.