From e2862ed097a7de54a1a617f55dffee52a00010fc Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 5 Nov 2021 00:09:13 +0900 Subject: [PATCH] =?UTF-8?q?enhane:=20=E5=AE=8C=E5=85=A8=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A2=E3=82=A6=E3=83=88=E6=99=82=E3=81=AB=E3=81=99=E3=81=B9?= =?UTF-8?q?=E3=81=A6=E3=81=AE=E3=82=BF=E3=83=96=E3=81=8C=E3=82=A6=E3=82=A7?= =?UTF-8?q?=E3=83=AB=E3=82=AB=E3=83=A0=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=B8?= =?UTF-8?q?=E7=A7=BB=E5=8B=95=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(#7928)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhane: unison-reloadに指定したパスに移動できるように * null * null * null * add comments --- src/client/account.ts | 6 ++++-- src/client/init.ts | 5 ++++- src/client/scripts/unison-reload.ts | 13 +++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index a3fe082a2..a2165ebed 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -61,7 +61,7 @@ export async function signout() { document.cookie = `igi=; path=/`; if (accounts.length > 0) login(accounts[0].token); - else unisonReload(); + else unisonReload('/'); } export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> { @@ -122,7 +122,9 @@ export async function login(token: Account['token'], redirect?: string) { await addAccount(me.id, token); if (redirect) { - reloadChannel.postMessage('reload'); + // 他のタブは再読み込みするだけ + reloadChannel.postMessage(null); + // このページはredirectで指定された先に移動 location.href = redirect; return; } diff --git a/src/client/init.ts b/src/client/init.ts index 654e17639..81d17f0d2 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -93,7 +93,10 @@ if (defaultStore.state.reportError && !_DEV_) { document.addEventListener('touchend', () => {}, { passive: true }); // 一斉リロード -reloadChannel.addEventListener('message', () => location.reload()); +reloadChannel.addEventListener('message', path => { + if (path !== null) location.href = path; + else location.reload(); +}); //#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ // TODO: いつの日にか消したい diff --git a/src/client/scripts/unison-reload.ts b/src/client/scripts/unison-reload.ts index 92556aefa..59af584c1 100644 --- a/src/client/scripts/unison-reload.ts +++ b/src/client/scripts/unison-reload.ts @@ -1,10 +1,15 @@ // SafariがBroadcastChannel未実装なのでライブラリを使う import { BroadcastChannel } from 'broadcast-channel'; -export const reloadChannel = new BroadcastChannel<'reload'>('reload'); +export const reloadChannel = new BroadcastChannel('reload'); // BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。 -export function unisonReload() { - reloadChannel.postMessage('reload'); - location.reload(); +export function unisonReload(path?: string) { + if (path !== undefined) { + reloadChannel.postMessage(path); + location.href = path; + } else { + reloadChannel.postMessage(null); + location.reload(); + } }