From f7b2406e8dbcaf83b31c163982067eaf63632806 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 8 Feb 2022 10:13:52 -0800 Subject: [PATCH] Added server setting to force day/night mode, #3618 --- meshcentral-config-schema.json | 1 + views/default-mobile.handlebars | 7 ++++++- views/default.handlebars | 5 +++++ webserver.js | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index cb5a4d6b..532ee2c8 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -301,6 +301,7 @@ "rootRedirect": { "type": "string", "default": null, "description": "Redirects HTTP root requests to this URL. When in use, direct users to /login to see the normal login page." }, "mobileSite": { "type": "boolean", "default": true, "description": "When set to false, this setting will disable the mobile site." }, "unknownUserRootRedirect": { "type": "string", "default": null, "description": "Redirects HTTP root requests to this URL only where user is not already logged in. When in use, direct users to /login to see the normal login page." }, + "nightMode": { "type": "integer", "default": 0, "description": "0 = User selects day/night mode, 1 = Always night mode, 2 = Always day mode" }, "userQuota": { "type": "integer" }, "meshQuota": { "type": "integer" }, "loginKey": { "type": [ "string", "array" ], "items": { "type": "string" }, "default": null, "description": "Requires that users add the value ?key=xxx in the URL in order to see the web site." }, diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index fa55e9ba..897149fa 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -727,7 +727,7 @@
Change password
Delete account
-
Set dark mode
+
Personal notes

@@ -1309,6 +1309,9 @@ // Session Refresh Timer if (sessionTime >= 10) { sessionRefreshTimer = setTimeout(refreshCookieSession, Math.round((sessionTime * 60000) * 0.8)); } + // Hide night mode button if needed + QV('setDarkModeLink', (features2 & 0x00300000) == 0); + // Set the user's desktop shortcut keys deskKeyboardShortcuts = []; var deskKeyboardShortcutsStr = getstore('deskKeyShortcuts', '0x0A002E,0x100000,0x100028,0x100026,0x10004C,0x10004D,0x11004D,0x100052,0x020073,0x080057,0x020009,0x100025,0x100027').split(','); @@ -2209,6 +2212,8 @@ // Set night mode var nNightMode = getstore('nightMode', '0') nightMode = false; + if ((features2 & 0x00100000) != 0) { nNightMode = '1'; } + if ((features2 & 0x00200000) != 0) { nNightMode = '2'; } if (nNightMode == '1') { nightMode = true; } else if ((nNightMode == '0') && (window.matchMedia)) { nightMode = window.matchMedia('(prefers-color-scheme: dark)').matches } if (nightMode) { QC('body').add('night'); QS('body')['background-color'] = '#000'; QS('body')['color'] = 'lightgray'; } else { QC('body').remove('night'); QS('body')['background-color'] = '#FFF'; QS('body')['color'] = 'black'; } diff --git a/views/default.handlebars b/views/default.handlebars index 4891a0a4..df3fcbdf 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1645,6 +1645,9 @@ // Fix links if (urlargs.key) { Q('p6backuplink').href += '?key=' + urlargs.key; } + // Hide night mode button if needed + QV('uiViewButton4', (features2 & 0x00300000) == 0); + // Fix HTML words that in english have two or more meanings Q('DeskType').value = multiTranslate("[KeyboardTyping]|Type"); } @@ -1923,6 +1926,8 @@ // Set night mode var nNightMode = getstore('nightMode', '0') nightMode = false; + if ((features2 & 0x00100000) != 0) { nNightMode = '1'; } + if ((features2 & 0x00200000) != 0) { nNightMode = '2'; } if (nNightMode == '1') { nightMode = true; } else if ((nNightMode == '0') && (window.matchMedia)) { nightMode = window.matchMedia('(prefers-color-scheme: dark)').matches } if (nightMode) { QC('body').add('night'); QS('body')['background-color'] = '#000'; } else { QC('body').remove('night'); QS('body')['background-color'] = '#d3d9d6'; } diff --git a/webserver.js b/webserver.js index 97e13f84..d281de51 100644 --- a/webserver.js +++ b/webserver.js @@ -2887,6 +2887,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF if ((domain.passwordrequirements) && (domain.passwordrequirements.otp2factor == false)) { features2 += 0x00020000; } // Indicates support for OTP 2FA is disabled if ((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.backupcode2factor === false)) { features2 += 0x00040000; } // Indicates 2FA backup codes are disabled if ((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.single2factorwarning === false)) { features2 += 0x00080000; } // Indicates no warning if a single 2FA is in use + if (domain.nightmode === 1) { features2 += 0x00100000; } // Always night mode + if (domain.nightmode === 2) { features2 += 0x00200000; } // Always day mode return { features: features, features2: features2 }; }