From 56386b74d04f5723d1b3ac209cc81ab48a1a1e7e Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 29 Oct 2021 00:28:25 +0900 Subject: [PATCH] =?UTF-8?q?enhane:=20unison-reload=E3=81=AB=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E3=81=97=E3=81=9F=E3=83=91=E3=82=B9=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E5=8B=95=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/account.ts | 2 +- src/client/init.ts | 5 ++++- src/client/scripts/unison-reload.ts | 13 +++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index a3fe082a22..63c68487fc 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'] }[]> { diff --git a/src/client/init.ts b/src/client/init.ts index 123d4020e1..37bfbc4f6a 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -91,7 +91,10 @@ if (defaultStore.state.reportError && !_DEV_) { document.addEventListener('touchend', () => {}, { passive: true }); // 一斉リロード -reloadChannel.addEventListener('message', () => location.reload()); +reloadChannel.addEventListener('message', path => { + if (path === 'reload') location.reload(); + else location.href = path; +}); //#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 92556aefaa..745a0a7a1d 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('reload'); + location.reload(); + } }