account switch – only refresh other tabs when focused

This commit is contained in:
Andrea Vos 2023-07-10 19:17:26 +02:00
parent 1a207284f6
commit f86a40a4f8

View File

@ -104,9 +104,20 @@
this.loadAds();
this.loadGTM();
let needsRefresh = false;
const bc = new BroadcastChannel('account_switch');
bc.onmessage = (ev) => {
if (ev.data !== this.$user()?.username) {
needsRefresh = true;
if (document.hasFocus()) {
needsRefresh = false;
window.location.reload();
}
}
}
window.onfocus = () => {
if (needsRefresh) {
needsRefresh = false;
window.location.reload();
}
}