This commit is contained in:
syuilo 2025-03-27 09:28:29 +09:00
parent ed86b1706d
commit 0a4642addd
8 changed files with 112 additions and 110 deletions

View File

@ -82,39 +82,6 @@ export async function mainBoot() {
}
}
const stream = useStream();
let reloadDialogShowing = false;
stream.on('_disconnected_', async () => {
if (prefer.s.serverDisconnectedBehavior === 'reload') {
window.location.reload();
} else if (prefer.s.serverDisconnectedBehavior === 'dialog') {
if (reloadDialogShowing) return;
reloadDialogShowing = true;
const { canceled } = await confirm({
type: 'warning',
title: i18n.ts.disconnectedFromServer,
text: i18n.ts.reloadConfirm,
});
reloadDialogShowing = false;
if (!canceled) {
window.location.reload();
}
}
});
stream.on('emojiAdded', emojiData => {
addCustomEmoji(emojiData.emoji);
});
stream.on('emojiUpdated', emojiData => {
updateCustomEmojis(emojiData.emojis);
});
stream.on('emojiDeleted', emojiData => {
removeCustomEmojis(emojiData.emojis);
});
launchPlugins();
try {
@ -172,8 +139,6 @@ export async function mainBoot() {
}
}
stream.on('announcementCreated', onAnnouncementCreated);
if ($i.isDeleted) {
alert({
type: 'warning',
@ -351,50 +316,87 @@ export async function mainBoot() {
}
}
const main = markRaw(stream.useChannel('main', null, 'System'));
if (store.s.realtimeMode) {
const stream = useStream();
// 自分の情報が更新されたとき
main.on('meUpdated', i => {
updateCurrentAccountPartial(i);
});
main.on('readAllNotifications', () => {
updateCurrentAccountPartial({
hasUnreadNotification: false,
unreadNotificationsCount: 0,
let reloadDialogShowing = false;
stream.on('_disconnected_', async () => {
if (prefer.s.serverDisconnectedBehavior === 'reload') {
window.location.reload();
} else if (prefer.s.serverDisconnectedBehavior === 'dialog') {
if (reloadDialogShowing) return;
reloadDialogShowing = true;
const { canceled } = await confirm({
type: 'warning',
title: i18n.ts.disconnectedFromServer,
text: i18n.ts.reloadConfirm,
});
reloadDialogShowing = false;
if (!canceled) {
window.location.reload();
}
}
});
});
main.on('unreadNotification', () => {
const unreadNotificationsCount = ($i?.unreadNotificationsCount ?? 0) + 1;
updateCurrentAccountPartial({
hasUnreadNotification: true,
unreadNotificationsCount,
stream.on('emojiAdded', emojiData => {
addCustomEmoji(emojiData.emoji);
});
});
main.on('unreadAntenna', () => {
updateCurrentAccountPartial({ hasUnreadAntenna: true });
sound.playMisskeySfx('antenna');
});
stream.on('emojiUpdated', emojiData => {
updateCustomEmojis(emojiData.emojis);
});
main.on('newChatMessage', () => {
updateCurrentAccountPartial({ hasUnreadChatMessages: true });
sound.playMisskeySfx('chatMessage');
});
stream.on('emojiDeleted', emojiData => {
removeCustomEmojis(emojiData.emojis);
});
main.on('readAllAnnouncements', () => {
updateCurrentAccountPartial({ hasUnreadAnnouncement: false });
});
stream.on('announcementCreated', onAnnouncementCreated);
// 個人宛てお知らせが発行されたとき
main.on('announcementCreated', onAnnouncementCreated);
const main = markRaw(stream.useChannel('main', null, 'System'));
// トークンが再生成されたとき
// このままではMisskeyが利用できないので強制的にサインアウトさせる
main.on('myTokenRegenerated', () => {
signout();
});
// 自分の情報が更新されたとき
main.on('meUpdated', i => {
updateCurrentAccountPartial(i);
});
main.on('readAllNotifications', () => {
updateCurrentAccountPartial({
hasUnreadNotification: false,
unreadNotificationsCount: 0,
});
});
main.on('unreadNotification', () => {
const unreadNotificationsCount = ($i?.unreadNotificationsCount ?? 0) + 1;
updateCurrentAccountPartial({
hasUnreadNotification: true,
unreadNotificationsCount,
});
});
main.on('unreadAntenna', () => {
updateCurrentAccountPartial({ hasUnreadAntenna: true });
sound.playMisskeySfx('antenna');
});
main.on('newChatMessage', () => {
updateCurrentAccountPartial({ hasUnreadChatMessages: true });
sound.playMisskeySfx('chatMessage');
});
main.on('readAllAnnouncements', () => {
updateCurrentAccountPartial({ hasUnreadAnnouncement: false });
});
// 個人宛てお知らせが発行されたとき
main.on('announcementCreated', onAnnouncementCreated);
// トークンが再生成されたとき
// このままではMisskeyが利用できないので強制的にサインアウトさせる
main.on('myTokenRegenerated', () => {
signout();
});
}
}
// shortcut

View File

@ -36,6 +36,7 @@ import { i18n } from '@/i18n.js';
import { infoImageUrl } from '@/instance.js';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import { prefer } from '@/preferences.js';
import { store } from '@/store.js';
const props = defineProps<{
excludeTypes?: typeof notificationTypes[number][];
@ -60,7 +61,9 @@ const pagination = computed(() => prefer.r.useGroupedNotifications.value ? {
function onNotification(notification) {
const isMuted = props.excludeTypes ? props.excludeTypes.includes(notification.type) : false;
if (isMuted || window.document.visibilityState === 'visible') {
useStream().send('readNotification');
if (store.s.realtimeMode) {
useStream().send('readNotification');
}
}
if (!isMuted) {
@ -76,19 +79,22 @@ function reload() {
});
}
let connection: Misskey.ChannelConnection<Misskey.Channels['main']>;
let connection: Misskey.ChannelConnection<Misskey.Channels['main']> | null = null;
onMounted(() => {
connection = useStream().useChannel('main');
connection.on('notification', onNotification);
connection.on('notificationFlushed', reload);
if (store.s.realtimeMode) {
connection = useStream().useChannel('main');
connection.on('notification', onNotification);
connection.on('notificationFlushed', reload);
}
});
onActivated(() => {
pagingComponent.value?.reload();
connection = useStream().useChannel('main');
connection.on('notification', onNotification);
connection.on('notificationFlushed', reload);
if (store.s.realtimeMode) {
connection = useStream().useChannel('main');
connection.on('notification', onNotification);
connection.on('notificationFlushed', reload);
}
});
onUnmounted(() => {

View File

@ -28,6 +28,7 @@ import * as sound from '@/utility/sound.js';
import { $i } from '@/i.js';
import { instance } from '@/instance.js';
import { prefer } from '@/preferences.js';
import { store } from '@/store.js';
const props = withDefaults(defineProps<{
src: BasicTimelineType | 'mentions' | 'directs' | 'list' | 'antenna' | 'channel' | 'role';
@ -94,7 +95,7 @@ let connection: Misskey.ChannelConnection | null = null;
let connection2: Misskey.ChannelConnection | null = null;
let paginationQuery: Paging | null = null;
const stream = useStream();
const stream = store.s.realtimeMode ? useStream() : null;
function connectChannel() {
if (props.src === 'antenna') {
@ -239,7 +240,7 @@ function updatePaginationQuery() {
}
function refreshEndpointAndChannel() {
if (!prefer.s.disableStreamingTimeline) {
if (!prefer.s.disableStreamingTimeline && store.s.realtimeMode) {
disconnectChannel();
connectChannel();
}

View File

@ -12,7 +12,6 @@ import { $i } from '@/i.js';
import { misskeyApi } from '@/utility/misskey-api.js';
import { get, set } from '@/utility/idb-proxy.js';
import { store } from '@/store.js';
import { useStream } from '@/stream.js';
import { deepClone } from '@/utility/clone.js';
import { deepMerge } from '@/utility/merge.js';
@ -129,25 +128,6 @@ export class Pizzax<T extends StateDef> {
if (where === 'deviceAccount' && !($i && userId !== $i.id)) return;
this.r[key].value = this.s[key] = value;
});
if ($i) {
const connection = useStream().useChannel('main');
// streamingのuser storage updateイベントを監視して更新
connection.on('registryUpdated', ({ scope, key, value }: { scope?: string[], key: keyof T, value: T[typeof key]['default'] }) => {
if (!scope || scope.length !== 2 || scope[0] !== 'client' || scope[1] !== this.key || this.s[key] === value) return;
this.r[key].value = this.s[key] = value;
this.addIdbSetJob(async () => {
const cache = await get(this.registryCacheKeyName);
if (cache[key] !== value) {
cache[key] = value;
await set(this.registryCacheKeyName, cache);
}
});
});
}
}
private load(): Promise<void> {

View File

@ -76,6 +76,10 @@ export const store = markRaw(new Pizzax('base', {
where: 'device',
default: false,
},
realtimeMode: {
where: 'device',
default: false,
},
recentlyUsedEmojis: {
where: 'device',
default: [] as string[],

View File

@ -58,6 +58,7 @@ import { useStream } from '@/stream.js';
import { i18n } from '@/i18n.js';
import { prefer } from '@/preferences.js';
import { globalEvents } from '@/events.js';
import { store } from '@/store.js';
const XStreamIndicator = defineAsyncComponent(() => import('./stream-indicator.vue'));
const XUpload = defineAsyncComponent(() => import('./upload.vue'));
@ -70,7 +71,9 @@ function onNotification(notification: Misskey.entities.Notification, isClient =
if (window.document.visibilityState === 'visible') {
if (!isClient && notification.type !== 'test') {
//
useStream().send('readNotification');
if (store.s.realtimeMode) {
useStream().send('readNotification');
}
}
notifications.value.unshift(notification);
@ -87,8 +90,10 @@ function onNotification(notification: Misskey.entities.Notification, isClient =
}
if ($i) {
const connection = useStream().useChannel('main', null, 'UI');
connection.on('notification', onNotification);
if (store.s.realtimeMode) {
const connection = useStream().useChannel('main', null, 'UI');
connection.on('notification', onNotification);
}
globalEvents.on('clientNotification', notification => onNotification(notification, true));
//#region Listen message from SW

View File

@ -20,6 +20,7 @@ import { i18n } from '@/i18n.js';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os.js';
import { prefer } from '@/preferences.js';
import { store } from '@/store.js';
const zIndex = os.claimZIndex('high');
@ -37,11 +38,13 @@ function reload() {
window.location.reload();
}
useStream().on('_disconnected_', onDisconnected);
if (store.s.realtimeMode) {
useStream().on('_disconnected_', onDisconnected);
onUnmounted(() => {
useStream().off('_disconnected_', onDisconnected);
});
onUnmounted(() => {
useStream().off('_disconnected_', onDisconnected);
});
}
</script>
<style lang="scss" module>

View File

@ -4,10 +4,11 @@
*/
import { onUnmounted } from 'vue';
import type { Ref, ShallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import type { Ref, ShallowRef } from 'vue';
import { useStream } from '@/stream.js';
import { $i } from '@/i.js';
import { store } from '@/store.js';
export function useNoteCapture(props: {
rootEl: ShallowRef<HTMLElement | undefined>;
@ -17,7 +18,7 @@ export function useNoteCapture(props: {
}) {
const note = props.note;
const pureNote = props.pureNote;
const connection = $i ? useStream() : null;
const connection = $i && store.s.realtimeMode ? useStream() : null;
function onStreamNoteUpdated(noteData): void {
const { type, id, body } = noteData;