mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-29 11:06:10 +00:00
web/download: show explanation when getting blocked by browser
This commit is contained in:
parent
5c780a2d2e
commit
97e7763503
|
@ -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.",
|
"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.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",
|
"safety.title": "important safety notice",
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
|
|
||||||
import { app, device } from "$lib/device";
|
import { device } from "$lib/device";
|
||||||
import { copyURL, openURL, shareURL } from "$lib/download";
|
import { copyURL, openURL, shareURL } from "$lib/download";
|
||||||
|
|
||||||
import DialogContainer from "$components/dialog/DialogContainer.svelte";
|
import DialogContainer from "$components/dialog/DialogContainer.svelte";
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
export let url: string;
|
export let url: string;
|
||||||
|
export let bodyText: string = "";
|
||||||
|
|
||||||
let close: () => void;
|
let close: () => void;
|
||||||
</script>
|
</script>
|
||||||
|
@ -69,6 +70,9 @@
|
||||||
</VerticalActionButton>
|
</VerticalActionButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="body-text">
|
||||||
|
{bodyText}
|
||||||
|
</div>
|
||||||
<DialogButtons
|
<DialogButtons
|
||||||
buttons={[
|
buttons={[
|
||||||
{
|
{
|
||||||
|
@ -97,7 +101,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.popup-body {
|
.popup-body {
|
||||||
text-align: center;
|
|
||||||
max-width: 340px;
|
max-width: 340px;
|
||||||
width: calc(100% - var(--padding) - var(--dialog-padding) * 2);
|
width: calc(100% - var(--padding) - var(--dialog-padding) * 2);
|
||||||
max-height: 50%;
|
max-height: 50%;
|
||||||
|
@ -140,4 +143,14 @@
|
||||||
gap: calc(var(--padding) / 2);
|
gap: calc(var(--padding) / 2);
|
||||||
overflow-x: scroll;
|
overflow-x: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.body-text {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--gray);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
user-select: text;
|
||||||
|
-webkit-user-select: text;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
import { device } from "$lib/device";
|
|
||||||
import settings from "$lib/state/settings";
|
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) =>
|
import { createDialog } from "$lib/dialogs";
|
||||||
createDialog({
|
import type { DialogInfo } from "$lib/types/dialog";
|
||||||
|
|
||||||
|
export const openSavingDialog = (url: string, body: string | void) => {
|
||||||
|
let dialogData: DialogInfo = {
|
||||||
type: "saving",
|
type: "saving",
|
||||||
id: "saving",
|
id: "saving",
|
||||||
url
|
url
|
||||||
})
|
}
|
||||||
|
if (body) dialogData.bodyText = body;
|
||||||
|
|
||||||
|
createDialog(dialogData)
|
||||||
|
}
|
||||||
|
|
||||||
export const openURL = (url: string) => {
|
export const openURL = (url: string) => {
|
||||||
const open = window.open(url, "_blank");
|
const open = window.open(url, "_blank");
|
||||||
|
|
||||||
/* if new tab got blocked by user agent, show a saving dialog */
|
/* if new tab got blocked by user agent, show a saving dialog */
|
||||||
if (!open) {
|
if (!open) {
|
||||||
return openSavingDialog(url);
|
return openSavingDialog(url, get(t)("dialog.saving.blocked"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ type PickerDialog = Dialog & {
|
||||||
type SavingDialog = Dialog & {
|
type SavingDialog = Dialog & {
|
||||||
type: "saving",
|
type: "saving",
|
||||||
url: string,
|
url: string,
|
||||||
|
bodyText?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DialogInfo = SmallDialog | PickerDialog | SavingDialog;
|
export type DialogInfo = SmallDialog | PickerDialog | SavingDialog;
|
||||||
|
|
Loading…
Reference in a new issue