Added code to dismiss the reload dialogue on reconnect.

This commit is contained in:
Werner Kroneman 2024-12-07 15:33:43 +01:00
parent 88c8478f8c
commit 7ad73fedfb

View file

@ -8,7 +8,7 @@ import {common} from './common.js';
import type * as Misskey from 'misskey-js';
import {ui} from '@@/js/config.js';
import {i18n} from '@/i18n.js';
import {alert, popup, post} from '@/os.js';
import {alert, popup, post, toast} from '@/os.js';
import {useStream} from '@/stream.js';
import * as sound from '@/scripts/sound.js';
import {$i, signout, updateAccount} from '@/account.js';
@ -27,6 +27,7 @@ import {addCustomEmoji, removeCustomEmojis, updateCustomEmojis} from '@/custom-e
import MkDialog from "@/components/MkDialog.vue";
export async function mainBoot() {
const { isClientUpdated } = await common(() => createApp(
new URLSearchParams(window.location.search).has('zen') || (ui === 'deck' && deckStore.state.useSimpleUiForNonRootPages && location.pathname !== '/') ? defineAsyncComponent(() => import('@/ui/zen.vue')) :
!$i ? defineAsyncComponent(() => import('@/ui/visitor.vue')) :
@ -46,25 +47,45 @@ export async function mainBoot() {
const stream = useStream();
let reloadDialogShowing = false;
// A reference to the function to close the "reconnecting" dialog; null if the dialog is not open.
let reloadDialogDisposeFn : Function | null = null;
// When the stream is disconnected, show a dialog to reload the page.
stream.on('_disconnected_', async () => {
// TODO: Where's that setting?
if (defaultStore.state.serverDisconnectedBehavior === 'dialog') {
if (reloadDialogShowing) return;
reloadDialogShowing = true;
// If the dialog is already open, do nothing.
if (reloadDialogDisposeFn) return;
// Show a popup dialog with a warning message and a "reload" button.
const {dispose} = popup(MkDialog, {
...({
type: 'warning',
title: i18n.ts.disconnectedFromServer,
text: i18n.ts.reloadConfirm,
}),
showCancelButton: true,
showCancelButton: true, // Show a "cancel" button; this dismisses the dialog without reloading the page.
}, {
// If the user clicks one of the buttons, and it's the "positive" button (in this case, the "reload" button),
done: result => {
if (!result) location.reload();
},
// If the dialog is closed, dispose of the dialog.
closed: () => dispose(),
});
reloadDialogShowing = false;
// Save the function to close the dialog so that it can be called later.
reloadDialogDisposeFn = dispose;
}
});
// When the stream is (re)connected, close the "reconnecting" dialog if it's open.
stream.on('_connected_', () => {
if (reloadDialogDisposeFn) {
reloadDialogDisposeFn();
reloadDialogDisposeFn = null;
toast("Reconnected to server.");
}
});