1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Clipper: Fixed init sequence

This commit is contained in:
Laurent Cozic 2018-09-22 11:21:39 +01:00
parent 5178f99100
commit afb8b92528
2 changed files with 26 additions and 7 deletions

View File

@ -2,7 +2,7 @@ const randomClipperPort = require('./randomClipperPort');
class Bridge {
init(browser, browserSupportsPromises, dispatch) {
async init(browser, browserSupportsPromises, dispatch) {
console.info('Popup: Init bridge');
this.browser_ = browser;
@ -36,7 +36,7 @@ class Bridge {
this.browser_.runtime.onMessage.addListener(this.browser_notify);
const backgroundPage = this.browser_.extension.getBackgroundPage();
const backgroundPage = await this.backgroundPage(this.browser_);
// Not sure why the getBackgroundPage() sometimes returns null, so
// in that case default to "prod" environment, which means the live
@ -53,6 +53,17 @@ class Bridge {
this.findClipperServerPort();
}
async backgroundPage(browser) {
const bgp = browser.extension.getBackgroundPage();
if (bgp) return bgp;
return new Promise((resolve, reject) => {
browser.runtime.getBackgroundPage((bgp) => {
resolve(bgp);
})
});
}
env() {
return this.env_;
}

View File

@ -88,11 +88,19 @@ function reducer(state = defaultState, action) {
return newState;
}
const store = createStore(reducer, applyMiddleware(reduxMiddleware));
async function main() {
const store = createStore(reducer, applyMiddleware(reduxMiddleware));
bridge().init(window.browser ? window.browser : window.chrome, !!window.browser, store.dispatch);
bridge().restoreState();
console.info('Popup: Init bridge and restore state...');
console.info('Popup: Creating React app...');
await bridge().init(window.browser ? window.browser : window.chrome, !!window.browser, store.dispatch);
bridge().restoreState();
ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));
console.info('Popup: Creating React app...');
ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));
}
main().catch((error) => {
console.error('Fatal error on initialisation:', error);
});