mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-11-23 17:42:09 +00:00
602fa36573
Adds an alternative console layout modelled on the community redesign by @rathlinus and rebuilt on the existing EJS/JavaScript/CSS stack -- the svelte-rewrite branch stays a design reference and is not merged. What ships: - lib/uiShell.js resolves the shell once (query, then cookie, then default) so SSR markup, asset includes and window.BetterDesk.uiShell cannot disagree. UX 3.5 remains the default and the fallback; unknown values (including the removed `classic`) are ignored instead of erroring. - routes/ui-shell.routes.js exposes GET/POST /api/ui-shell (auth + CSRF) and persists the choice per browser in the bd_ui_shell cookie. No database migration, no effect on other operators. - lib/consoleNav.js groups the existing pages into Devices, Support, People, Activity and Settings. Every entry keeps its route, RBAC permission and panel-access section, so a role sees exactly the pages it could open before; the grouping is presentation only. - views/partials/ux36-sidebar.ejs renders that model with proper aria-current/aria-expanded state and no duplicate navigation markup. - public/css/ux36.css layers the new chrome on top of ux35.css without forking the --ux35-* token contract, so branding, wallpapers, fonts and light/dark/custom themes keep working in both shells. - public/js/ux36-shell.js adds the one-open-group default, filter sync and the Settings switch; ux35-shell.js keeps owning drawer, resize and theme. - Settings -> General gains a "Console interface" card so operators can opt in and out without a URL; ?ui=ux36 works as a support deep link. - Settings deep links now accept ?tab=<topic> in addition to #topic. - New nav.* and ux36.* keys in all 26 locales (real translations). - Docs: CHANGELOG, UX wiki page, Web-Console wiki page, README, contributor attributions, and .cursor/rules/ux36-attribution.mdc so future UX 3.6 commits keep the credit. Tests: tests/ux36-shell.test.js, tests/ux36-pages.render.test.js and tests/ux36-ui-shell.routes.test.js; ux35-ui-contract.test.js updated to assert both shells. Full web-nodejs suite: 986 passed; the three failing suites (users.routes, devices.routes, dashboardPairingUi) fail identically on the untouched branch. Refs #493 Refs #495 Reported-by: @rathlinus Based-on: @rathlinus UX redesign (Refs #493, #495) Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
/**
|
|
* BetterDesk Console — UI shell resolution (UX 3.5 default, UX 3.6 beta).
|
|
*
|
|
* The shell choice is a per-browser preference. It is resolved in exactly one
|
|
* place so SSR markup, CSS/JS includes and `window.BetterDesk.uiShell` cannot
|
|
* disagree, and every unknown or malformed value falls back to `ux35`.
|
|
*
|
|
* UX 3.5 remains the safe default; UX 3.6 is opt-in beta.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const SHELL_UX35 = 'ux35';
|
|
const SHELL_UX36 = 'ux36';
|
|
|
|
const SUPPORTED_SHELLS = Object.freeze([SHELL_UX35, SHELL_UX36]);
|
|
const DEFAULT_SHELL = SHELL_UX35;
|
|
|
|
/** Cookie name — same key used by the legacy bridge so stale values stay valid. */
|
|
const SHELL_COOKIE = 'bd_ui_shell';
|
|
const SHELL_COOKIE_MAX_AGE_MS = 365 * 24 * 60 * 60 * 1000;
|
|
|
|
function normalizeShell(value) {
|
|
const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
return SUPPORTED_SHELLS.includes(raw) ? raw : null;
|
|
}
|
|
|
|
function isBetaShell(shell) {
|
|
return normalizeShell(shell) === SHELL_UX36;
|
|
}
|
|
|
|
/**
|
|
* Resolve the shell for a request.
|
|
*
|
|
* Priority: explicit `?ui=` query (operator deep link / support), then the
|
|
* browser cookie, then the default. Unknown values are ignored rather than
|
|
* throwing, so old `?ui=classic` links keep working — they simply land on the
|
|
* default shell.
|
|
*/
|
|
function resolveShell(req) {
|
|
const fromQuery = normalizeShell(req?.query?.ui);
|
|
if (fromQuery) return fromQuery;
|
|
const fromCookie = normalizeShell(req?.cookies?.[SHELL_COOKIE]);
|
|
if (fromCookie) return fromCookie;
|
|
return DEFAULT_SHELL;
|
|
}
|
|
|
|
/** Cookie attributes matching the panel session cookie hardening. */
|
|
function shellCookieOptions(httpsEnabled) {
|
|
return {
|
|
httpOnly: false, // the client shell bridge reads it; value is not a secret
|
|
sameSite: 'lax',
|
|
secure: !!httpsEnabled,
|
|
maxAge: SHELL_COOKIE_MAX_AGE_MS,
|
|
path: '/',
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
SHELL_UX35,
|
|
SHELL_UX36,
|
|
SUPPORTED_SHELLS,
|
|
DEFAULT_SHELL,
|
|
SHELL_COOKIE,
|
|
SHELL_COOKIE_MAX_AGE_MS,
|
|
normalizeShell,
|
|
isBetaShell,
|
|
resolveShell,
|
|
shellCookieOptions,
|
|
};
|