From aa9a35474696e8513b5ddf0b734036a9dac97fc1 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 27 May 2020 12:54:52 -0700 Subject: [PATCH] Preload (#6062) --- demo/src/html/index.html.template | 13 +------------ src/entrypoints/core.ts | 6 ++++++ src/html/_preload_roboto.html.template | 16 ++++++++++++++++ src/html/authorize.html.template | 13 +------------ src/html/index.html.template | 20 ++++++-------------- src/html/onboarding.html.template | 13 +------------ src/layouts/home-assistant.ts | 13 ++++++++++++- 7 files changed, 43 insertions(+), 51 deletions(-) create mode 100644 src/html/_preload_roboto.html.template diff --git a/demo/src/html/index.html.template b/demo/src/html/index.html.template index dc3d4994e2..0b045fddd8 100644 --- a/demo/src/html/index.html.template +++ b/demo/src/html/index.html.template @@ -5,18 +5,6 @@ - - <%= renderTemplate('_js_base') %> + <%= renderTemplate('_preload_roboto') %> diff --git a/src/entrypoints/core.ts b/src/entrypoints/core.ts index dc2ee49e8b..8a6bedf9db 100644 --- a/src/entrypoints/core.ts +++ b/src/entrypoints/core.ts @@ -28,6 +28,7 @@ import { HomeAssistant } from "../types"; declare global { interface Window { hassConnection: Promise<{ auth: Auth; conn: Connection }>; + hassConnectionReady?: (hassConnection: Window["hassConnection"]) => void; } } @@ -82,6 +83,11 @@ window.hassConnection = (authProm() as Promise).then( connProm ); +// This is set if app was somehow loaded before core. +if (window.hassConnectionReady) { + window.hassConnectionReady(window.hassConnection); +} + // Start fetching some of the data that we will need. window.hassConnection.then(({ conn }) => { const noop = () => { diff --git a/src/html/_preload_roboto.html.template b/src/html/_preload_roboto.html.template new file mode 100644 index 0000000000..6ac777eb8e --- /dev/null +++ b/src/html/_preload_roboto.html.template @@ -0,0 +1,16 @@ + diff --git a/src/html/authorize.html.template b/src/html/authorize.html.template index f57c709147..3cbcfda5ce 100644 --- a/src/html/authorize.html.template +++ b/src/html/authorize.html.template @@ -3,18 +3,6 @@ Home Assistant - - <%= renderTemplate('_header') %>