Skip to content

Commit a69721f

Browse files
authored
Add pagehide to make page unload code work on iOS and iPad (#1710)
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.
1 parent bcb6d22 commit a69721f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/utils/ensure-single-browser-tab-only.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ if (!foundElectron) {
3030
}
3131
});
3232

33-
window.addEventListener('beforeunload', function() {
33+
window.addEventListener('pagehide', unload);
34+
window.addEventListener('beforeunload', unload);
35+
36+
function unload() {
3437
keepGoing = false;
3538
const [lastClient] =
3639
JSON.parse(localStorage.getItem('session-lock')) || emptyLock;
3740

3841
lastClient === clientId && localStorage.removeItem('session-lock');
39-
});
42+
}
4043
}
4144

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

0 commit comments

Comments
 (0)