diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-02-05 16:39:40 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-02-05 16:39:40 -0800 |
commit | 4e3792aba319b52f957c70347e859f677972e4e2 (patch) | |
tree | 3ea382513378f852f2126d1113e21061c61adec8 /ext/fg/js/driver.js | |
parent | 5076b80f9690a12fda23d06b2c3ddd1df08cff56 (diff) |
handle content script and background script desync on version update1.0.9
Diffstat (limited to 'ext/fg/js/driver.js')
-rw-r--r-- | ext/fg/js/driver.js | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 5467a9f0..8904c12c 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -33,11 +33,11 @@ class Driver { window.addEventListener('mousemove', this.onMouseMove.bind(this)); window.addEventListener('resize', e => this.searchClear()); - getOptions().then(options => { + Promise.all([getOptions(), isEnabled()]).then(([options, enabled]) => { this.options = options; - return isEnabled(); - }).then(enabled => { this.enabled = enabled; + }).catch(error => { + this.handleError(error); }); } @@ -119,14 +119,14 @@ class Driver { this.pendingLookup = true; this.searchTerms(textSource).then(found => { if (!found) { - this.searchKanji(textSource).then(found => { + return this.searchKanji(textSource).then(found => { if (!found && hideNotFound) { this.searchClear(); } }); } }).catch(error => { - window.alert('Error: ' + error); + this.handleError(error, textSource); }).then(() => { this.pendingLookup = false; }); @@ -157,9 +157,6 @@ class Driver { return true; } - }).catch(error => { - window.alert('Error: ' + error); - return false; }); } @@ -181,9 +178,6 @@ class Driver { return true; } - }).catch(error => { - window.alert('Error: ' + error); - return false; }); } @@ -197,6 +191,17 @@ class Driver { this.lastTextSource = null; } + handleError(error, textSource) { + if (window.orphaned) { + if (textSource) { + this.popup.showNextTo(textSource.getRect()); + this.popup.showOrphaned(); + } + } else { + showError(error); + } + } + api_setOptions(options) { this.options = options; } |