Skip to content

Commit 2bedd16

Browse files
GiteaBotwxiaoguang
andauthored
Improve logout from worker (#30775) (#30789)
Backport #30775 by wxiaoguang A quick fix for #30756 Co-authored-by: wxiaoguang <[email protected]>
1 parent 022eac4 commit 2bedd16

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

web_src/js/features/notification.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import $ from 'jquery';
22
import {GET} from '../modules/fetch.js';
33
import {toggleElem} from '../utils/dom.js';
4+
import {logoutFromWorker} from '../modules/worker.js';
45

56
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
67
let notificationSequenceNumber = 0;
@@ -95,7 +96,7 @@ export function initNotificationCount() {
9596
type: 'close',
9697
});
9798
worker.port.close();
98-
window.location.href = `${appSubUrl}/`;
99+
logoutFromWorker();
99100
} else if (event.data.type === 'close') {
100101
worker.port.postMessage({
101102
type: 'close',

web_src/js/features/stopwatch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import prettyMilliseconds from 'pretty-ms';
22
import {createTippy} from '../modules/tippy.js';
33
import {GET} from '../modules/fetch.js';
44
import {hideElem, showElem} from '../utils/dom.js';
5+
import {logoutFromWorker} from '../modules/worker.js';
56

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

@@ -75,7 +76,7 @@ export function initStopwatch() {
7576
type: 'close',
7677
});
7778
worker.port.close();
78-
window.location.href = `${appSubUrl}/`;
79+
logoutFromWorker();
7980
} else if (event.data.type === 'close') {
8081
worker.port.postMessage({
8182
type: 'close',

web_src/js/modules/worker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {sleep} from '../utils.js';
2+
3+
const {appSubUrl} = window.config;
4+
5+
export async function logoutFromWorker() {
6+
// wait for a while because other requests (eg: logout) may be in the flight
7+
await sleep(5000);
8+
window.location.href = `${appSubUrl}/`;
9+
}

0 commit comments

Comments
 (0)