enhane: 完全ログアウト時にすべてのタブがウェルカムページへ移動するように (#7928)

* enhane: unison-reloadに指定したパスに移動できるように

* null

* null

* null

* add comments
This commit is contained in:
tamaina 2021-11-05 00:09:13 +09:00 committed by GitHub
parent 1c38c7010d
commit e2862ed097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -61,7 +61,7 @@ export async function signout() {
document.cookie = `igi=; path=/`; document.cookie = `igi=; path=/`;
if (accounts.length > 0) login(accounts[0].token); if (accounts.length > 0) login(accounts[0].token);
else unisonReload(); else unisonReload('/');
} }
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> { 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); await addAccount(me.id, token);
if (redirect) { if (redirect) {
reloadChannel.postMessage('reload'); // 他のタブは再読み込みするだけ
reloadChannel.postMessage(null);
// このページはredirectで指定された先に移動
location.href = redirect; location.href = redirect;
return; return;
} }

View File

@ -93,7 +93,10 @@ if (defaultStore.state.reportError && !_DEV_) {
document.addEventListener('touchend', () => {}, { passive: true }); 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/ //#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
// TODO: いつの日にか消したい // TODO: いつの日にか消したい

View File

@ -1,10 +1,15 @@
// SafariがBroadcastChannel未実装なのでライブラリを使う // SafariがBroadcastChannel未実装なのでライブラリを使う
import { BroadcastChannel } from 'broadcast-channel'; import { BroadcastChannel } from 'broadcast-channel';
export const reloadChannel = new BroadcastChannel<'reload'>('reload'); export const reloadChannel = new BroadcastChannel<string | null>('reload');
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。 // BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
export function unisonReload() { export function unisonReload(path?: string) {
reloadChannel.postMessage('reload'); if (path !== undefined) {
reloadChannel.postMessage(path);
location.href = path;
} else {
reloadChannel.postMessage(null);
location.reload(); location.reload();
} }
}