Added server setting to force day/night mode, #3618
Ylian Saint-Hilaire committed
Feb 8, 2022 at 10:13 UTC
f7b2406e8dbcaf83b31c163982067eaf63632806
4 files changed
+14
-1
meshcentral-config-schema.json
+1
@@ -301,6 +301,7 @@
301
"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." },
302
"mobileSite": { "type": "boolean", "default": true, "description": "When set to false, this setting will disable the mobile site." },
303
"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." },
304
+ "nightMode": { "type": "integer", "default": 0, "description": "0 = User selects day/night mode, 1 = Always night mode, 2 = Always day mode" },
305
"userQuota": { "type": "integer" },
306
"meshQuota": { "type": "integer" },
307
"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." },
views/default-mobile.handlebars
+6
-1
@@ -727,7 +727,7 @@
727
<div style="margin-top:5px"><span id="changeEmailId" style="display:none"><a onclick="account_showChangeEmail()" style="cursor:pointer">Change email address</a></span></div>
728
<div style="margin-top:5px"><a onclick="account_showChangePassword()" style="cursor:pointer">Change password</a><span id="p2nextPasswordUpdateTime"></span></div>
729
<div style="margin-top:5px"><a onclick="account_showDeleteAccount()" style="cursor:pointer">Delete account</a></div>
730
- <div style="margin-top:5px"><a onclick="toggleNightMode()" style="cursor:pointer">Set dark mode</a></div>
730
+ <div style="margin-top:5px" id="setDarkModeLink"><a onclick="toggleNightMode()" style="cursor:pointer">Set dark mode</a></div>
731
<div style="margin-top:5px"><a onclick="showNotes(false)" style="cursor:pointer">Personal notes</a></div>
732
</div>
733
<br style=clear:both />
@@ -1309,6 +1309,9 @@
1309
// Session Refresh Timer
1310
if (sessionTime >= 10) { sessionRefreshTimer = setTimeout(refreshCookieSession, Math.round((sessionTime * 60000) * 0.8)); }
1311
1312
+ // Hide night mode button if needed
1313
+ QV('setDarkModeLink', (features2 & 0x00300000) == 0);
1314
+
1315
// Set the user's desktop shortcut keys
1316
deskKeyboardShortcuts = [];
1317
var deskKeyboardShortcutsStr = getstore('deskKeyShortcuts', '0x0A002E,0x100000,0x100028,0x100026,0x10004C,0x10004D,0x11004D,0x100052,0x020073,0x080057,0x020009,0x100025,0x100027').split(',');
@@ -2209,6 +2212,8 @@
2212
// Set night mode
2213
var nNightMode = getstore('nightMode', '0')
2214
nightMode = false;
2215
+ if ((features2 & 0x00100000) != 0) { nNightMode = '1'; }
2216
+ if ((features2 & 0x00200000) != 0) { nNightMode = '2'; }
2217
if (nNightMode == '1') { nightMode = true; }
2218
else if ((nNightMode == '0') && (window.matchMedia)) { nightMode = window.matchMedia('(prefers-color-scheme: dark)').matches }
2219
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'; }
views/default.handlebars
+5
@@ -1645,6 +1645,9 @@
1645
// Fix links
1646
if (urlargs.key) { Q('p6backuplink').href += '?key=' + urlargs.key; }
1647
1648
+ // Hide night mode button if needed
1649
+ QV('uiViewButton4', (features2 & 0x00300000) == 0);
1650
+
1651
// Fix HTML words that in english have two or more meanings
1652
Q('DeskType').value = multiTranslate("[KeyboardTyping]|Type");
1653
}
@@ -1923,6 +1926,8 @@
1926
// Set night mode
1927
var nNightMode = getstore('nightMode', '0')
1928
nightMode = false;
1929
+ if ((features2 & 0x00100000) != 0) { nNightMode = '1'; }
1930
+ if ((features2 & 0x00200000) != 0) { nNightMode = '2'; }
1931
if (nNightMode == '1') { nightMode = true; }
1932
else if ((nNightMode == '0') && (window.matchMedia)) { nightMode = window.matchMedia('(prefers-color-scheme: dark)').matches }
1933
if (nightMode) { QC('body').add('night'); QS('body')['background-color'] = '#000'; } else { QC('body').remove('night'); QS('body')['background-color'] = '#d3d9d6'; }
webserver.js
+2
@@ -2887,6 +2887,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
2887
if ((domain.passwordrequirements) && (domain.passwordrequirements.otp2factor == false)) { features2 += 0x00020000; } // Indicates support for OTP 2FA is disabled
2888
if ((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.backupcode2factor === false)) { features2 += 0x00040000; } // Indicates 2FA backup codes are disabled
2889
if ((typeof domain.passwordrequirements != 'object') || (domain.passwordrequirements.single2factorwarning === false)) { features2 += 0x00080000; } // Indicates no warning if a single 2FA is in use
2890
+ if (domain.nightmode === 1) { features2 += 0x00100000; } // Always night mode
2891
+ if (domain.nightmode === 2) { features2 += 0x00200000; } // Always day mode
2892
return { features: features, features2: features2 };
2893
}
2894