Fix media downloads for Home Assistant companion apps.

This commit is contained in:
Dermot Duffy
2021-11-26 22:02:55 -08:00
parent 144fb567d3
commit 3e7e8d2d41
+12 -2
View File
@@ -603,13 +603,23 @@ export class FrigateCard extends LitElement {
return;
}
// Use the HTML5 download attribute to prevent a new window from temporarily
// opening.
if (navigator.userAgent.startsWith("Home Assistant/")) {
// Home Assistant companion apps cannot download files without opening a
// new browser window.
//
// User-agents are specified here:
// - Android: https://github.com/home-assistant/android/blob/master/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt#L107
// - iOS: https://github.com/home-assistant/iOS/blob/master/Sources/Shared/API/HAAPI.swift#L75
window.open(response, '_blank');
} else {
// Use the HTML5 download attribute to prevent a new window from
// temporarily opening.
const link = document.createElement('a');
link.setAttribute('download', '');
link.href = response;
link.click();
link.remove();
}{}
}
/**