Use async/await on content script

This commit is contained in:
Shin'ya Ueoka 2018-06-17 21:42:52 +09:00
parent 48e4bccf0d
commit 7f56a08f3b
3 changed files with 32 additions and 34 deletions

View file

@ -44,15 +44,16 @@ export default class Common {
}
}
reloadSettings() {
browser.runtime.sendMessage({
type: messages.SETTINGS_QUERY,
}).then((settings) => {
async reloadSettings() {
try {
let settings = await browser.runtime.sendMessage({
type: messages.SETTINGS_QUERY,
});
this.store.dispatch(settingActions.set(settings));
}).catch((e) => {
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);
setTimeout(() => this.reloadSettings(), 500);
});
}
}
}