aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-05 19:21:06 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-05 20:03:45 +0300
commitaea7c590d1b381786978cd7871aed545be96ce34 (patch)
tree527579d8066ca0b18876641acfd0ee2e84c2e269
parentabd056e5637be5cca3033296843dd442593c73e7 (diff)
refactor _updateFrameOffset
-rw-r--r--ext/fg/js/popup-proxy.js34
1 files changed, 15 insertions, 19 deletions
diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js
index f1618c9f..966198a9 100644
--- a/ext/fg/js/popup-proxy.js
+++ b/ext/fg/js/popup-proxy.js
@@ -120,8 +120,9 @@ class PopupProxy {
}
async _updateFrameOffset() {
+ const now = Date.now();
const firstRun = this._frameOffsetUpdatedAt === null;
- const expired = firstRun || this._frameOffsetUpdatedAt < Date.now() - PopupProxy._frameOffsetExpireTimeout;
+ const expired = firstRun || this._frameOffsetUpdatedAt < now - PopupProxy._frameOffsetExpireTimeout;
if (this._frameOffsetPromise === null && !expired) { return; }
if (this._frameOffsetPromise !== null) {
@@ -131,27 +132,22 @@ class PopupProxy {
return;
}
- this._frameOffsetPromise = this._getFrameOffset();
+ const promise = this._updateFrameOffsetInner(now);
+ if (firstRun) {
+ await promise;
+ }
+ }
- const handleOffset = (offset) => {
+ async _updateFrameOffsetInner(now) {
+ this._frameOffsetPromise = this._getFrameOffset();
+ try {
+ const offset = await this._frameOffsetPromise;
this._frameOffset = offset !== null ? offset : [0, 0];
- this._frameOffsetUpdatedAt = Date.now();
+ this._frameOffsetUpdatedAt = now;
+ } catch (e) {
+ logError(e);
+ } finally {
this._frameOffsetPromise = null;
- };
-
- const handleError = (e) => {
- console.error(e);
- this._frameOffsetPromise = null;
- };
-
- if (firstRun) {
- try {
- handleOffset(await this._frameOffsetPromise);
- } catch (e) {
- handleError(e);
- }
- } else {
- this._frameOffsetPromise.then(handleOffset, handleError);
}
}