Skip to content

Commit 2e8a413

Browse files
committed
replaced redux set data as it does not work on chrome
1 parent 897e2d7 commit 2e8a413

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/weh-ui.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ function Open(name,options) {
2828
}
2929
}
3030

31-
function reduxSetDataCode(data) {
32-
return `
33-
( () => {
34-
try {
35-
store.dispatch({
36-
type: "SET_WEH_DATA",
37-
payload: ${JSON.stringify(data)}
38-
})
39-
} catch(e) {
40-
console.error("store.dispatch error",e);
41-
return false;
42-
}
43-
} ) ();
44-
`;
45-
}
46-
4731
function OpenTab(name,options) {
4832
return new Promise((resolve, reject) => {
4933
var url = browser.extension.getURL(options.url+"?panel="+name);
@@ -60,10 +44,18 @@ function OpenTab(name,options) {
6044
tabId: tab.id
6145
}
6246
tabs[tab.id] = name;
63-
if(options.reduxData)
64-
return browser.tabs.executeScript(tab.id,{
65-
code: reduxSetDataCode(options.reduxData)
66-
});
47+
if(options.initData) {
48+
return new Promise((resolve, reject) => {
49+
const onUpdated = (tabId,changeInfo) => {
50+
if(tabId==tab.id && changeInfo.status=="complete") {
51+
weh.rpc.call(name,"wehInitData",options.initData)
52+
.then(resolve,reject);
53+
browser.tabs.onUpdated.removeListener(onUpdated);
54+
}
55+
}
56+
browser.tabs.onUpdated.addListener(onUpdated);
57+
})
58+
}
6759
});
6860
})
6961
.then(resolve)
@@ -105,7 +97,7 @@ function CreatePanel(name,options) {
10597
// useless if auto resize
10698
Promise.resolve()
10799
.then(()=>{
108-
if(options.reduxData && options.reduxData.autoResize)
100+
if(options.initData && options.initData.autoResize)
109101
return;
110102
else
111103
return browser.windows.update(window.id,{
@@ -164,11 +156,8 @@ function CreatePanel(name,options) {
164156
.then((tab)=>{
165157
weh.__declareAppTab(name,tab.id);
166158
tabs[tab.id] = name;
167-
if(options.reduxData)
168-
return browser.tabs.executeScript(tab.id,{
169-
code: reduxSetDataCode(options.reduxData),
170-
runAt: "document_idle"
171-
});
159+
if(options.initData)
160+
return weh.rpc.call(name,"wehInitData",options.initData);
172161
}).then(resolve)
173162
.catch(reject);
174163

0 commit comments

Comments
 (0)