31 lines
617 B
TypeScript
31 lines
617 B
TypeScript
type DownloadDialogState = {
|
|
isOpen: boolean;
|
|
url: string | null;
|
|
};
|
|
|
|
let state: DownloadDialogState = { isOpen: false, url: null };
|
|
const listeners = new Set<() => void>();
|
|
|
|
function emit() {
|
|
listeners.forEach((l) => l());
|
|
}
|
|
|
|
export function subscribeDownloadDialog(listener: () => void) {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
}
|
|
|
|
export function getDownloadDialogState() {
|
|
return state;
|
|
}
|
|
|
|
export function openDownloadDialog(url: string | null) {
|
|
state = { isOpen: true, url };
|
|
emit();
|
|
}
|
|
|
|
export function closeDownloadDialog() {
|
|
state = { isOpen: false, url: null };
|
|
emit();
|
|
}
|