From f0d3b2b4f6d61aefcb879637f4a7caab5a45c379 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 3 Dec 2019 22:33:20 -0700 Subject: [PATCH] Change statusbar color on dark theme --- www/js/main.js | 6 ++---- www/js/platform.js | 23 +++++++++++++++++++++++ www/js/settings.js | 6 +----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/www/js/main.js b/www/js/main.js index 1513326..690ce0c 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -62,13 +62,11 @@ router.on("pageInit", function (pagedata) { } }); -if (localStorage.getItem("darktheme") == "true") { - $("#app").addClass("theme-dark"); -} - // Run platform-specific setup code for Cordova or NW.js initPlatform(); +// Switch to dark theme if requested by user setting +setAppTheme(); if (localStorage.getItem("configured") == null) { // Open the setup page diff --git a/www/js/platform.js b/www/js/platform.js index e694aec..9c07b90 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -22,6 +22,14 @@ var removeTrayMenu = function () { } +var setAppTheme = function () { + if (localStorage.getItem("darktheme") == "true") { + $("#app").addClass("theme-dark"); + } else { + $("#app").removeClass("theme-dark"); + } +} + function initCordova() { platform_type = "cordova"; @@ -46,6 +54,21 @@ function initCordova() { openBrowser = function (url) { cordova.InAppBrowser.open(url, '_blank', 'location=yes'); } + + setAppTheme = function () { + if (localStorage.getItem("darktheme") == "true") { + $("#app").addClass("theme-dark"); + if (cordova.platformId == 'android') { + StatusBar.styleDefault(); + } + } else { + $("#app").removeClass("theme-dark"); + if (cordova.platformId == 'android') { + StatusBar.backgroundColorByHexString("#D32F2F"); + StatusBar.styleLightContent(); + } + } + } } function initNW() { diff --git a/www/js/settings.js b/www/js/settings.js index 16f2871..346adac 100644 --- a/www/js/settings.js +++ b/www/js/settings.js @@ -14,9 +14,5 @@ $('.item-content[data-setting=darktheme] .toggle input').on("change", function ( var checked = $(this).prop('checked'); localStorage.setItem("darktheme", checked); - if (localStorage.getItem("darktheme") == "true") { - $("#app").addClass("theme-dark"); - } else { - $("#app").removeClass("theme-dark"); - } + setAppTheme(); }); \ No newline at end of file