WORK IN PROGRESS
This commit is contained in:
parent
b040c4da2f
commit
852e4db958
5 changed files with 21 additions and 17 deletions
|
@ -17,6 +17,7 @@ const data = localStorage.getItem('account');
|
|||
export const $i = data ? reactive(JSON.parse(data) as Account) : null;
|
||||
|
||||
export async function signout() {
|
||||
waiting();
|
||||
localStorage.removeItem('account');
|
||||
|
||||
//#region Remove account
|
||||
|
@ -42,7 +43,7 @@ export async function signout() {
|
|||
document.cookie = `igi=; path=/`;
|
||||
|
||||
if (accounts.length > 0) login(accounts[0].token);
|
||||
else location.href = '/';
|
||||
else unisonReload(true);
|
||||
}
|
||||
|
||||
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
|
||||
|
@ -92,16 +93,16 @@ export function refreshAccount() {
|
|||
return fetchAccount($i.token).then(updateAccount);
|
||||
}
|
||||
|
||||
export async function login(token: Account['token'], href?: string) {
|
||||
export async function login(token: Account['token'], redirect?: string) {
|
||||
waiting();
|
||||
if (_DEV_) console.log('logging as token ', token);
|
||||
const me = await fetchAccount(token);
|
||||
localStorage.setItem('account', JSON.stringify(me));
|
||||
await addAccount(me.id, token);
|
||||
|
||||
if (href) {
|
||||
if (redirect) {
|
||||
reloadChannel.postMessage('reload');
|
||||
location.href = href;
|
||||
location.href = redirect;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,14 +115,14 @@ export default defineComponent({
|
|||
|
||||
this.connection = os.stream.useSharedConnection('main');
|
||||
|
||||
// 既読処理
|
||||
// notification.isReadは更新しないので注意
|
||||
this.connection.on('readAllNotifications', () => {
|
||||
this.readObserver.unobserve(this.$el);
|
||||
this.notification = markNotificationRead(this.notification);
|
||||
});
|
||||
this.connection.on('readNotifications', notificationIds => {
|
||||
if (notificationIds.includes(this.notification.id)) {
|
||||
this.readObserver.unobserve(this.$el);
|
||||
this.notification = markNotificationRead(this.notification);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ import { search } from '@/scripts/search';
|
|||
import { isMobile } from '@/scripts/is-mobile';
|
||||
import { getThemes } from '@/theme-store';
|
||||
import { initializeSw } from '@/scripts/initialize-sw';
|
||||
import { reloadChannel } from '@/scripts/unison-reload';
|
||||
import { reload, reloadChannel } from '@/scripts/unison-reload';
|
||||
import { deleteLoginId } from '@/scripts/login-id';
|
||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||
|
||||
|
@ -120,7 +120,7 @@ if (defaultStore.state.reportError && !_DEV_) {
|
|||
document.addEventListener('touchend', () => {}, { passive: true });
|
||||
|
||||
// 一斉リロード
|
||||
reloadChannel.addEventListener('message', () => location.reload());
|
||||
reloadChannel.addEventListener('message', reload);
|
||||
|
||||
//#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
|
||||
// TODO: いつの日にか消したい
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
// SafariがBroadcastChannel未実装なのでライブラリを使う
|
||||
import { BroadcastChannel } from 'broadcast-channel';
|
||||
|
||||
export const reloadChannel = new BroadcastChannel<'reload'>('reload');
|
||||
export const reloadChannel = new BroadcastChannel<boolean>('reload');
|
||||
|
||||
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
|
||||
export function unisonReload() {
|
||||
reloadChannel.postMessage('reload');
|
||||
export function unisonReload(redirectToRoot?: boolean) {
|
||||
reloadChannel.postMessage(!!redirectToRoot);
|
||||
reload();
|
||||
}
|
||||
|
||||
export function reload(redirectToRoot?: boolean) {
|
||||
if (redirectToRoot) {
|
||||
location.href = '/';
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5042,11 +5042,6 @@ idb-keyval@5.0.2:
|
|||
resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.2.tgz#243cf2b7db1bee2a8a41b78c14a18a85db0e1646"
|
||||
integrity sha512-1DYjY/nX2U9pkTkwFoAmKcK1ZWmkNgO32Oon9tp/9+HURizxUQ4fZRxMJZs093SldP7q6dotVj03kIkiqOILyA==
|
||||
|
||||
idb-keyval@5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-5.0.1.tgz#d3913debfb58edee299da5cf2dded6c2670c05ef"
|
||||
integrity sha512-bfi+Znn6oSPPgGcVUj2tYMIOQ5TD6V1qj50SdKQecGZx9lqUATcQ7ArHOt9sPcEhACoYe//yr2igmS6SMc59SA==
|
||||
|
||||
ieee754@1.1.13, ieee754@^1.1.13, ieee754@^1.1.4:
|
||||
version "1.1.13"
|
||||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"
|
||||
|
|
Loading…
Reference in a new issue