2024-07-27 10:07:26 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 09:33:43 +01:00
|
|
|
|
|
|
|
export const downloadFile = (url: string) => {
|
2024-07-27 10:07:26 +01:00
|
|
|
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);
|
2024-07-22 09:33:43 +01:00
|
|
|
} else {
|
2024-07-27 10:07:26 +01:00
|
|
|
return openURL(url);
|
2024-07-22 09:33:43 +01:00
|
|
|
}
|
2024-07-27 10:07:26 +01:00
|
|
|
}
|