Skip to content

Commit

Permalink
Add pagehide to make page unload code work on iOS and iPad (#1710)
Browse files Browse the repository at this point in the history
The pageunload event no longer exists on Safari mobile. This fix adds the
pagehide event to ensure things get cleaned up as the browser closes or
refreshes.
  • Loading branch information
belcherj authored Nov 12, 2019
1 parent bcb6d22 commit a69721f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/utils/ensure-single-browser-tab-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ if (!foundElectron) {
}
});

window.addEventListener('beforeunload', function() {
window.addEventListener('pagehide', unload);
window.addEventListener('beforeunload', unload);

function unload() {
keepGoing = false;
const [lastClient] =
JSON.parse(localStorage.getItem('session-lock')) || emptyLock;

lastClient === clientId && localStorage.removeItem('session-lock');
});
}
}

function uuidv4() {
Expand All @@ -57,7 +60,7 @@ function grabSessionLock() {
const now = Date.now();
// easy case - someone else clearly has the lock
// add some hysteresis to prevent fighting between sessions
if (lastClient !== clientId && now - lastBeat < HEARTBEAT_DELAY * 5) {
if (lastClient !== clientId && now - lastBeat < HEARTBEAT_DELAY * 2) {
return 'lock-unavailable';
}

Expand Down

0 comments on commit a69721f

Please sign in to comment.