]> source.dussan.org Git - gitea.git/commitdiff
Improve logout from worker (#30775)
authorwxiaoguang <wxiaoguang@gmail.com>
Tue, 30 Apr 2024 15:35:42 +0000 (23:35 +0800)
committerGitHub <noreply@github.com>
Tue, 30 Apr 2024 15:35:42 +0000 (15:35 +0000)
A quick fix for #30756

web_src/js/features/notification.js
web_src/js/features/stopwatch.js
web_src/js/modules/worker.js [new file with mode: 0644]

index 2de640e6742c098ceba07a538b45492270765281..8e5a1f83db8034b893af97e4438bbdd1d8845d07 100644 (file)
@@ -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;
@@ -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',
index bcea26bd6e78eea98778c398da7d59c875d20fc4..79d9892b74821fa67fb59c45b5c5d7031cdc552a 100644 (file)
@@ -1,6 +1,7 @@
 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;
 
@@ -77,7 +78,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',
diff --git a/web_src/js/modules/worker.js b/web_src/js/modules/worker.js
new file mode 100644 (file)
index 0000000..ef3f1de
--- /dev/null
@@ -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}/`;
+}