diff options
author | Giteabot <teabot@gitea.io> | 2024-05-01 05:19:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 05:19:13 +0800 |
commit | 2bedd16c14178461132ad5de347e385721ee3841 (patch) | |
tree | 466fe2dc147ad8c9449bcfb5bb625258f631952b /web_src | |
parent | 022eac4ac8e59f861237cc1e02f7ef117eaf8e30 (diff) | |
download | gitea-2bedd16c14178461132ad5de347e385721ee3841.tar.gz gitea-2bedd16c14178461132ad5de347e385721ee3841.zip |
Improve logout from worker (#30775) (#30789)
Backport #30775 by wxiaoguang
A quick fix for #30756
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/features/notification.js | 3 | ||||
-rw-r--r-- | web_src/js/features/stopwatch.js | 3 | ||||
-rw-r--r-- | web_src/js/modules/worker.js | 9 |
3 files changed, 13 insertions, 2 deletions
diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index 2de640e674..8e5a1f83db 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -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', diff --git a/web_src/js/features/stopwatch.js b/web_src/js/features/stopwatch.js index 2ec74344fc..c58a446075 100644 --- a/web_src/js/features/stopwatch.js +++ b/web_src/js/features/stopwatch.js @@ -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; @@ -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', diff --git a/web_src/js/modules/worker.js b/web_src/js/modules/worker.js new file mode 100644 index 0000000000..ef3f1dea48 --- /dev/null +++ b/web_src/js/modules/worker.js @@ -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}/`; +} |