Skip to content

Commit

Permalink
Improve logout from worker (#30775) (#30789)
Browse files Browse the repository at this point in the history
Backport #30775 by wxiaoguang

A quick fix for #30756

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
GiteaBot and wxiaoguang authored Apr 30, 2024
1 parent 022eac4 commit 2bedd16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion web_src/js/features/notification.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'jquery';
import {GET} from '../modules/fetch.js';
import {toggleElem} from '../utils/dom.js';
import {logoutFromWorker} from '../modules/worker.js';

const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
let notificationSequenceNumber = 0;
Expand Down Expand Up @@ -95,7 +96,7 @@ export function initNotificationCount() {
type: 'close',
});
worker.port.close();
window.location.href = `${appSubUrl}/`;
logoutFromWorker();
} else if (event.data.type === 'close') {
worker.port.postMessage({
type: 'close',
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/features/stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import prettyMilliseconds from 'pretty-ms';
import {createTippy} from '../modules/tippy.js';
import {GET} from '../modules/fetch.js';
import {hideElem, showElem} from '../utils/dom.js';
import {logoutFromWorker} from '../modules/worker.js';

const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config;

Expand Down Expand Up @@ -75,7 +76,7 @@ export function initStopwatch() {
type: 'close',
});
worker.port.close();
window.location.href = `${appSubUrl}/`;
logoutFromWorker();
} else if (event.data.type === 'close') {
worker.port.postMessage({
type: 'close',
Expand Down
9 changes: 9 additions & 0 deletions web_src/js/modules/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {sleep} from '../utils.js';

const {appSubUrl} = window.config;

export async function logoutFromWorker() {
// wait for a while because other requests (eg: logout) may be in the flight
await sleep(5000);
window.location.href = `${appSubUrl}/`;
}

0 comments on commit 2bedd16

Please sign in to comment.