aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/nwc.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/nwc.js')
-rw-r--r--src/features/nwc.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/features/nwc.js b/src/features/nwc.js
index dc87388..9768740 100644
--- a/src/features/nwc.js
+++ b/src/features/nwc.js
@@ -388,7 +388,10 @@ export function nwcFeature(ctx) {
return !!(prior && prior.length);
};
if (age > 5 && await lookBack()) return dlog('nwc: skip — request already answered elsewhere', ev.id.slice(0, 8));
- if (mobile && age <= 5) await new Promise((r) => setTimeout(r, 1000));
+ // (a phone with this app on screen is as awake as any computer: only
+ // one behind another app holds back — every zap answered by an open
+ // phone used to wait this second for nobody)
+ if (mobile && age <= 5 && typeof document !== 'undefined' && document.hidden) await new Promise((r) => setTimeout(r, 1000));
claimed = await claim(ev.id);
if (claimed === false) return dlog('nwc: standing down — another device claimed', ev.id.slice(0, 8));
if (claimed === null && age <= 5) {
@@ -981,7 +984,14 @@ export function nwcFeature(ctx) {
if (typeof window !== 'undefined') {
window.addEventListener('online', () => listen());
document.addEventListener('visibilitychange', () => {
- if (document.visibilityState === 'visible' && conns().length) { listen(); refreshRegistration(); }
+ if (document.visibilityState === 'visible' && conns().length) {
+ listen(); refreshRegistration();
+ // the worker may have paid while this app sat behind another one
+ Promise.resolve(hook('arkBgAbsorb')).then((had) => { if (had) return reconcileBg(); }).catch(() => {});
+ }
+ // going behind another app: the worker answers from the mirror now, so
+ // it gets this moment's coins, not the last minute-and-a-half's
+ if (document.visibilityState === 'hidden' && conns().length) writeBg();
});
}
}