From a7142f334c43df4b3c13f5a4d6a80e18acb1a495 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 14 Feb 2021 21:42:14 +0900 Subject: [PATCH] :v: --- src/client/init.ts | 4 ++++ src/client/scripts/unison-reload.ts | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client/init.ts b/src/client/init.ts index 17feca4c8b..748090b9da 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -58,6 +58,7 @@ import { makeHotkey } from './scripts/hotkey'; import { search } from './scripts/search'; import { getThemes } from './theme-store'; import { initializeSw } from './scripts/initialize-sw'; +import { reloadChannel } from './scripts/unison-reload'; console.info(`Misskey v${version}`); @@ -105,6 +106,9 @@ if (defaultStore.state.reportError && !_DEV_) { // タッチデバイスでCSSの:hoverを機能させる document.addEventListener('touchend', () => {}, { passive: true }); +// 一斉リロード +reloadChannel.addEventListener('message', () => location.reload()); + //#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ // TODO: いつの日にか消したい const vh = window.innerHeight * 0.01; diff --git a/src/client/scripts/unison-reload.ts b/src/client/scripts/unison-reload.ts index f55b9588be..f1e32d1d93 100644 --- a/src/client/scripts/unison-reload.ts +++ b/src/client/scripts/unison-reload.ts @@ -1,12 +1,10 @@ // SafariがBroadcastChannel未実装なのでライブラリを使う import { BroadcastChannel } from 'broadcast-channel'; -const ch = new BroadcastChannel('reload'); +export const reloadChannel = new BroadcastChannel<'reload'>('reload'); // BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。 -export function unisonReload(forcedReload?: boolean) { - ch.postMessage(forcedReload); - location.reload(forcedReload as boolean); +export function unisonReload() { + reloadChannel.postMessage('reload'); + location.reload(); } - -ch.addEventListener('message', forcedReload => location.reload(forcedReload as boolean));