diff --git a/packages/webui/src/public/app.js b/packages/webui/src/public/app.js
index 90ea07b0c..b736b4a66 100644
--- a/packages/webui/src/public/app.js
+++ b/packages/webui/src/public/app.js
@@ -50,6 +50,11 @@
const row = id => data?.sessions.find(r => key(r) === id);
const announce = text => { $('announce').textContent = text; };
// Colours come from tokens.css by data-palette and data-mode. System removes data-mode, so the OS setting picks light or dark.
+ const darkPreference = window.matchMedia('(prefers-color-scheme: dark)');
+ function syncThemeSwitch() {
+ const dark = mode === 'dark' || mode === 'dim' || (mode === 'system' && darkPreference.matches);
+ $('theme-switch').setAttribute('aria-checked', String(dark));
+ }
function theme() {
const p = Brand.palettes.find(p => p.id === palette) || Brand.palettes[0];
palette = p.id;
@@ -57,6 +62,7 @@
document.documentElement.dataset.palette = palette;
if (mode === 'system') delete document.documentElement.dataset.mode; else document.documentElement.dataset.mode = mode;
$('palette').value = palette; $('mode').value = mode;
+ syncThemeSwitch();
try { localStorage.setItem('mosaic-console-appearance', JSON.stringify({ palette, mode })); } catch {}
}
$('palette').innerHTML = Brand.palettes.map(p => ``).join('');
@@ -64,6 +70,9 @@
theme();
$('palette').onchange = e => { palette = e.target.value; theme(); };
$('mode').onchange = e => { mode = e.target.value; theme(); };
+ $('mobile-refresh').onclick = () => $('refresh').click();
+ $('theme-switch').onclick = () => { $('mode').value = $('theme-switch').getAttribute('aria-checked') === 'true' ? 'light' : 'dark'; $('mode').dispatchEvent(new Event('change', { bubbles: true })); };
+ darkPreference.addEventListener('change', syncThemeSwitch);
function seenButton(r) {
if (!['waiting', 'error'].includes(r.state) || !r.lastActivity) return '';
return ``;
diff --git a/packages/webui/src/public/index.html b/packages/webui/src/public/index.html
index 0bab04afa..a16a16f95 100644
--- a/packages/webui/src/public/index.html
+++ b/packages/webui/src/public/index.html
@@ -11,7 +11,7 @@
+
diff --git a/packages/webui/src/public/processing.css b/packages/webui/src/public/processing.css
index 419c40a6d..5e390ade5 100644
--- a/packages/webui/src/public/processing.css
+++ b/packages/webui/src/public/processing.css
@@ -108,3 +108,13 @@ body.signed-out #dashboard-summary,body.signed-out #dashboard-cards,body.signed-
.cmd-right .processing-link{display:none}
}
@media(min-width:760px) and (max-width:1100px){.kpi-grid{grid-template-columns:repeat(4,minmax(0,1fr));row-gap:16px}.kpi:nth-child(4){border-right:0}}
+
+/* Appearance toggle shares the existing saved appearance setting. */
+.theme-switch{display:inline-flex;align-items:center;justify-content:center;width:56px;min-width:56px;height:44px;padding:0;border:0;border-radius:var(--r);background:transparent;color:var(--muted);cursor:pointer}
+.theme-switch:hover{background:var(--raised)}
+.theme-switch:focus-visible{outline:2px solid var(--action);outline-offset:2px}
+.theme-track{position:relative;display:flex;align-items:center;justify-content:space-between;width:42px;height:24px;padding:4px;border:1px solid var(--line);border-radius:999px;background:var(--raised)}
+.theme-track svg{width:14px;height:14px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
+.theme-thumb{position:absolute;left:3px;top:3px;width:16px;height:16px;border-radius:50%;background:var(--action);transition:transform .15s ease}
+.theme-switch[aria-checked="true"] .theme-thumb{transform:translateX(18px)}
+@media(max-width:759px){.theme-switch{width:48px;min-width:48px}.cmd-right #refresh{display:none}}
diff --git a/packages/webui/tests/dashboard-shell-browser.test.mjs b/packages/webui/tests/dashboard-shell-browser.test.mjs
index 5b96ba1dd..68c197b4d 100644
--- a/packages/webui/tests/dashboard-shell-browser.test.mjs
+++ b/packages/webui/tests/dashboard-shell-browser.test.mjs
@@ -49,17 +49,19 @@ test('avatar menu supports keyboard navigation and local or SSO sign out', {time
assert.deepEqual(await b.evaluate('(()=>{const r=document.querySelector("#sign-out button").getBoundingClientRect();return [r.width>=44,r.height>=44]})()'),[true,true]);
});
-test('compact header keeps search and refresh usable, with pause in the avatar menu', {timeout:90000}, async t => {
+test('compact header keeps search and theme switch usable, with refresh and pause in the avatar menu', {timeout:90000}, async t => {
const {f,b,wait}=await w15Fixture(t);
await b.call('Emulation.setDeviceMetricsOverride',{width:390,height:900,deviceScaleFactor:1,mobile:false});
await b.navigate(f.base+'/#/'); await wait('document.querySelectorAll("#dashboard-kpis .kpi").length > 0');
- const state = await b.evaluate(`(()=>{const ids=['nav-open','cmdk','refresh','avatar-button'];const boxes=ids.map(id=>document.getElementById(id).getBoundingClientRect());return {tops:boxes.map(x=>x.top), widths:boxes.map(x=>x.width), overflow:document.documentElement.scrollWidth>innerWidth, pauseVisible:!!document.querySelector('#pause').getClientRects().length, zeroBadges:document.querySelectorAll('#sections .count').length, held:document.querySelector('#held').textContent}})()`);
+ const state = await b.evaluate(`(()=>{const ids=['nav-open','cmdk','theme-switch','avatar-button'];const boxes=ids.map(id=>document.getElementById(id).getBoundingClientRect());return {tops:boxes.map(x=>x.top), widths:boxes.map(x=>x.width), overflow:document.documentElement.scrollWidth>innerWidth, pauseVisible:!!document.querySelector('#pause').getClientRects().length, zeroBadges:document.querySelectorAll('#sections .count').length, held:document.querySelector('#held').textContent}})()`);
assert.ok(Math.max(...state.tops)-Math.min(...state.tops)<15, JSON.stringify(state));
assert.ok(state.widths.every(x=>x>=44)); assert.equal(state.overflow,false); assert.equal(state.pauseVisible,false);
assert.equal(state.zeroBadges,0); assert.doesNotMatch(state.held,/behind the sign-in proxy/);
await b.evaluate('document.querySelector("#cmdk").click()'); assert.equal(await b.evaluate('document.querySelector("#cmdk-dialog").open'),true);
await b.key('Escape'); await b.evaluate('document.querySelector("#avatar-button").click()');
+ assert.equal(await b.evaluate('!!document.querySelector("#mobile-refresh").getClientRects().length && !document.querySelector("#refresh").getClientRects().length'),true);
assert.equal(await b.evaluate('!!document.querySelector("#mobile-pause").getClientRects().length'),true);
+ assert.equal(await b.evaluate('(()=>{let n=0;document.querySelector("#refresh").addEventListener("click",()=>n++,{once:true});document.querySelector("#mobile-refresh").click();return n})()'),1);
await b.evaluate('document.querySelector("#mobile-pause").click()');
assert.equal(await b.evaluate('document.querySelector("#pause").getAttribute("aria-pressed")'),'true');
});
diff --git a/packages/webui/tests/shell.test.mjs b/packages/webui/tests/shell.test.mjs
index fcb45a0ea..fe4681153 100644
--- a/packages/webui/tests/shell.test.mjs
+++ b/packages/webui/tests/shell.test.mjs
@@ -326,7 +326,7 @@ test('shell in a browser: System default, seeded states, 400px, focus and the Ct
// Ctrl+K: opens on the views and the kept tasks, filters, Enter goes, Esc restores focus.
await go('#/inbox', 'Inbox');
- await b.evaluate('document.querySelector("#refresh").focus()');
+ await b.evaluate('document.querySelector("#theme-switch").focus()');
await b.key('k', 'KeyK', 3); await new Promise(r => setTimeout(r, 200));
assert.equal(await b.evaluate('document.querySelector("#cmdk-dialog").open'), false, 'Ctrl+Alt+K opens nothing');
await b.key('k', 'KeyK', 2); await wait('document.querySelector("#cmdk-dialog").open');
@@ -336,14 +336,14 @@ test('shell in a browser: System default, seeded states, 400px, focus and the Ct
assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#cmdk-list [data-href]")].map(e=>e.dataset.href)'), ['#/agents']);
// The view render focuses its h1; wait for it so a late render can't take focus from the next step.
await b.key('Enter'); await wait('location.hash==="#/agents" && !document.querySelector("#cmdk-dialog").open && document.activeElement===document.querySelector("#bus-view h1") && document.activeElement.textContent==="Agents"');
- await b.evaluate('document.querySelector("#refresh").focus()');
+ await b.evaluate('document.querySelector("#theme-switch").focus()');
await b.key('k', 'KeyK', 2); await wait('document.querySelector("#cmdk-dialog").open');
await b.call('Input.insertText', { text: 'kept' });
assert.equal(await b.evaluate('document.querySelector("#cmdk-list [aria-selected=true]").dataset.href'), '#/tasks/vikunja%3A32%2F7');
await b.key('ArrowDown'); await b.key('ArrowUp');
assert.equal(await b.evaluate('document.querySelector("#cmdk-input").getAttribute("aria-activedescendant")'), 'cmdk-opt-0');
await flat(); await shot('palette-400');
- await b.key('Escape'); await wait('!document.querySelector("#cmdk-dialog").open && document.activeElement?.id==="refresh"');
+ await b.key('Escape'); await wait('!document.querySelector("#cmdk-dialog").open && document.activeElement?.id==="theme-switch"');
await b.evaluate('{const c=document.querySelector("#cmdk");c.focus();c.click()}'); await wait('document.querySelector("#cmdk-dialog").open');
await b.call('Input.insertText', { text: 'zzzz' });
assert.match(await text('#cmdk-list'), /No view, decision or task matches\./);
diff --git a/packages/webui/tests/theme-switch-browser.test.mjs b/packages/webui/tests/theme-switch-browser.test.mjs
new file mode 100644
index 000000000..5c807f8aa
--- /dev/null
+++ b/packages/webui/tests/theme-switch-browser.test.mjs
@@ -0,0 +1,30 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { w15Fixture } from './w15-fixture.mjs';
+
+test('navbar theme switch follows and persists appearance', {timeout:90000}, async t => {
+ const {f,b,wait}=await w15Fixture(t);
+ await b.call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:'light'}]});
+ await b.navigate(f.base+'/#/'); await wait('!!document.querySelector("#mode")');
+ assert.equal(await b.evaluate('document.querySelector("#theme-switch")?.getAttribute("role")'),'switch');
+ await b.evaluate('document.querySelector("#mode").value="system";document.querySelector("#mode").dispatchEvent(new Event("change",{bubbles:true}))');
+ assert.equal(await b.evaluate('document.querySelector("#theme-switch").getAttribute("aria-checked")'),'false');
+ await b.evaluate('document.querySelector("#theme-switch").click()');
+ assert.deepEqual(await b.evaluate('[document.documentElement.dataset.mode,document.querySelector("#mode").value,document.querySelector("#theme-switch").getAttribute("aria-checked")]'),['dark','dark','true']);
+ await b.call('Page.reload'); await wait('document.querySelector("#theme-switch")?.getAttribute("aria-checked") === "true"');
+ assert.equal(await b.evaluate('document.documentElement.dataset.mode'),'dark');
+ await b.evaluate('document.querySelector("#mode").value="dim";document.querySelector("#mode").dispatchEvent(new Event("change"))');
+ assert.equal(await b.evaluate('document.querySelector("#theme-switch").getAttribute("aria-checked")'),'true');
+ await b.evaluate('document.querySelector("#theme-switch").click()');
+ assert.deepEqual(await b.evaluate('[document.documentElement.dataset.mode,document.querySelector("#mode").value]'),['light','light']);
+ await b.evaluate('document.querySelector("#mode").value="system";document.querySelector("#mode").dispatchEvent(new Event("change"))');
+ assert.equal(await b.evaluate('document.querySelector("#theme-switch").getAttribute("aria-checked")'),'false');
+ await b.call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:'dark'}]});
+ await wait('document.querySelector("#theme-switch").getAttribute("aria-checked") === "true"');
+ assert.equal(await b.evaluate('document.documentElement.hasAttribute("data-mode")'),false);
+ for (const width of [1440,390]) {
+ await b.viewport(width,900);
+ const v=await b.evaluate(`(()=>{const s=document.querySelector('#theme-switch'),a=document.querySelector('#avatar-button'),r=s.getBoundingClientRect(),ar=a.getBoundingClientRect();return {role:s.getAttribute('role'),name:s.getAttribute('aria-label'),width:r.width,height:r.height,left:r.right<=ar.left,top:Math.abs(r.top-ar.top),overflow:document.documentElement.scrollWidth>innerWidth}})()`);
+ assert.deepEqual([v.role,v.name,v.width>=44,v.height>=44,v.left,v.top<15,v.overflow],['switch','Dark mode',true,true,true,true,false],JSON.stringify(v));
+ }
+});