Fix persisting Shared Worker when logging out with multiple tabs

This commit is contained in:
yflory 2023-07-05 09:34:56 +03:00
parent a5d5dba9f2
commit 66e74efb0c
4 changed files with 17 additions and 1 deletions

View file

@ -387,6 +387,9 @@ define([
cb();
});
};
common.stopWorker = function () {
postMessage('STOPWORKER', null, function () {});
};
common.logoutFromAll = function (cb) {
var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
localStorage.setItem(Constants.tokenKey, token);

View file

@ -19,6 +19,7 @@ define([
if (q === 'CONNECT') { return; }
if (q === 'JOIN_PAD') { return; }
if (q === 'SEND_PAD_MSG') { return; }
if (q === 'STOPWORKER') { return; }
chan.on(q, function (data, cb) {
try {
Rpc.queries[q](clientId, data, cb);
@ -29,6 +30,9 @@ define([
}
});
});
chan.on('STOPWORKER', function (data, cb) {
cb();
});
chan.on('CONNECT', function (cfg, cb) {
// load Store here, with cfg, and pass a "query" (chan.query)
// cId is a clientId used in ServiceWorker or SharedWorker

View file

@ -53,6 +53,7 @@ var init = function (client, cb) {
if (q === 'CONNECT') { return; }
if (q === 'JOIN_PAD') { return; }
if (q === 'SEND_PAD_MSG') { return; }
if (q === 'STOPWORKER') { return; }
chan.on(q, function (data, cb) {
try {
Rpc.queries[q](clientId, data, cb);
@ -71,6 +72,10 @@ var init = function (client, cb) {
}
});
});
chan.on('STOPWORKER', function (data, cb) {
console.error('ICI');
self.close();
});
chan.on('CONNECT', function (cfg, cb) {
debug('SharedW connecting to store...');
/*

View file

@ -1319,11 +1319,15 @@ define([
});
sframeChan.on('Q_LOGOUT', function (data, cb) {
Cryptpad.stopWorker();
Utils.LocalStore.logout(cb);
});
sframeChan.on('Q_LOGOUT_EVERYWHERE', function (data, cb) {
Cryptpad.logoutFromAll(Utils.Util.bake(Utils.LocalStore.logout, cb));
Cryptpad.logoutFromAll(Utils.Util.bake(Utils.LocalStore.logout, function () {
Cryptpad.stopWorker();
cb();
}));
});
sframeChan.on('EV_NOTIFY', function (data) {