From 34e2fe320d0f778d621a0683a9b54c03f1e1aae6 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 2 Dec 2023 00:07:13 +0800 Subject: [PATCH] Attempt to fix theme-color bug --- src/app.jsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/app.jsx b/src/app.jsx index 0fcf230..dc46bb4 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -187,6 +187,32 @@ setTimeout(() => { // ); })(); +// Possible fix for iOS PWA theme-color bug +// It changes when loading web pages in "webview" +const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); +if (isIOS) { + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible') { + // Get current color scheme + const colorScheme = window.matchMedia('(prefers-color-scheme: dark)') + .matches + ? 'dark' + : 'light'; + // Get current theme-color + const $meta = document.querySelector( + `meta[name="theme-color"][media*="${colorScheme}"]`, + ); + const color = $meta?.getAttribute('content'); + if (color) { + $meta.content = ''; + setTimeout(() => { + $meta.content = color; + }, 10); + } + } + }); +} + subscribe(states, (changes) => { for (const [action, path, value, prevValue] of changes) { // Change #app dataset based on settings.shortcutsViewMode