From 97e77635033dae777194cf0e9238971f88543e58 Mon Sep 17 00:00:00 2001 From: wukko Date: Sun, 28 Jul 2024 19:15:22 +0600 Subject: [PATCH] web/download: show explanation when getting blocked by browser --- web/i18n/en/dialog.json | 1 + web/src/components/dialog/SavingDialog.svelte | 17 +++++++++++++++-- web/src/lib/download.ts | 19 +++++++++++++------ web/src/lib/types/dialog.ts | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/web/i18n/en/dialog.json b/web/i18n/en/dialog.json index 4a993528..13b5cf3e 100644 --- a/web/i18n/en/dialog.json +++ b/web/i18n/en/dialog.json @@ -18,6 +18,7 @@ "picker.description.ios": "press an item to save it with a shortcut. images can also be saved with a long press.", "saving.title": "choose how to save", + "saving.blocked": "cobalt tried opening the file in a new tab, but your browser blocked it. you can allow pop-ups for cobalt to prevent this from happening next time.", "safety.title": "important safety notice", diff --git a/web/src/components/dialog/SavingDialog.svelte b/web/src/components/dialog/SavingDialog.svelte index 5e1832ab..4940af3c 100644 --- a/web/src/components/dialog/SavingDialog.svelte +++ b/web/src/components/dialog/SavingDialog.svelte @@ -1,7 +1,7 @@ @@ -69,6 +70,9 @@ +
+ {bodyText} +
diff --git a/web/src/lib/download.ts b/web/src/lib/download.ts index fbd3a124..60227f21 100644 --- a/web/src/lib/download.ts +++ b/web/src/lib/download.ts @@ -1,23 +1,30 @@ import { get } from "svelte/store"; -import { device } from "$lib/device"; import settings from "$lib/state/settings"; -import { createDialog } from "$lib/dialogs"; +import { device } from "$lib/device"; +import { t } from "$lib/i18n/translations"; -export const openSavingDialog = (url: string) => - createDialog({ +import { createDialog } from "$lib/dialogs"; +import type { DialogInfo } from "$lib/types/dialog"; + +export const openSavingDialog = (url: string, body: string | void) => { + let dialogData: DialogInfo = { type: "saving", id: "saving", url - }) + } + if (body) dialogData.bodyText = body; + + createDialog(dialogData) +} export const openURL = (url: string) => { const open = window.open(url, "_blank"); /* if new tab got blocked by user agent, show a saving dialog */ if (!open) { - return openSavingDialog(url); + return openSavingDialog(url, get(t)("dialog.saving.blocked")); } } diff --git a/web/src/lib/types/dialog.ts b/web/src/lib/types/dialog.ts index 0a5004db..d3d086e1 100644 --- a/web/src/lib/types/dialog.ts +++ b/web/src/lib/types/dialog.ts @@ -39,6 +39,7 @@ type PickerDialog = Dialog & { type SavingDialog = Dialog & { type: "saving", url: string, + bodyText?: string, }; export type DialogInfo = SmallDialog | PickerDialog | SavingDialog;