From de7f90bd353d6d2a36fb6729c9b5d32a327eda52 Mon Sep 17 00:00:00 2001 From: zombieFox Date: Wed, 5 Aug 2020 09:52:14 +0100 Subject: [PATCH] [refactor] improve initial page colour when switching to automatic theme style --- package-lock.json | 2 +- package.json | 2 +- src/js/theme.js | 26 ++++++++++++++++++++++---- src/js/version.js | 2 +- src/manifest.json | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35a74900..6acd92e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nightTab", - "version": "5.79.0", + "version": "5.80.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 10cd4e1a..c397d167 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightTab", - "version": "5.79.0", + "version": "5.80.0", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", "main": "index.js", "scripts": { diff --git a/src/js/theme.js b/src/js/theme.js index 61a8bb13..11821931 100644 --- a/src/js/theme.js +++ b/src/js/theme.js @@ -124,8 +124,24 @@ var theme = (function() { }; mod.style = { - save: function() { - data.mod.set("nightTabStyle", state.get.current().theme.style); + initial: function() { + switch (state.get.current().theme.style) { + case "dark": + data.mod.set("nightTabStyle", state.get.current().theme.style); + break; + + case "light": + data.mod.set("nightTabStyle", state.get.current().theme.style); + break; + + case "system": + if (window.matchMedia("(prefers-color-scheme:dark)").matches) { + data.mod.set("nightTabStyle", "dark"); + } else if (window.matchMedia("(prefers-color-scheme:light)").matches) { + data.mod.set("nightTabStyle", "light"); + }; + break; + }; }, light: function() { helper.setObject({ @@ -133,7 +149,6 @@ var theme = (function() { path: "theme.style", newValue: "light" }); - mod.style.save(); }, dark: function() { helper.setObject({ @@ -141,7 +156,6 @@ var theme = (function() { path: "theme.style", newValue: "dark" }); - mod.style.save(); }, system: function() { helper.setObject({ @@ -3019,14 +3033,17 @@ var theme = (function() { var style = { dark: function() { mod.style.dark(); + mod.style.initial(); render.style.dark(); }, light: function() { mod.style.light(); + mod.style.initial(); render.style.light(); }, system: function() { mod.style.system(); + mod.style.initial(); render.style.system(); }, check: function() { @@ -3066,6 +3083,7 @@ var theme = (function() { }; var init = function() { + mod.style.initial(); mod.color.generated(); mod.accent.random(); mod.custom.close(); diff --git a/src/js/version.js b/src/js/version.js index 4eada931..85198a27 100644 --- a/src/js/version.js +++ b/src/js/version.js @@ -1,6 +1,6 @@ var version = (function() { - var current = "5.79.0"; + var current = "5.80.0"; var name = "Jaded Raven"; diff --git a/src/manifest.json b/src/manifest.json index e4d898c3..51403357 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name": "nightTab", "short_name": "nightTab", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", - "version": "5.79.0", + "version": "5.80.0", "manifest_version": 2, "chrome_url_overrides": { "newtab": "index.html"