mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Fix downloads on mobile (#9375)
This commit is contained in:
parent
1e6e99e3c7
commit
342020b420
@ -22,6 +22,7 @@ import {
|
|||||||
import { HassDialog } from "../../../../src/dialogs/make-dialog-manager";
|
import { HassDialog } from "../../../../src/dialogs/make-dialog-manager";
|
||||||
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
||||||
import { HomeAssistant } from "../../../../src/types";
|
import { HomeAssistant } from "../../../../src/types";
|
||||||
|
import { fileDownload } from "../../../../src/util/file_download";
|
||||||
import "../../components/supervisor-snapshot-content";
|
import "../../components/supervisor-snapshot-content";
|
||||||
import type { SupervisorSnapshotContent } from "../../components/supervisor-snapshot-content";
|
import type { SupervisorSnapshotContent } from "../../components/supervisor-snapshot-content";
|
||||||
import { HassioSnapshotDialogParams } from "./show-dialog-hassio-snapshot";
|
import { HassioSnapshotDialogParams } from "./show-dialog-hassio-snapshot";
|
||||||
@ -288,12 +289,11 @@ class HassioSnapshotDialog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const a = document.createElement("a");
|
fileDownload(
|
||||||
a.href = signedPath.path;
|
this,
|
||||||
a.download = `home_assistant_snapshot_${slugify(this._computeName)}.tar`;
|
signedPath.path,
|
||||||
this.shadowRoot!.appendChild(a);
|
`home_assistant_snapshot_${slugify(this._computeName)}.tar`
|
||||||
a.click();
|
);
|
||||||
this.shadowRoot!.removeChild(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _computeName() {
|
private get _computeName() {
|
||||||
|
@ -7,14 +7,14 @@ import { afterNextRender } from "../common/util/render-status";
|
|||||||
import { FrontendLocaleData } from "../data/translation";
|
import { FrontendLocaleData } from "../data/translation";
|
||||||
import { getValueInPercentage, normalize } from "../util/calculate";
|
import { getValueInPercentage, normalize } from "../util/calculate";
|
||||||
|
|
||||||
|
// Workaround for https://github.com/home-assistant/frontend/issues/6467
|
||||||
|
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||||
|
|
||||||
const getAngle = (value: number, min: number, max: number) => {
|
const getAngle = (value: number, min: number, max: number) => {
|
||||||
const percentage = getValueInPercentage(normalize(value, min, max), min, max);
|
const percentage = getValueInPercentage(normalize(value, min, max), min, max);
|
||||||
return (percentage * 180) / 100;
|
return (percentage * 180) / 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Workaround for https://github.com/home-assistant/frontend/issues/6467
|
|
||||||
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
||||||
|
|
||||||
@customElement("ha-gauge")
|
@customElement("ha-gauge")
|
||||||
export class Gauge extends LitElement {
|
export class Gauge extends LitElement {
|
||||||
@property({ type: Number }) public min = 0;
|
@property({ type: Number }) public min = 0;
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
import "../../../../../layouts/hass-tabs-subpage";
|
import "../../../../../layouts/hass-tabs-subpage";
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../../../types";
|
import type { HomeAssistant, Route } from "../../../../../types";
|
||||||
|
import { fileDownload } from "../../../../../util/file_download";
|
||||||
import "../../../ha-config-section";
|
import "../../../ha-config-section";
|
||||||
import { showZWaveJSAddNodeDialog } from "./show-dialog-zwave_js-add-node";
|
import { showZWaveJSAddNodeDialog } from "./show-dialog-zwave_js-add-node";
|
||||||
import { showZWaveJSRemoveNodeDialog } from "./show-dialog-zwave_js-remove-node";
|
import { showZWaveJSRemoveNodeDialog } from "./show-dialog-zwave_js-remove-node";
|
||||||
@ -312,12 +313,7 @@ class ZWaveJSConfigDashboard extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const a = document.createElement("a");
|
fileDownload(this, signedPath.path, `zwave_js_dump.jsonl`);
|
||||||
a.href = signedPath.path;
|
|
||||||
a.download = `zwave_js_dump.jsonl`;
|
|
||||||
this.shadowRoot!.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
this.shadowRoot!.removeChild(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
const isSafari14 = /^((?!chrome|android).)*version\/14\.0\s.*safari/i.test(
|
const isSafari14 = /^((?!chrome|android).)*version\/14\.0\s.*safari/i.test(
|
||||||
navigator.userAgent
|
navigator.userAgent
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSafari14) {
|
if (isSafari14) {
|
||||||
const origAttachShadow = window.Element.prototype.attachShadow;
|
const origAttachShadow = window.Element.prototype.attachShadow;
|
||||||
window.Element.prototype.attachShadow = function (init) {
|
window.Element.prototype.attachShadow = function (init) {
|
||||||
|
14
src/util/file_download.ts
Normal file
14
src/util/file_download.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export const fileDownload = (
|
||||||
|
element: HTMLElement,
|
||||||
|
href: string,
|
||||||
|
filename: string
|
||||||
|
): void => {
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.target = "_blank";
|
||||||
|
a.href = href;
|
||||||
|
a.download = filename;
|
||||||
|
|
||||||
|
element.shadowRoot!.appendChild(a);
|
||||||
|
a.dispatchEvent(new MouseEvent("click"));
|
||||||
|
element.shadowRoot!.removeChild(a);
|
||||||
|
};
|
0
src/util/is_safari.ts
Normal file
0
src/util/is_safari.ts
Normal file
Loading…
x
Reference in New Issue
Block a user