web/dialogs: add saving method dialog

This commit is contained in:
wukko
2024-07-27 15:07:26 +06:00
parent 7411f358d2
commit a9f9a3e342
7 changed files with 230 additions and 10 deletions

View File

@@ -1,9 +1,41 @@
import { device } from "$lib/device";
import { get } from "svelte/store";
import { app, device } from "$lib/device";
import settings from "$lib/state/settings";
import { createDialog } from "$lib/dialogs";
export const openURL = (url: string) => {
return window.open(url, "_blank");
}
export const shareURL = async (url: string) => {
try {
return await navigator?.share({ url });
} catch {
return false;
}
}
export const copyURL = async (url: string) => {
try {
return await navigator?.clipboard.writeText(url);
} catch {
return false;
}
}
export const downloadFile = (url: string) => {
if (device.is.iOS) {
return navigator?.share({ url }).catch(() => {});
const savingPreference = get(settings).save.downloadPopup;
if (savingPreference) {
createDialog({
type: "saving",
id: "saving",
url
})
} else if (device.is.iOS && app.is.installed) {
return shareURL(url);
} else {
return window.open(url, "_blank");
return openURL(url);
}
};
}