mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-10 03:52:57 +00:00
32 lines
685 B
TypeScript
32 lines
685 B
TypeScript
import ConfirmDialog from "$lib/dialogs/ConfirmDialog.svelte"
|
|
|
|
export async function askForConfirmation(
|
|
title: string,
|
|
message: string,
|
|
confirmTitle: string,
|
|
abortTitle: string,
|
|
): Promise<boolean> {
|
|
const dialog = new ConfirmDialog({
|
|
target: document.body,
|
|
props: {
|
|
title,
|
|
message,
|
|
confirmTitle,
|
|
abortTitle,
|
|
},
|
|
})
|
|
|
|
let resolvePromise: (value: boolean) => void
|
|
const resultPromise = new Promise<boolean>(resolve => {
|
|
resolvePromise = resolve
|
|
})
|
|
|
|
dialog.$on("abort", () => resolvePromise(false))
|
|
dialog.$on("confirm", () => resolvePromise(true))
|
|
|
|
const result = await resultPromise
|
|
dialog.$destroy()
|
|
|
|
return result
|
|
}
|