summaryrefslogtreecommitdiff
path: root/packages/frontend/src/utility/reload-ask.ts
blob: f49de80231d9fefe126ee8f3e07bac49f92087bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
import { unisonReload } from '@/utility/unison-reload.js';

let isReloadConfirming = false;

export async function reloadAsk(opts: {
	unison?: boolean;
	reason?: string;
	type?: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question';
	title?: string;
	okText?: string;
	cancelText?: string;
}) {
	if (isReloadConfirming) {
		return;
	}

	isReloadConfirming = true;

	const { canceled } = await os.confirm({
		type: opts.type ?? 'question',
		title: opts.title ?? i18n.ts.reloadConfirm,
		text: opts.reason ?? undefined,
		okText: opts.okText ?? i18n.ts.yes,
		cancelText: opts.cancelText ?? i18n.ts.no,
	}).finally(() => {
		isReloadConfirming = false;
	});

	if (canceled) return;

	if (opts.unison) {
		unisonReload();
	} else {
		window.location.reload();
	}
}