Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(desktop): make the shell feel like a real OS with an island taskbar, new Start, tray, notifications, lock and desktop files

nirholas4ecf633f9aca
diff --git a/data/changelog.json b/data/changelog.json
index 78da1bd2e..d1de6c8c0 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,26 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security, desktop (desktop entries become the desktop app's release notes). `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-10-11",
+ "title": "The desktop now looks and works like a real operating system",
+ "link": "/?view=desktop",
+ "summary": "The desktop shell is rebuilt to feel like a computer, not a web page. A floating island taskbar with Start, Widgets and Assistant buttons. A new Start menu with your avatar, the time, an A to Z list of every app and page, pinned apps, recent files, quick folder links and a power button, plus search across apps, pages and your files. A system tray with live network, volume and battery readouts that opens quick settings (dark mode, night light, do not disturb, energy saver, sounds, full screen, brightness and volume). A notification centre over a month calendar, with toasts that open the app that sent them. A lock screen (Ctrl+Alt+L), a power menu with restart, shut down and sign out, a Run box (Ctrl+Alt+R) and an About page with your real device specs. The desktop is now your Desktop folder: create folders and text files from the right-click menu, rename with F2, delete to the Recycle Bin, drop files from your computer onto it, and set any picture as the wallpaper. New Bubbles wallpaper in dark and light, glossy app icons, and Ctrl+Alt shortcuts for every system surface.",
+ "tags": [
+ "feature",
+ "desktop"
+ ]
+ },
+ {
+ "date": "2026-10-11",
+ "title": "The web desktop is now a real OS: a file system and eleven apps that run in your browser",
+ "link": "/?view=desktop",
+ "summary": "The desktop gains a persistent virtual file system (Home with Desktop, Documents, Pictures, Music, Videos and Downloads, a Recycle Bin, quota readout) and eleven native apps built on it: Files with list, detail and tile views and drag-free cut, copy, paste and rename; Notepad with tabs and autosave; Photos; Calculator with standard, scientific, programmer and unit-converter modes; Clock with world clocks, alarms, timer and stopwatch; Weather from live Open-Meteo forecasts for your location or any city; Camera that takes real photos and videos into Pictures and Videos; Paint with layers of tools, undo and export; Terminal with a real command set that opens apps and switches theme; Task Manager with live memory, frame rate and per-window usage; and a Media Player with playlists. Everything is stored in your browser and nothing is faked: metrics a browser cannot report say so.",
+ "tags": [
+ "feature",
+ "desktop"
+ ]
+ },
{
"date": "2026-10-11",
"title": "Live widgets and an assistant on the desktop, and the desktop is back at /",
@@ -35,21 +55,28 @@
"title": "The web desktop gets Snap layouts, taskbar peek and three shell styles: Fluent, Aqua and Classic",
"link": "/?view=desktop",
"summary": "Hover a window's maximize button (or press Alt+Z) to tile it into one of six layouts, then let Snap assist fill the empty zones with your other windows. Corners snap to quarters, Ctrl+Alt+Arrows snap from the keyboard, minimize flies the window into its taskbar button, and hovering a running app shows its window card with Aero Peek. Settings, Personalization, Style switches the whole shell to Aqua (menu bar, magnifying dock, traffic lights) or Classic (bevelled 9x chrome with a labelled taskbar).",
- "tags": ["feature", "desktop"]
+ "tags": [
+ "feature",
+ "desktop"
+ ]
},
{
"date": "2026-10-11",
"title": "3D viewers no longer flood the browser console, and /trenches stops hammering an offline feed",
"link": "/marketplace",
"summary": "Every page with a 3D model viewer moved to model-viewer 4.4.0, the first release that both decodes our compressed avatars and drops the debug lines 4.3 printed for every model on the page. The trenches dashboard now checks the feed once and backs off while it is offline instead of sending five requests every 15 seconds, and desktop app windows no longer trigger a fullscreen-attribute warning.",
- "tags": ["fix"]
+ "tags": [
+ "fix"
+ ]
},
{
"date": "2026-10-11",
"title": "A page for every three.ws app: Android, Solana Seeker, iPhone, desktop and the web desktop",
"link": "/apps",
"summary": "The new Apps hub lists every way to run three.ws, each with its own page: the web desktop, the Android app (APK download), Solana Seeker (live on the dApp Store, Seed Vault sign-in and Genesis Token verification), iPhone and iPad (what runs today and what the native build adds once Apple enrollment clears), and the Windows and Linux desktop app, whose download button reads the live release feed and picks the right file for your system.",
- "tags": ["feature"]
+ "tags": [
+ "feature"
+ ]
},
{
"date": "2026-10-11",
diff --git a/src/desktop/chrome/chrome.css b/src/desktop/chrome/chrome.css
new file mode 100644
index 000000000..6cf11d774
--- /dev/null
+++ b/src/desktop/chrome/chrome.css
@@ -0,0 +1,1295 @@
+/* The desktop's system chrome: island taskbar, Start, tray status, quick
+ * settings, notification centre, toasts, dialogs, lock and power screens,
+ * plus the screen overlays (brightness, night light, energy saver).
+ * Colours come from theme.css tokens so every surface follows light/dark. */
+
+/* ---------- Screen overlays ---------- */
+.os-dim,
+.os-night {
+ position: absolute;
+ inset: 0;
+ pointer-events: none;
+ z-index: 20050;
+}
+.os-dim {
+ background: #000;
+ opacity: 0;
+ transition: opacity 0.15s;
+}
+.os-night {
+ background: #ff8a1f;
+ mix-blend-mode: multiply;
+ opacity: 0;
+ transition: opacity 0.6s;
+}
+.os-night.on {
+ opacity: 0.22;
+}
+.os.os-saver *,
+.os.os-saver *::before,
+.os.os-saver *::after {
+ animation-duration: 0s !important;
+ transition-duration: 0s !important;
+}
+.os.os-saver .os-pop,
+.os.os-saver .os-task {
+ backdrop-filter: none;
+}
+
+/* ---------- Bubbles wallpaper ---------- */
+.os[data-wall='bubbles'] .os-wall {
+ background:
+ radial-gradient(ellipse 70px 46px at calc(22% - 58px) calc(30% - 70px), #ffffffb0, transparent 70%),
+ radial-gradient(circle 190px at 22% 30%, #7fb2ff55 0%, #6a5cff40 62%, #c7b8ff99 96%, transparent 100%),
+ radial-gradient(ellipse 40px 26px at calc(78% - 32px) calc(22% - 38px), #ffffffa0, transparent 70%),
+ radial-gradient(circle 110px at 78% 22%, #ff9de255 0%, #b45cff40 62%, #ffc4f299 96%, transparent 100%),
+ radial-gradient(ellipse 90px 58px at calc(66% - 80px) calc(74% - 92px), #ffffff90, transparent 70%),
+ radial-gradient(circle 250px at 66% 74%, #5ee0ff44 0%, #3b6cff38 62%, #a6e9ff88 96%, transparent 100%),
+ radial-gradient(ellipse 22px 14px at calc(42% - 16px) calc(58% - 20px), #ffffffb0, transparent 70%),
+ radial-gradient(circle 58px at 42% 58%, #ffd27a55 0%, #ff7a9a40 62%, #ffe2a899 96%, transparent 100%),
+ radial-gradient(ellipse 30px 20px at calc(10% - 24px) calc(80% - 28px), #ffffffa0, transparent 70%),
+ radial-gradient(circle 84px at 10% 80%, #8affc955 0%, #2fbf9f40 62%, #b9ffe699 96%, transparent 100%),
+ radial-gradient(ellipse 16px 10px at calc(90% - 12px) calc(56% - 14px), #ffffffa0, transparent 70%),
+ radial-gradient(circle 40px at 90% 56%, #ffffff40 0%, #8b7bff40 62%, #ffffff88 96%, transparent 100%),
+ radial-gradient(80% 70% at 20% 0%, #4b2ea8, transparent 70%),
+ radial-gradient(80% 80% at 100% 100%, #0a5b9e, transparent 70%),
+ linear-gradient(140deg, #0c1238, #241052 50%, #071a3c);
+}
+[data-theme='light'] .os[data-wall='bubbles'] .os-wall {
+ background:
+ radial-gradient(ellipse 70px 46px at calc(22% - 58px) calc(30% - 70px), #ffffffe0, transparent 70%),
+ radial-gradient(circle 190px at 22% 30%, #a9c8ff70 0%, #9b8cff50 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(ellipse 40px 26px at calc(78% - 32px) calc(22% - 38px), #ffffffe0, transparent 70%),
+ radial-gradient(circle 110px at 78% 22%, #ffc0ee70 0%, #d9a0ff50 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(ellipse 90px 58px at calc(66% - 80px) calc(74% - 92px), #ffffffd0, transparent 70%),
+ radial-gradient(circle 250px at 66% 74%, #a6efff70 0%, #8fb0ff50 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(ellipse 22px 14px at calc(42% - 16px) calc(58% - 20px), #ffffffe0, transparent 70%),
+ radial-gradient(circle 58px at 42% 58%, #ffe0a070 0%, #ffb0c450 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(ellipse 30px 20px at calc(10% - 24px) calc(80% - 28px), #ffffffe0, transparent 70%),
+ radial-gradient(circle 84px at 10% 80%, #b6ffe070 0%, #7fe0c850 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(ellipse 16px 10px at calc(90% - 12px) calc(56% - 14px), #ffffffe0, transparent 70%),
+ radial-gradient(circle 40px at 90% 56%, #ffffff80 0%, #c0b8ff50 62%, #ffffffd0 96%, transparent 100%),
+ radial-gradient(80% 70% at 20% 0%, #d8ccff, transparent 70%),
+ radial-gradient(80% 80% at 100% 100%, #c2e4ff, transparent 70%),
+ linear-gradient(140deg, #eef1ff, #f6ecff 50%, #e6f4ff);
+}
+/* White labels vanish on the pastel light wallpaper: switch to dark ink with a soft halo. */
+[data-theme='light'] .os[data-wall='bubbles'] .os-icon {
+ color: #1d1838;
+ text-shadow: 0 0 4px #ffffffd0, 0 1px 1px #ffffff90;
+}
+[data-theme='light'] .os[data-wall='bubbles'] .os-icon:hover {
+ background: #1d18381a;
+}
+
+/* ---------- App tiles: glossy, lit from above ---------- */
+.os .app-tile {
+ position: relative;
+ overflow: hidden;
+ background:
+ radial-gradient(120% 70% at 50% -10%, #ffffff55, transparent 60%),
+ linear-gradient(150deg, hsl(var(--hue) 82% 64%), hsl(calc(var(--hue) + 34) 74% 42%));
+ box-shadow:
+ 0 6px 14px -4px hsl(var(--hue) 70% 30% / 0.65),
+ 0 2px 4px #0004,
+ inset 0 1px 0 #ffffff70,
+ inset 0 -2px 4px #0003;
+}
+.os .app-tile .ico {
+ filter: drop-shadow(0 1px 1.5px #0005);
+}
+
+/* ---------- Island taskbar (Fluent) ---------- */
+@media (min-width: 721px) {
+ .os[data-style='fluent'] .os-task {
+ left: 50%;
+ right: auto;
+ bottom: 8px;
+ height: calc(var(--task-h) - 14px);
+ width: max-content;
+ max-width: calc(100vw - 16px);
+ transform: translateX(-50%);
+ grid-template-columns: auto auto auto;
+ gap: 4px;
+ padding: 0 6px;
+ border: 1px solid var(--hr);
+ border-radius: 16px;
+ background: var(--bg70);
+ backdrop-filter: var(--blur-heavy);
+ box-shadow: 0 10px 40px -8px #0008, inset 0 1px 0 #ffffff14;
+ }
+ .os[data-style='fluent'] .os-task.left {
+ left: 8px;
+ transform: none;
+ }
+ .os[data-style='fluent'] .os-task .os-tb {
+ width: 40px;
+ height: 38px;
+ border-radius: 10px;
+ }
+ .os[data-style='fluent'] .os-task .os-clock {
+ height: 38px;
+ border-radius: 10px;
+ }
+ .os[data-style='fluent'] .os-task-mid {
+ padding: 0 6px;
+ border-left: 1px solid var(--hr);
+ border-right: 1px solid var(--hr);
+ }
+ .os[data-style='fluent'] .os-showdesk {
+ display: none;
+ }
+ .os[data-style='fluent'] .start-menu,
+ .os[data-style='fluent'] .os-quick,
+ .os[data-style='fluent'] .os-notes {
+ bottom: calc(var(--task-h) + 4px);
+ }
+}
+
+/* Show desktop sliver at the far right of the bar */
+.os-showdesk {
+ align-self: stretch;
+ width: 8px;
+ margin-left: 4px;
+ border-left: 1px solid var(--hr);
+ border-radius: 0;
+}
+.os-showdesk:hover {
+ background: var(--hover-b);
+}
+
+/* ---------- Tray status pill and clock ---------- */
+.os-tb.os-status {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ width: auto;
+ padding: 0 10px;
+}
+/* Every style pins tray buttons to a square; the status pill holds several glyphs and must size to them. */
+.os[data-style] .os-task-right .os-tb.os-status {
+ width: auto;
+ padding: 0 8px;
+}
+.st-ico {
+ display: grid;
+ place-items: center;
+}
+.st-ico.off {
+ color: var(--text2);
+}
+.st-bat {
+ position: relative;
+ display: inline-block;
+ width: 20px;
+ height: 10px;
+ border: 1.5px solid currentColor;
+ border-radius: 3px;
+ flex: none;
+}
+.st-bat::after {
+ content: '';
+ position: absolute;
+ right: -4px;
+ top: 2px;
+ width: 2px;
+ height: 3px;
+ border-radius: 0 1px 1px 0;
+ background: currentColor;
+}
+.st-bat i {
+ position: absolute;
+ inset: 1px auto 1px 1px;
+ width: calc(var(--lvl, 100%) - 2px);
+ min-width: 1px;
+ border-radius: 1px;
+ background: currentColor;
+}
+.st-bat.low i {
+ background: #f5b83d;
+}
+.st-bat.critical i {
+ background: #ef4444;
+}
+.st-bat.chg i {
+ background: #34d399;
+}
+.os .os-clock {
+ position: relative;
+ flex-direction: row;
+ align-items: center;
+ gap: 8px;
+}
+.ck-t {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ line-height: 1.25;
+}
+.ck-t b {
+ font-weight: 500;
+ font-variant-numeric: tabular-nums;
+}
+.ck-t small {
+ font-size: 11px;
+ color: var(--text2);
+}
+/* The Aqua menu bar and the Classic taskbar are too short for two lines: time only, date in the tooltip. */
+.os:is([data-style='aqua'], [data-style='classic']) .ck-t small {
+ display: none;
+}
+.ck-n {
+ display: grid;
+ place-items: center;
+ min-width: 18px;
+ height: 18px;
+ padding: 0 5px;
+ border-radius: 9px;
+ font-size: 10px;
+ font-weight: 700;
+ color: #fff;
+ background: var(--accent);
+}
+.ck-dnd {
+ display: grid;
+ place-items: center;
+ color: var(--text2);
+}
+
+/* ---------- Start menu ---------- */
+.os .start-menu {
+ width: min(760px, calc(100vw - 16px));
+ margin-left: calc(min(760px, 100vw - 16px) / -2);
+ height: min(680px, calc(100vh - var(--task-h) - 56px));
+ padding: 0;
+ overflow: visible;
+ margin-top: 40px;
+ border-radius: 18px;
+}
+.os[data-style='aqua'] .start-menu {
+ margin-top: 0;
+}
+.sm-head {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
+ padding: 0 22px 14px;
+}
+.os .sm-user {
+ flex-direction: column;
+ gap: 6px;
+ margin-top: -36px;
+ padding: 0 10px 4px;
+ font-size: 14px;
+ font-weight: 600;
+ border-radius: 14px;
+}
+.os .sm-user:hover {
+ background: none;
+}
+.sm-user .avatar {
+ width: 72px;
+ height: 72px;
+ font-size: 26px;
+ border: 3px solid var(--cm);
+ box-shadow: 0 8px 24px #0006;
+ background-size: cover;
+ background-position: center;
+ transition: transform 0.2s var(--ease-decel);
+}
+.sm-user:hover .avatar {
+ transform: scale(1.05);
+}
+.sm-head .sm-search {
+ align-self: stretch;
+ height: 42px;
+ border-radius: 21px;
+}
+/* The pill already lights up on focus-within; a second ring on the input reads as a double border. */
+.sm-search input:focus-visible {
+ outline: none;
+}
+.sm-main {
+ flex: 1;
+ min-height: 0;
+ display: grid;
+ grid-template-columns: 220px 1fr;
+ border-top: 1px solid var(--hr);
+}
+.start-menu.searching .sm-side {
+ display: none;
+}
+.start-menu.searching .sm-main {
+ grid-template-columns: 1fr;
+}
+.sm-side {
+ overflow-y: auto;
+ padding: 10px 8px 12px;
+ border-right: 1px solid var(--hr);
+ scrollbar-width: thin;
+}
+.sm-letter {
+ margin: 10px 8px 2px;
+ padding: 2px 0;
+ font-size: 11px;
+ font-weight: 700;
+ color: var(--accent);
+}
+.sm-side-app {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ width: 100%;
+ padding: 5px 8px;
+ border-radius: 8px;
+ font-size: 13px;
+ text-align: left;
+}
+.sm-side-app span {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.sm-side-app .app-tile.sm {
+ width: 26px;
+ height: 26px;
+ border-radius: 7px;
+}
+.sm-side-app:hover {
+ background: var(--hover-b);
+}
+.sm-side-app:active {
+ background: var(--fill);
+}
+.os .sm-body {
+ margin: 0;
+ padding: 12px 18px 14px;
+}
+.sm-clock {
+ display: flex;
+ align-items: baseline;
+ gap: 14px;
+ margin: 2px 4px 14px;
+}
+.sm-clock b {
+ font-size: 40px;
+ font-weight: 300;
+ letter-spacing: -1px;
+ font-variant-numeric: tabular-nums;
+ line-height: 1;
+}
+.sm-clock span {
+ color: var(--text2);
+ font-size: 13px;
+}
+.os .sm-h .sm-more {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+}
+.os .sm-grid {
+ grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
+}
+.os .sm-foot {
+ margin: 0;
+ padding: 10px 16px;
+ border-radius: 0 0 18px 18px;
+}
+.sm-folders {
+ display: flex;
+ gap: 2px;
+}
+.sm-folder {
+ display: grid;
+ place-items: center;
+ width: 38px;
+ height: 34px;
+ border-radius: 8px;
+ color: var(--text2);
+ transition: background 0.12s, color 0.12s;
+}
+.sm-folder:hover {
+ background: var(--hover-b);
+ color: var(--text);
+}
+.sm-folder:active,
+.sm-pwr:active {
+ background: var(--fill);
+}
+.sm-power:hover {
+ color: #ef4444;
+}
+@media (max-width: 720px) {
+ .os .start-menu {
+ height: calc(100vh - var(--task-h) - 56px);
+ }
+ .sm-main {
+ grid-template-columns: 1fr;
+ }
+ .sm-side {
+ display: none;
+ }
+ .sm-clock b {
+ font-size: 32px;
+ }
+}
+
+/* ---------- Context menus: submenus, check marks, shortcuts ---------- */
+.os .ctx {
+ min-width: 220px;
+ border-radius: 10px;
+}
+.ctx button span {
+ flex: 1;
+}
+.ctx i.ico {
+ display: inline-block;
+ width: 16px;
+ height: 16px;
+ flex: none;
+}
+.ctx kbd {
+ font: inherit;
+ font-size: 11px;
+ color: var(--text2);
+}
+.ctx button[aria-expanded='true'] {
+ background: var(--hover-b);
+}
+.ctx-sub {
+ position: absolute;
+ animation-name: ctx-in;
+}
+
+/* ---------- Quick settings ---------- */
+.os-quick,
+.os-notes {
+ right: 8px;
+ bottom: calc(var(--task-h) + 10px);
+ transform-origin: bottom right;
+}
+.os-quick {
+ width: min(380px, calc(100vw - 16px));
+ padding: 18px 18px 0;
+ border-radius: 14px;
+}
+.qs-grid {
+ display: grid;
+ grid-template-columns: repeat(3, 1fr);
+ gap: 10px;
+}
+.qs-tile {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 10px;
+ min-height: 76px;
+ padding: 12px;
+ border-radius: 10px;
+ border: 1px solid var(--hr);
+ background: var(--hover-half);
+ font-size: 12px;
+ text-align: left;
+ transition: background 0.15s, color 0.15s, transform 0.1s;
+}
+.qs-tile:hover {
+ background: var(--hover-b);
+}
+.qs-tile:active {
+ transform: scale(0.97);
+}
+.qs-tile[aria-pressed='true'] {
+ color: #fff;
+ background: var(--accent);
+ border-color: transparent;
+}
+.qs-tile[aria-pressed='true']:hover {
+ filter: brightness(1.08);
+}
+.qs-sliders {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ margin: 18px 0 10px;
+}
+.qs-slider {
+ display: grid;
+ grid-template-columns: 22px 1fr 40px;
+ align-items: center;
+ gap: 12px;
+}
+.qs-slider output {
+ font-size: 12px;
+ color: var(--text2);
+ text-align: right;
+ font-variant-numeric: tabular-nums;
+}
+.qs-slider input {
+ -webkit-appearance: none;
+ appearance: none;
+ height: 22px;
+ background: transparent;
+ cursor: pointer;
+}
+.qs-slider input::-webkit-slider-runnable-track {
+ height: 4px;
+ border-radius: 2px;
+ background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--fill-track, #8886) var(--fill, 50%));
+}
+.qs-slider input::-moz-range-track {
+ height: 4px;
+ border-radius: 2px;
+ background: linear-gradient(90deg, var(--accent) var(--fill, 50%), #8886 var(--fill, 50%));
+}
+.qs-slider input::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ width: 18px;
+ height: 18px;
+ margin-top: -7px;
+ border-radius: 50%;
+ background: var(--accent);
+ border: 4px solid var(--card);
+ box-shadow: 0 0 0 1px var(--hr), 0 2px 6px #0005;
+ transition: transform 0.1s;
+}
+.qs-slider input::-moz-range-thumb {
+ width: 12px;
+ height: 12px;
+ border-radius: 50%;
+ background: var(--accent);
+ border: 4px solid var(--card);
+ box-shadow: 0 0 0 1px var(--hr);
+}
+.qs-slider input:active::-webkit-slider-thumb {
+ transform: scale(1.2);
+}
+.qs-info {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ padding: 10px 0 12px;
+ border-top: 1px solid var(--hr);
+}
+.qs-line {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 4px 2px;
+}
+.qs-line > .ico,
+.qs-line > .st-bat {
+ flex: none;
+}
+.qs-line b {
+ display: block;
+ font-size: 13px;
+ font-weight: 500;
+}
+.qs-line small {
+ display: block;
+ font-size: 11px;
+ color: var(--text2);
+}
+.qs-foot {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin: 0 -18px;
+ padding: 8px 12px;
+ background: var(--bg30);
+ border-top: 1px solid var(--hr);
+ border-radius: 0 0 14px 14px;
+}
+.qs-user {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 6px 8px;
+ border-radius: 8px;
+ font-size: 13px;
+ min-width: 0;
+}
+.qs-user span {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.qs-foot-acts {
+ display: flex;
+ gap: 2px;
+}
+.qs-ico {
+ display: grid;
+ place-items: center;
+ width: 38px;
+ height: 34px;
+ border-radius: 8px;
+}
+.qs-user:hover,
+.qs-ico:hover {
+ background: var(--hover-b);
+}
+.qs-user:active,
+.qs-ico:active {
+ background: var(--fill);
+}
+.avatar.img {
+ background-size: cover;
+ background-position: center;
+ color: transparent;
+}
+
+/* ---------- Notification centre and calendar ---------- */
+.os-notes {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+ width: min(380px, calc(100vw - 16px));
+ max-height: calc(100vh - var(--task-h) - 24px);
+ padding: 0;
+ background: none;
+ border: 0;
+ box-shadow: none;
+ backdrop-filter: none;
+}
+.nc-panel,
+.nc-cal {
+ background: var(--cm);
+ backdrop-filter: var(--blur-heavy);
+ border: 1px solid var(--hr);
+ border-radius: 14px;
+ box-shadow: var(--shadow-lg);
+}
+.nc-panel {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ flex: 1 1 auto;
+ max-height: 52vh;
+}
+.nc-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ padding: 12px 14px 8px;
+ font-size: 14px;
+}
+.nc-head-acts {
+ display: flex;
+ gap: 4px;
+}
+.nc-dnd,
+.nc-clear {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ padding: 4px 10px;
+ border-radius: 8px;
+ font-size: 12px;
+ background: var(--hover-half);
+}
+.nc-dnd:hover,
+.nc-clear:hover {
+ background: var(--hover-b);
+}
+.nc-dnd[aria-pressed='true'] {
+ color: #fff;
+ background: var(--accent);
+}
+.nc-list {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ padding: 2px 10px 12px;
+ overflow-y: auto;
+ scrollbar-width: thin;
+}
+.nc-card,
+.os-ntoast {
+ position: relative;
+ padding: 10px 12px;
+ border-radius: 10px;
+ background: var(--card);
+ border: 1px solid var(--hr);
+ font-size: 13px;
+ text-align: left;
+}
+.nc-card.link,
+.os-ntoast.link {
+ cursor: pointer;
+}
+.nc-card.link:hover {
+ background: var(--hover);
+}
+.nt-head {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin-bottom: 6px;
+ font-size: 11px;
+ color: var(--text2);
+}
+.nt-head span {
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.nt-head .app-tile.xs {
+ width: 18px;
+ height: 18px;
+ border-radius: 5px;
+}
+.nt-head time {
+ font-size: 11px;
+}
+.nt-x {
+ display: grid;
+ place-items: center;
+ width: 22px;
+ height: 22px;
+ border-radius: 6px;
+ opacity: 0;
+ transition: opacity 0.12s, background 0.12s;
+}
+.nc-card:hover .nt-x,
+.os-ntoast:hover .nt-x,
+.nt-x:focus-visible {
+ opacity: 1;
+}
+.nt-x:hover {
+ background: var(--hover-b);
+}
+.nc-card b,
+.os-ntoast b {
+ display: block;
+ font-weight: 600;
+}
+.nc-card p,
+.os-ntoast p {
+ margin: 3px 0 0;
+ color: var(--text2);
+ line-height: 1.4;
+}
+.nc-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 6px;
+ padding: 26px 18px 30px;
+ color: var(--text2);
+ text-align: center;
+}
+.nc-empty b {
+ color: var(--text);
+ font-weight: 600;
+}
+.nc-empty small {
+ max-width: 260px;
+ line-height: 1.45;
+}
+.nc-cal {
+ padding: 14px;
+ flex: none;
+}
+.cal-today {
+ display: flex;
+ flex-direction: column;
+ padding-bottom: 10px;
+ margin-bottom: 8px;
+ border-bottom: 1px solid var(--hr);
+}
+.cal-today b {
+ font-size: 15px;
+ font-weight: 600;
+}
+.cal-today span {
+ font-size: 12px;
+ color: var(--text2);
+}
+.nc-cal .cal-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin-bottom: 6px;
+ font-size: 13px;
+ font-weight: 600;
+}
+.nc-cal .cal-head button {
+ display: inline-grid;
+ place-items: center;
+ width: 28px;
+ height: 26px;
+ border-radius: 7px;
+}
+.nc-cal .cal-head button:hover {
+ background: var(--hover-b);
+}
+.nc-cal .cal-grid {
+ display: grid;
+ grid-template-columns: repeat(7, 1fr);
+ gap: 2px;
+ text-align: center;
+ font-size: 12px;
+}
+.nc-cal .cal-grid i {
+ font-style: normal;
+ color: var(--text2);
+ padding: 4px 0;
+}
+.nc-cal .cal-grid b {
+ display: grid;
+ place-items: center;
+ justify-self: center;
+ width: 34px;
+ height: 34px;
+ padding: 0;
+ border-radius: 50%;
+ font-weight: 400;
+}
+.nc-cal .cal-grid b.mute {
+ color: var(--text2);
+ opacity: 0.55;
+}
+
+/* ---------- Toasts ---------- */
+.os-ntoasts {
+ position: absolute;
+ right: 12px;
+ bottom: calc(var(--task-h) + 12px);
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ width: min(360px, calc(100vw - 24px));
+ z-index: 10003;
+ pointer-events: none;
+}
+.os-ntoast {
+ pointer-events: auto;
+ background: var(--cm);
+ backdrop-filter: var(--blur-heavy);
+ box-shadow: var(--shadow-md);
+ animation: nt-in 0.35s var(--ease-decel);
+}
+.os-ntoast.out {
+ opacity: 0;
+ transform: translateX(24px);
+ transition: opacity 0.2s, transform 0.2s;
+}
+@keyframes nt-in {
+ from {
+ opacity: 0;
+ transform: translateX(40px);
+ }
+}
+
+/* ---------- Dialogs (Run, About, Rename) ---------- */
+.os-dialog-wrap {
+ position: absolute;
+ inset: 0;
+ display: grid;
+ place-items: center;
+ padding: 16px;
+ background: #0005;
+ z-index: 20000;
+ animation: fade-in 0.15s;
+}
+.os-dialog-wrap.out {
+ opacity: 0;
+ transition: opacity 0.15s;
+}
+@keyframes fade-in {
+ from {
+ opacity: 0;
+ }
+}
+.os-dialog {
+ width: min(440px, 100%);
+ max-height: calc(100vh - 32px);
+ display: flex;
+ flex-direction: column;
+ background: var(--cm);
+ backdrop-filter: var(--blur-heavy);
+ border: 1px solid var(--hr);
+ border-radius: 12px;
+ box-shadow: var(--shadow-focus);
+ animation: pop-in 0.2s var(--ease-decel);
+ overflow: hidden;
+}
+.os-dialog.about {
+ width: min(520px, 100%);
+}
+.dlg-head {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 10px 8px 10px 14px;
+ font-size: 13px;
+}
+.dlg-head b {
+ flex: 1;
+ font-weight: 600;
+}
+.dlg-x {
+ display: grid;
+ place-items: center;
+ width: 32px;
+ height: 28px;
+ border-radius: 7px;
+}
+.dlg-x:hover {
+ background: #e81123;
+ color: #fff;
+}
+.dlg-body {
+ padding: 6px 18px 16px;
+ overflow-y: auto;
+ font-size: 13px;
+ line-height: 1.5;
+}
+.dlg-foot {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+ padding: 12px 16px;
+ background: var(--bg30);
+ border-top: 1px solid var(--hr);
+}
+.os-dialog .os-btn {
+ min-width: 88px;
+ justify-content: center;
+}
+.run-body p {
+ margin: 0 0 12px;
+ color: var(--text2);
+}
+.run-field {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+}
+.run-field input {
+ flex: 1;
+ min-width: 0;
+ height: 34px;
+ padding: 0 10px;
+ border-radius: 7px;
+ border: 1px solid var(--hr);
+ border-bottom: 2px solid var(--accent);
+ background: var(--bg30);
+ color: var(--text);
+ font: inherit;
+ outline: 0;
+ user-select: text;
+}
+.run-body .run-err {
+ margin: 10px 0 0;
+ color: #f87171;
+}
+.about-hero {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ padding: 10px 0 16px;
+ color: var(--accent);
+}
+.about-hero b {
+ display: block;
+ font-size: 22px;
+ font-weight: 600;
+ color: var(--text);
+}
+.about-hero span {
+ color: var(--text2);
+}
+.about-specs {
+ display: grid;
+ grid-template-columns: max-content 1fr;
+ gap: 6px 16px;
+ margin: 0;
+ padding: 12px 14px;
+ border-radius: 10px;
+ background: var(--bg30);
+ border: 1px solid var(--hr);
+}
+.about-specs dt {
+ color: var(--text2);
+}
+.about-specs dd {
+ margin: 0;
+ overflow-wrap: anywhere;
+}
+.about-legal {
+ margin: 12px 0 0;
+ font-size: 12px;
+ color: var(--text2);
+}
+
+/* ---------- Lock screen ---------- */
+.os-lockscreen {
+ position: absolute;
+ inset: 0;
+ z-index: 20040;
+ display: grid;
+ place-items: center;
+ color: #fff;
+ outline: 0;
+ overflow: hidden;
+ animation: fade-in 0.35s;
+}
+.os-lockscreen::before {
+ content: '';
+ position: absolute;
+ inset: -40px;
+ transition: filter 0.4s, transform 0.4s;
+ background:
+ radial-gradient(circle 220px at 18% 26%, #7fb2ff40 0%, #6a5cff30 62%, #c7b8ff80 96%, transparent 100%),
+ radial-gradient(circle 300px at 74% 72%, #5ee0ff30 0%, #3b6cff28 62%, #a6e9ff70 96%, transparent 100%),
+ radial-gradient(circle 120px at 80% 20%, #ff9de240 0%, #b45cff30 62%, #ffc4f280 96%, transparent 100%),
+ linear-gradient(140deg, #0c1238, #241052 50%, #071a3c);
+}
+.os-lockscreen.sign::before {
+ filter: blur(28px) brightness(0.7);
+ transform: scale(1.05);
+}
+.os-lockscreen.out {
+ transform: translateY(-100%);
+ transition: transform 0.45s var(--ease-decel);
+}
+.ls-face,
+.ls-sign {
+ position: relative;
+ grid-area: 1 / 1;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ text-align: center;
+ transition: opacity 0.3s, transform 0.35s var(--ease-decel);
+}
+.ls-face {
+ align-self: start;
+ margin-top: 12vh;
+ text-shadow: 0 2px 20px #0006;
+}
+.ls-time {
+ font-size: clamp(64px, 12vw, 128px);
+ font-weight: 200;
+ letter-spacing: -2px;
+ line-height: 1;
+ font-variant-numeric: tabular-nums;
+}
+.ls-date {
+ margin-top: 10px;
+ font-size: clamp(16px, 2.2vw, 24px);
+ font-weight: 400;
+}
+.ls-hint {
+ margin-top: 40vh;
+ font-size: 13px;
+ opacity: 0.75;
+ animation: ls-hint 2.4s ease-in-out infinite;
+}
+@keyframes ls-hint {
+ 50% {
+ opacity: 0.35;
+ }
+}
+.ls-sign {
+ gap: 14px;
+ opacity: 0;
+ transform: translateY(24px);
+ pointer-events: none;
+}
+.os-lockscreen.sign .ls-face {
+ opacity: 0;
+ transform: translateY(-40px);
+ pointer-events: none;
+}
+.os-lockscreen.sign .ls-sign {
+ opacity: 1;
+ transform: none;
+ pointer-events: auto;
+}
+.ls-av {
+ width: 132px;
+ height: 132px;
+ font-size: 46px;
+ border: 3px solid #ffffff40;
+ box-shadow: 0 16px 48px #0008;
+}
+.ls-name {
+ font-size: 26px;
+ font-weight: 500;
+}
+.ls-go {
+ min-width: 140px;
+ padding: 9px 22px;
+ border-radius: 10px;
+ color: #fff;
+ background: #ffffff26;
+ border: 1px solid #ffffff40;
+ backdrop-filter: var(--blur-light);
+ font-size: 14px;
+ transition: background 0.15s;
+}
+.ls-go:hover {
+ background: #ffffff3d;
+}
+.ls-go:active {
+ background: #ffffff1a;
+}
+.ls-corner {
+ position: absolute;
+ bottom: 24px;
+ display: flex;
+ gap: 8px;
+}
+.ls-left {
+ left: 24px;
+}
+.ls-right {
+ right: 24px;
+}
+.ls-chip {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ min-width: 40px;
+ height: 40px;
+ padding: 0 10px;
+ justify-content: center;
+ border-radius: 10px;
+ color: #fff;
+ font-size: 13px;
+}
+button.ls-chip:hover {
+ background: #ffffff26;
+}
+button.ls-chip:active {
+ background: #ffffff1a;
+}
+
+/* ---------- Power (restart, shut down) ---------- */
+.os-power {
+ position: absolute;
+ inset: 0;
+ z-index: 20060;
+ display: grid;
+ place-content: center;
+ justify-items: center;
+ gap: 22px;
+ color: #fff;
+ background: #0b1030;
+ font-size: 16px;
+ animation: fade-in 0.3s;
+}
+.os-power.off {
+ background: #000;
+}
+.os-power p {
+ margin: 0;
+}
+.pw-spin {
+ position: relative;
+ width: 44px;
+ height: 44px;
+}
+.pw-spin i {
+ position: absolute;
+ inset: 0;
+ animation: pw-orbit 2.2s infinite;
+}
+.pw-spin i::before {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 50%;
+ width: 5px;
+ height: 5px;
+ margin-left: -2.5px;
+ border-radius: 50%;
+ background: #fff;
+}
+.pw-spin i:nth-child(2) {
+ animation-delay: 0.12s;
+}
+.pw-spin i:nth-child(3) {
+ animation-delay: 0.24s;
+}
+.pw-spin i:nth-child(4) {
+ animation-delay: 0.36s;
+}
+.pw-spin i:nth-child(5) {
+ animation-delay: 0.48s;
+}
+@keyframes pw-orbit {
+ 0% {
+ transform: rotate(0);
+ opacity: 1;
+ animation-timing-function: cubic-bezier(0.5, 0, 0.6, 1);
+ }
+ 45% {
+ transform: rotate(300deg);
+ animation-timing-function: linear;
+ }
+ 60% {
+ transform: rotate(420deg);
+ animation-timing-function: cubic-bezier(0.4, 0, 0.5, 1);
+ }
+ 100% {
+ transform: rotate(720deg);
+ opacity: 0.2;
+ }
+}
+.os-power.off .pw-spin,
+.os-power.off > p:not(.pw-hint) {
+ display: none;
+}
+.pw-on {
+ display: grid;
+ place-items: center;
+ width: 72px;
+ height: 72px;
+ border-radius: 50%;
+ color: #fff;
+ background: #ffffff14;
+ border: 1px solid #ffffff30;
+ transition: background 0.15s, box-shadow 0.2s;
+}
+.pw-on:hover {
+ background: #ffffff24;
+ box-shadow: 0 0 0 8px #ffffff10;
+}
+.pw-hint {
+ font-size: 13px;
+ color: #ffffff99;
+}
+
+/* ---------- Desktop drop target ---------- */
+.os-icons.drop {
+ outline: 2px dashed var(--accent);
+ outline-offset: -6px;
+ border-radius: 12px;
+ background: #ffffff0c;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .ls-hint,
+ .pw-spin i {
+ animation: none;
+ }
+}
+
+/* Desktop widgets live between the icons and the windows. */
+.os-widgets-host {
+ position: absolute;
+ inset: 0;
+ z-index: 0;
+ pointer-events: none;
+}
+.os-tb.os-assist .ico {
+ color: var(--accent);
+}
diff --git a/src/desktop/chrome/index.js b/src/desktop/chrome/index.js
new file mode 100644
index 000000000..fbf6c44a5
--- /dev/null
+++ b/src/desktop/chrome/index.js
@@ -0,0 +1,747 @@
+// The desktop's system chrome: tray status (network, volume, battery), the
+// clock, quick settings, the notification centre with its calendar, toasts,
+// the lock screen, power (lock, sign out, restart, shut down), and the Run
+// and About dialogs. Every reading is live: the Battery API, the Network
+// Information API, navigator.storage, navigator.userAgentData, the session.
+// The shell owns popover stacking (openPop/closePops) and hands it in here.
+
+import './chrome.css';
+import { icon, registerGlyph } from '../icons.js';
+import { formatBytes } from '../layout.js';
+import { formatClock, batteryInfo, networkInfo, addNotification, sanitizeNotifications, relTime, parseRun, RUN_ALIASES } from './logic.js';
+
+registerGlyph('mute', '<path d="M4 9h3.5L12 5v14l-4.5-4H4zM16 9.5l5 5M21 9.5l-5 5"/>');
+registerGlyph('assistant', '<path d="M12 3.5c.6 3.6 2.4 5.4 6 6-3.6.6-5.4 2.4-6 6-.6-3.6-2.4-5.4-6-6 3.6-.6 5.4-2.4 6-6z"/><path d="M18.5 15.5c.3 1.7 1.1 2.5 2.5 2.8-1.4.3-2.2 1.1-2.5 2.7-.3-1.6-1.1-2.4-2.5-2.7 1.4-.3 2.2-1.1 2.5-2.8z"/>');
+
+const NOTES_KEY = 'tws:notifications';
+const OS_VERSION = '12.0';
+
+const h = (tag, cls, html) => {
+ const el = document.createElement(tag);
+ if (cls) el.className = cls;
+ if (html != null) el.innerHTML = html;
+ return el;
+};
+const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
+const button = (cls, html, label) => {
+ const b = h('button', cls, html);
+ b.type = 'button';
+ if (label) {
+ b.setAttribute('aria-label', label);
+ b.title = label;
+ }
+ return b;
+};
+const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
+
+/** Resolve after `el` finishes its CSS transition/animation (or at once with reduced motion). */
+function settle(el) {
+ if (reduced()) return Promise.resolve();
+ return new Promise((res) => {
+ el.addEventListener('transitionend', res, { once: true });
+ el.addEventListener('animationend', res, { once: true });
+ });
+}
+
+/** A soft two-note ping, synthesised so it works offline. Honours the volume slider. */
+function ping(volume) {
+ if (!(volume > 0)) return;
+ try {
+ const Ctx = globalThis.AudioContext || globalThis.webkitAudioContext;
+ if (!Ctx) return;
+ const ctx = new Ctx();
+ if (ctx.state === 'suspended') {
+ ctx.close().catch(() => {});
+ return;
+ }
+ const t = ctx.currentTime;
+ const g = ctx.createGain();
+ g.gain.value = 0.0001;
+ g.connect(ctx.destination);
+ const peak = 0.18 * (volume / 100);
+ g.gain.exponentialRampToValueAtTime(Math.max(0.0002, peak), t + 0.02);
+ g.gain.exponentialRampToValueAtTime(0.0001, t + 0.7);
+ [[880, 0], [1318.5, 0.09]].forEach(([f, dt]) => {
+ const o = ctx.createOscillator();
+ o.type = 'sine';
+ o.frequency.value = f;
+ o.connect(g);
+ o.start(t + dt);
+ o.stop(t + dt + 0.6);
+ });
+ setTimeout(() => ctx.close().catch(() => {}), 1200);
+ } catch {
+ /* audio unavailable */
+ }
+}
+
+/**
+ * @param {object} sh shell services: root, store, prefs(), setPrefs(patch), onPrefs(fn),
+ * openPop(kind, el, trigger, onClose), closePops(), menu(x, y, items), launchId(id, o),
+ * resolveApp(id), searchApps(q), wm, save(), displayName(), account(), tile(app,size,glyph),
+ * goClassic()
+ */
+export function createChrome(sh) {
+ const { root, store } = sh;
+ let notes = sanitizeNotifications(store.get(NOTES_KEY));
+ const noteListeners = new Set();
+ const saveNotes = () => {
+ store.set(NOTES_KEY, JSON.stringify(notes));
+ noteListeners.forEach((fn) => fn());
+ };
+
+ // ---------- screen overlays: brightness, night light, energy saver ----------
+ const dim = h('div', 'os-dim');
+ const night = h('div', 'os-night');
+ dim.setAttribute('aria-hidden', 'true');
+ night.setAttribute('aria-hidden', 'true');
+ root.append(night, dim);
+ function applyScreen(p) {
+ dim.style.opacity = String(((100 - p.brightness) / 100) * 0.85);
+ night.classList.toggle('on', p.nightLight);
+ root.classList.toggle('os-saver', p.saver);
+ }
+ applyScreen(sh.prefs());
+ sh.onPrefs(applyScreen);
+
+ // ---------- toasts ----------
+ const toasts = h('div', 'os-ntoasts');
+ toasts.setAttribute('role', 'status');
+ toasts.setAttribute('aria-live', 'polite');
+ root.append(toasts);
+ function toastCard({ title, body = '', app = '' }, ms = 5200) {
+ const a = app ? sh.resolveApp(app) : null;
+ const card = h('div', 'os-ntoast');
+ card.innerHTML =
+ `<div class="nt-head">${a ? sh.tile(a, 'xs', 12) : icon('logo', 14)}<span>${esc(a ? a.title : 'three.ws')}</span>` +
+ `<button type="button" class="nt-x" aria-label="Dismiss">${icon('close', 12)}</button></div>` +
+ `<b></b>${body ? '<p></p>' : ''}`;
+ card.querySelector('b').textContent = title;
+ if (body) card.querySelector('p').textContent = body;
+ let timer = 0;
+ const close = () => {
+ clearTimeout(timer);
+ if (!card.isConnected || card.classList.contains('out')) return;
+ card.classList.add('out');
+ settle(card).then(() => card.remove());
+ };
+ card.querySelector('.nt-x').addEventListener('click', (e) => {
+ e.stopPropagation();
+ close();
+ });
+ if (a) {
+ card.classList.add('link');
+ card.addEventListener('click', () => {
+ close();
+ sh.launchId(a.id);
+ });
+ }
+ const arm = () => (timer = setTimeout(close, ms));
+ card.addEventListener('pointerenter', () => clearTimeout(timer));
+ card.addEventListener('pointerleave', arm);
+ toasts.append(card);
+ while (toasts.children.length > 4) toasts.firstElementChild.remove();
+ arm();
+ }
+ /** Transient message (not kept in the notification centre). */
+ function toast(msg) {
+ toastCard({ title: String(msg) }, 4200);
+ }
+ /** A real notification: kept in the centre, toasted unless Do not disturb is on. */
+ function notify(n) {
+ const before = notes;
+ notes = addNotification(notes, typeof n === 'string' ? { title: n } : n);
+ if (notes === before) return;
+ saveNotes();
+ const p = sh.prefs();
+ if (p.dnd) return;
+ toastCard(notes[0]);
+ if (p.sound) ping(p.volume);
+ }
+
+ // ---------- live system status ----------
+ const status = { battery: null, net: null };
+ const statusListeners = new Set();
+ const emitStatus = () => statusListeners.forEach((fn) => fn(status));
+ function readNet() {
+ const c = navigator.connection;
+ status.net = networkInfo({ online: navigator.onLine, type: c?.type, effectiveType: c?.effectiveType, downlink: c?.downlink, rtt: c?.rtt });
+ emitStatus();
+ }
+ readNet();
+ addEventListener('online', () => {
+ readNet();
+ notify({ title: 'Back online', body: status.net.detail });
+ });
+ addEventListener('offline', () => {
+ readNet();
+ notify({ title: 'You are offline', body: 'three.ws pages will load again when the connection returns. Your files are stored on this device.' });
+ });
+ navigator.connection?.addEventListener?.('change', readNet);
+ let batteryRef = null;
+ let warnedLow = false;
+ if (navigator.getBattery) {
+ navigator
+ .getBattery()
+ .then((b) => {
+ batteryRef = b;
+ const read = () => {
+ status.battery = batteryInfo(b);
+ if (status.battery && !status.battery.charging && status.battery.pct <= 15 && !warnedLow) {
+ warnedLow = true;
+ notify({ title: 'Battery low', body: `${status.battery.pct}% remaining. Plug in or turn on Energy saver in quick settings.` });
+ }
+ if (status.battery?.charging) warnedLow = false;
+ emitStatus();
+ };
+ ['levelchange', 'chargingchange', 'chargingtimechange', 'dischargingtimechange'].forEach((ev) => b.addEventListener(ev, read));
+ read();
+ })
+ .catch(() => {
+ /* no battery API on this device */
+ });
+ }
+
+ // ---------- tray: status pill and clock ----------
+ const statusBtn = button('os-tb os-status', '', 'Quick settings');
+ statusBtn.setAttribute('aria-haspopup', 'dialog');
+ statusBtn.setAttribute('aria-expanded', 'false');
+ function paintStatus() {
+ const p = sh.prefs();
+ const net = status.net;
+ const bat = status.battery;
+ const vol = p.volume === 0 || !p.sound ? 'mute' : 'volume';
+ statusBtn.innerHTML =
+ `<span class="st-ico${net.online ? '' : ' off'}">${icon(net.online ? 'wifi' : 'plane', 16)}</span>` +
+ `<span class="st-ico">${icon(vol === 'mute' ? 'mute' : 'volume', 16)}</span>` +
+ (bat ? `<span class="st-bat ${bat.tier}${bat.charging ? ' chg' : ''}" style="--lvl:${bat.pct}%"><i></i></span>` : '');
+ const parts = [net.online ? `${net.label}, ${net.detail}` : 'Offline', vol === 'mute' ? 'Sound off' : `Volume ${p.volume}%`];
+ if (bat) parts.push(`Battery ${bat.pct}%, ${bat.label}`);
+ statusBtn.title = parts.join('\n');
+ statusBtn.setAttribute('aria-label', `Quick settings. ${parts.join('. ')}`);
+ }
+ statusListeners.add(paintStatus);
+ sh.onPrefs(paintStatus);
+ paintStatus();
+
+ const clockBtn = button('os-clock', '');
+ clockBtn.setAttribute('aria-haspopup', 'dialog');
+ clockBtn.setAttribute('aria-expanded', 'false');
+ function paintClock() {
+ const p = sh.prefs();
+ const d = new Date();
+ const { time, date } = formatClock(d, { clock24: p.clock24 });
+ const unread = notes.length;
+ clockBtn.innerHTML = `<span class="ck-t"><b>${esc(time)}</b><small>${esc(date)}</small></span>${unread && !p.dnd ? `<span class="ck-n" aria-hidden="true">${unread > 9 ? '9+' : unread}</span>` : p.dnd ? `<span class="ck-dnd" aria-hidden="true">${icon('sleep', 14)}</span>` : ''}`;
+ clockBtn.title = d.toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
+ clockBtn.setAttribute('aria-label', `${d.toLocaleString()}. ${unread} notifications. Open notifications and calendar`);
+ }
+ // Align ticks to the minute boundary so the time flips exactly when the minute does.
+ let clockT = 0;
+ (function tick() {
+ paintClock();
+ clockT = setTimeout(tick, 60000 - (Date.now() % 60000) + 5);
+ })();
+ noteListeners.add(paintClock);
+ sh.onPrefs(paintClock);
+
+ // ---------- quick settings ----------
+ function slider(label, glyph, value, min, onInput) {
+ const row = h('label', 'qs-slider', `${icon(glyph, 18)}<input type="range" min="${min}" max="100" step="1" aria-label="${esc(label)}"><output></output>`);
+ const input = row.querySelector('input');
+ const out = row.querySelector('output');
+ input.value = String(value);
+ const paint = () => {
+ out.textContent = `${input.value}%`;
+ input.style.setProperty('--fill', `${((input.value - min) / (100 - min)) * 100}%`);
+ };
+ input.addEventListener('input', () => {
+ paint();
+ onInput(Number(input.value));
+ });
+ paint();
+ return row;
+ }
+ function toggleQuick() {
+ const el = h('div', 'os-pop os-quick');
+ el.setAttribute('role', 'dialog');
+ el.setAttribute('aria-label', 'Quick settings');
+ const grid = h('div', 'qs-grid');
+ const tiles = [
+ { id: 'dark', label: 'Dark mode', glyph: 'moon', on: () => document.documentElement.getAttribute('data-theme') !== 'light', flip: (on) => sh.setPrefs({ mode: on ? 'light' : 'dark' }) },
+ { id: 'night', label: 'Night light', glyph: 'sun', on: () => sh.prefs().nightLight, flip: (on) => sh.setPrefs({ nightLight: !on }) },
+ { id: 'dnd', label: 'Do not disturb', glyph: 'sleep', on: () => sh.prefs().dnd, flip: (on) => sh.setPrefs({ dnd: !on }) },
+ { id: 'saver', label: 'Energy saver', glyph: 'battery', on: () => sh.prefs().saver, flip: (on) => sh.setPrefs({ saver: !on }) },
+ { id: 'sound', label: 'System sounds', glyph: 'volume', on: () => sh.prefs().sound, flip: (on) => sh.setPrefs({ sound: !on }) },
+ {
+ id: 'full',
+ label: 'Full screen',
+ glyph: 'fullscreen',
+ on: () => !!document.fullscreenElement,
+ flip: (on) => (on ? document.exitFullscreen() : document.documentElement.requestFullscreen()).catch(() => toast('Full screen was blocked by the browser.')),
+ hidden: !document.fullscreenEnabled,
+ },
+ ];
+ const tileEls = [];
+ tiles
+ .filter((t) => !t.hidden)
+ .forEach((t) => {
+ const b = button('qs-tile', `${icon(t.glyph, 18)}<span>${esc(t.label)}</span>`);
+ b.setAttribute('aria-pressed', String(!!t.on()));
+ b.addEventListener('click', () => {
+ t.flip(!!t.on());
+ });
+ tileEls.push([b, t]);
+ grid.append(b);
+ });
+ const sync = () => tileEls.forEach(([b, t]) => b.setAttribute('aria-pressed', String(!!t.on())));
+ const offPrefs = sh.onPrefs(sync);
+ const onFs = () => sync();
+ document.addEventListener('fullscreenchange', onFs);
+
+ const p = sh.prefs();
+ const sliders = h('div', 'qs-sliders');
+ sliders.append(
+ slider('Brightness', 'sun', p.brightness, 30, (v) => sh.setPrefs({ brightness: v })),
+ slider('Volume', 'volume', p.volume, 0, (v) => sh.setPrefs({ volume: v })),
+ );
+
+ const info = h('div', 'qs-info');
+ function paintInfo() {
+ const n = status.net;
+ const b = status.battery;
+ info.innerHTML =
+ `<div class="qs-line">${icon(n.online ? 'wifi' : 'plane', 16)}<div><b>${esc(n.label)}</b><small>${esc(n.detail)}</small></div></div>` +
+ (b ? `<div class="qs-line"><span class="st-bat ${b.tier}${b.charging ? ' chg' : ''}" style="--lvl:${b.pct}%"><i></i></span><div><b>${b.pct}%</b><small>${esc(b.label)}</small></div></div>` : '');
+ }
+ paintInfo();
+ statusListeners.add(paintInfo);
+
+ const foot = h('div', 'qs-foot');
+ const user = button('qs-user', `<i class="avatar sm" style="--hue:${p.avatarHue}"></i><span>${esc(sh.displayName())}</span>`, 'Your account settings');
+ user.addEventListener('click', () => sh.launchId('settings', { section: 'profile' }));
+ const gear = button('qs-ico', icon('gear', 18), 'All settings');
+ gear.addEventListener('click', () => sh.launchId('settings'));
+ const pwr = button('qs-ico', icon('power', 18), 'Power');
+ pwr.addEventListener('click', (e) => {
+ const r = pwr.getBoundingClientRect();
+ e.stopPropagation();
+ powerMenu(r.left, r.top - 8, true);
+ });
+ const acts = h('div', 'qs-foot-acts');
+ acts.append(gear, pwr);
+ foot.append(user, acts);
+ paintAvatar(user.querySelector('.avatar'));
+
+ el.append(grid, sliders, info, foot);
+ sh.openPop('quick', el, statusBtn, () => {
+ offPrefs();
+ statusListeners.delete(paintInfo);
+ document.removeEventListener('fullscreenchange', onFs);
+ });
+ }
+ statusBtn.addEventListener('click', toggleQuick);
+
+ // ---------- notification centre + calendar ----------
+ function toggleNotes() {
+ const el = h('div', 'os-pop os-notes');
+ el.setAttribute('role', 'dialog');
+ el.setAttribute('aria-label', 'Notifications and calendar');
+ const panel = h('section', 'nc-panel');
+ const head = h('div', 'nc-head', '<b>Notifications</b>');
+ const dndBtn = button('nc-dnd', '', '');
+ const clear = button('nc-clear', 'Clear all', 'Clear all notifications');
+ clear.addEventListener('click', () => {
+ notes = [];
+ saveNotes();
+ });
+ const paintDnd = () => {
+ const on = sh.prefs().dnd;
+ dndBtn.innerHTML = `${icon('sleep', 14)}<span>${on ? 'Do not disturb is on' : 'Do not disturb'}</span>`;
+ dndBtn.setAttribute('aria-pressed', String(on));
+ };
+ dndBtn.addEventListener('click', () => sh.setPrefs({ dnd: !sh.prefs().dnd }));
+ const headActs = h('div', 'nc-head-acts');
+ headActs.append(dndBtn, clear);
+ head.append(headActs);
+ const list = h('div', 'nc-list');
+ function paintList() {
+ paintDnd();
+ clear.hidden = !notes.length;
+ list.replaceChildren();
+ if (!notes.length) {
+ list.append(h('div', 'nc-empty', `${icon('bell', 28)}<b>You're all caught up</b><small>Saved files, finished downloads, connection changes and app alerts land here.</small>`));
+ return;
+ }
+ const now = Date.now();
+ notes.forEach((n) => {
+ const a = n.app ? sh.resolveApp(n.app) : null;
+ const card = h('div', `nc-card${a ? ' link' : ''}`);
+ card.innerHTML =
+ `<div class="nt-head">${a ? sh.tile(a, 'xs', 12) : icon('logo', 14)}<span>${esc(a ? a.title : 'three.ws')}</span><time>${esc(relTime(n.at, now))}</time>` +
+ `<button type="button" class="nt-x" aria-label="Dismiss notification">${icon('close', 12)}</button></div><b></b>${n.body ? '<p></p>' : ''}`;
+ card.querySelector('b').textContent = n.title;
+ if (n.body) card.querySelector('p').textContent = n.body;
+ card.querySelector('.nt-x').addEventListener('click', (e) => {
+ e.stopPropagation();
+ notes = notes.filter((x) => x.id !== n.id);
+ saveNotes();
+ });
+ if (a)
+ card.addEventListener('click', () => {
+ sh.closePops();
+ sh.launchId(a.id);
+ });
+ list.append(card);
+ });
+ }
+ panel.append(head, list);
+ paintList();
+ noteListeners.add(paintList);
+ const offPrefs = sh.onPrefs(paintDnd);
+
+ const cal = h('section', 'nc-cal');
+ let view = new Date();
+ view.setDate(1);
+ function paintCal() {
+ const today = new Date();
+ const first = new Date(view.getFullYear(), view.getMonth(), 1);
+ const start = new Date(first);
+ start.setDate(1 - first.getDay());
+ const cells = [];
+ for (let i = 0; i < 42; i++) {
+ const d = new Date(start);
+ d.setDate(start.getDate() + i);
+ const cls = [d.getMonth() !== view.getMonth() ? 'mute' : '', d.toDateString() === today.toDateString() ? 'today' : ''].join(' ').trim();
+ cells.push(`<b class="${cls}"${cls.includes('today') ? ' aria-current="date"' : ''}>${d.getDate()}</b>`);
+ }
+ const dow = [...Array(7)].map((_, i) => `<i>${new Date(2024, 0, 7 + i).toLocaleDateString([], { weekday: 'narrow' })}</i>`).join('');
+ cal.innerHTML =
+ `<div class="cal-today"><b>${esc(today.toLocaleDateString([], { weekday: 'long' }))}</b><span>${esc(today.toLocaleDateString([], { month: 'long', day: 'numeric', year: 'numeric' }))}</span></div>` +
+ `<div class="cal-head"><span>${esc(view.toLocaleDateString([], { month: 'long', year: 'numeric' }))}</span><span>` +
+ `<button type="button" data-d="0" aria-label="Back to this month">${icon('home', 13)}</button>` +
+ `<button type="button" data-d="-1" aria-label="Previous month">${icon('chevron', 14).replace('<svg', '<svg style="transform:rotate(180deg)"')}</button>` +
+ `<button type="button" data-d="1" aria-label="Next month">${icon('chevron', 14)}</button></span></div>` +
+ `<div class="cal-grid" role="grid">${dow}${cells.join('')}</div>`;
+ cal.querySelectorAll('[data-d]').forEach((b) =>
+ b.addEventListener('click', () => {
+ const d = Number(b.dataset.d);
+ view = d ? new Date(view.getFullYear(), view.getMonth() + d, 1) : new Date(new Date().getFullYear(), new Date().getMonth(), 1);
+ paintCal();
+ }),
+ );
+ }
+ paintCal();
+ el.append(panel, cal);
+ sh.openPop('notes', el, clockBtn, () => {
+ noteListeners.delete(paintList);
+ offPrefs();
+ });
+ }
+ clockBtn.addEventListener('click', toggleNotes);
+
+ // ---------- dialogs ----------
+ function dialog({ title, glyph = 'logo', body, buttons = [], cls = '' }) {
+ sh.closePops();
+ root.querySelector('.os-dialog-wrap')?.remove();
+ const wrap = h('div', 'os-dialog-wrap');
+ const dlg = h('div', `os-dialog ${cls}`.trim());
+ dlg.setAttribute('role', 'dialog');
+ dlg.setAttribute('aria-modal', 'true');
+ dlg.setAttribute('aria-label', title);
+ dlg.innerHTML = `<div class="dlg-head">${icon(glyph, 18)}<b></b><button type="button" class="dlg-x" aria-label="Close">${icon('close', 14)}</button></div><div class="dlg-body"></div><div class="dlg-foot"></div>`;
+ dlg.querySelector('b').textContent = title;
+ const bodyEl = dlg.querySelector('.dlg-body');
+ if (typeof body === 'string') bodyEl.innerHTML = body;
+ else if (body) bodyEl.append(body);
+ const prevFocus = document.activeElement;
+ const close = () => {
+ wrap.classList.add('out');
+ removeEventListener('keydown', onKey, true);
+ settle(wrap).then(() => wrap.remove());
+ if (prevFocus?.isConnected) prevFocus.focus({ preventScroll: true });
+ };
+ const foot = dlg.querySelector('.dlg-foot');
+ buttons.forEach(([label, fn, primary]) => {
+ const b = button(`os-btn${primary ? ' primary' : ''}`, esc(label));
+ b.addEventListener('click', () => {
+ if (fn?.() === false) return;
+ close();
+ });
+ foot.append(b);
+ });
+ dlg.querySelector('.dlg-x').addEventListener('click', close);
+ function onKey(e) {
+ if (e.key === 'Escape') {
+ e.stopPropagation();
+ close();
+ }
+ }
+ addEventListener('keydown', onKey, true);
+ wrap.addEventListener('pointerdown', (e) => e.target === wrap && close());
+ wrap.append(dlg);
+ root.append(wrap);
+ (dlg.querySelector('input') || foot.querySelector('.primary') || dlg.querySelector('.dlg-x')).focus({ preventScroll: true });
+ return { el: dlg, close };
+ }
+
+ function runDialog() {
+ const body = h('div', 'run-body', `<p>Type the name of an app, a three.ws page, a folder or a website, and three.ws will open it for you.</p><label class="run-field"><span>Open:</span><input type="text" autocomplete="off" spellcheck="false" list="os-run-list" aria-label="Open"></label><datalist id="os-run-list"></datalist><p class="run-err" role="alert" hidden></p>`);
+ const input = body.querySelector('input');
+ const err = body.querySelector('.run-err');
+ const listEl = body.querySelector('datalist');
+ const history = (() => {
+ try {
+ const v = JSON.parse(store.get('tws:run') || '[]');
+ return Array.isArray(v) ? v.filter((x) => typeof x === 'string').slice(0, 12) : [];
+ } catch {
+ return [];
+ }
+ })();
+ history.forEach((v) => listEl.append(Object.assign(document.createElement('option'), { value: v })));
+ input.value = history[0] || '';
+ const go = () => {
+ const raw = input.value.trim();
+ const r = parseRun(raw);
+ let ok = true;
+ if (r.kind === 'empty') ok = false;
+ else if (r.kind === 'url') window.open(r.value, '_blank', 'noopener');
+ else if (r.kind === 'file') sh.launchId('files', { arg: r.value });
+ else if (r.kind === 'path') {
+ const app = sh.searchApps('').find((a) => a.href === r.value);
+ if (app) sh.launchId(app.id);
+ else sh.openPath(r.value);
+ } else {
+ const alias = RUN_ALIASES[r.value];
+ if (alias === 'about') aboutDialog();
+ else if (alias && sh.resolveApp(alias)) sh.launchId(alias);
+ else {
+ const hit = sh.searchApps(r.value)[0];
+ if (hit) sh.launchId(hit.id);
+ else ok = false;
+ }
+ }
+ if (!ok) {
+ err.hidden = false;
+ err.textContent = raw ? `three.ws cannot find "${raw}". Check the name, then try again.` : 'Type something to open.';
+ input.select();
+ return false;
+ }
+ store.set('tws:run', JSON.stringify([raw, ...history.filter((x) => x !== raw)].slice(0, 12)));
+ return true;
+ };
+ const d = dialog({ title: 'Run', glyph: 'terminal', body, cls: 'run', buttons: [['OK', go, true], ['Cancel'], ['Browse...', () => (sh.launchId('files'), true)]] });
+ input.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ if (go()) d.close();
+ }
+ });
+ input.select();
+ }
+
+ async function aboutDialog() {
+ const body = h('div', 'about-body');
+ body.innerHTML = `<div class="about-hero">${icon('logo', 44)}<div><b>three.ws OS</b><span>Version ${OS_VERSION}</span></div></div><dl class="about-specs"></dl><p class="about-legal">three.ws OS runs in your browser. Your desktop, files and settings are stored on this device; three.ws pages and your account live on three.ws.</p>`;
+ const specs = body.querySelector('dl');
+ const row = (k, v) => v && specs.insertAdjacentHTML('beforeend', `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`);
+ const ua = navigator.userAgentData;
+ let browser = '';
+ let platform = navigator.platform || '';
+ try {
+ if (ua?.getHighEntropyValues) {
+ const v = await ua.getHighEntropyValues(['fullVersionList', 'platformVersion', 'architecture', 'model']);
+ const b = (v.fullVersionList || []).find((x) => !/Not.?A.?Brand|Chromium/i.test(x.brand)) || (v.fullVersionList || [])[0];
+ if (b) browser = `${b.brand} ${b.version}`;
+ platform = [ua.platform, v.platformVersion, v.architecture].filter(Boolean).join(' ');
+ }
+ } catch {
+ /* high entropy hints refused */
+ }
+ if (!browser) {
+ const m = navigator.userAgent.match(/(Firefox|Edg|OPR|Chrome|Safari)\/([\d.]+)/);
+ if (m) browser = `${{ Edg: 'Edge', OPR: 'Opera' }[m[1]] || m[1]} ${m[2]}`;
+ }
+ row('Device name', sh.displayName() === 'Guest' ? location.host : `${sh.displayName()}'s three.ws`);
+ row('Browser', browser);
+ row('Platform', platform);
+ row('Processor', navigator.hardwareConcurrency ? `${navigator.hardwareConcurrency} logical cores` : '');
+ row('Memory', navigator.deviceMemory ? `${navigator.deviceMemory} GB or more` : '');
+ row('Display', `${screen.width} x ${screen.height} at ${devicePixelRatio}x, ${screen.colorDepth}-bit color`);
+ try {
+ const est = await navigator.storage.estimate();
+ if (est.quota) row('Storage', `${formatBytes(est.usage || 0)} used of ${formatBytes(est.quota)}`);
+ } catch {
+ /* storage estimate unsupported */
+ }
+ row('Network', status.net.online ? `${status.net.label}, ${status.net.detail}` : 'Offline');
+ if (status.battery) row('Battery', `${status.battery.pct}%, ${status.battery.label}`);
+ row('Account', sh.account() ? sh.account().email || sh.displayName() : 'Not signed in');
+ dialog({ title: 'About three.ws OS', glyph: 'logo', body, cls: 'about', buttons: [['Changelog', () => (sh.openPath('/changelog'), true)], ['OK', null, true]] });
+ }
+
+ // ---------- power ----------
+ function powerMenu(x, y, above = false) {
+ const items = [
+ ['Lock', 'lock', () => lock()],
+ ...(sh.account() ? [['Sign out', 'user', () => signOut()]] : [['Sign in', 'user', () => sh.openPath('/login')]]),
+ '-',
+ ['Restart', 'restart', () => power('restart')],
+ ['Shut down', 'power', () => power('shutdown')],
+ ];
+ sh.menu(x, y, items, above);
+ }
+
+ async function signOut() {
+ try {
+ const r = await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' });
+ if (!r.ok) throw new Error(`HTTP ${r.status}`);
+ } catch (e) {
+ toast(`Could not sign out (${e.message}). Check your connection and try again.`);
+ return;
+ }
+ await power('restart', 'Signing out');
+ }
+
+ /** Shut down closes every window and saves the session, then leaves a dark screen with a power button; restart does the same and reloads. */
+ async function power(kind, label) {
+ sh.closePops();
+ const screen = h('div', `os-power ${kind}`);
+ screen.setAttribute('role', 'alertdialog');
+ screen.setAttribute('aria-live', 'assertive');
+ const text = label || (kind === 'restart' ? 'Restarting' : 'Shutting down');
+ screen.innerHTML = `<div class="pw-spin" aria-hidden="true"><i></i><i></i><i></i><i></i><i></i></div><p>${esc(text)}</p>`;
+ root.append(screen);
+ await settle(screen);
+ sh.save();
+ const closing = sh.wm.list().length;
+ sh.wm.closeAll();
+ if (closing && !reduced()) await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
+ if (kind === 'restart') {
+ location.reload();
+ return;
+ }
+ screen.classList.add('off');
+ screen.innerHTML = '';
+ const on = button('pw-on', icon('power', 30), 'Power on');
+ on.addEventListener('click', () => location.reload());
+ screen.append(on, h('p', 'pw-hint', 'three.ws OS is shut down. Press the power button to start it again.'));
+ on.focus({ preventScroll: true });
+ }
+
+ // ---------- lock screen ----------
+ let lockEl = null;
+ function paintAvatar(av) {
+ const a = sh.account();
+ const p = sh.prefs();
+ av.style.setProperty('--hue', String(p.avatarHue));
+ if (a?.avatar_url && /^https?:\/\//.test(a.avatar_url)) {
+ av.textContent = '';
+ av.style.backgroundImage = `url("${a.avatar_url.replace(/"/g, '%22')}")`;
+ av.classList.add('img');
+ } else {
+ av.textContent = (sh.displayName() || '?').trim().split(/\s+/).map((s) => s[0]).slice(0, 2).join('').toUpperCase();
+ }
+ }
+ function lock() {
+ if (lockEl) return;
+ sh.closePops();
+ sh.save();
+ const el = h('div', 'os-lockscreen');
+ el.setAttribute('role', 'dialog');
+ el.setAttribute('aria-modal', 'true');
+ el.setAttribute('aria-label', 'Locked');
+ el.innerHTML =
+ `<div class="ls-face"><time class="ls-time"></time><div class="ls-date"></div><p class="ls-hint">Press any key or click to unlock</p></div>` +
+ `<div class="ls-sign"><i class="avatar ls-av"></i><b class="ls-name"></b><button type="button" class="ls-go">Sign in</button></div>` +
+ `<div class="ls-corner ls-left"></div><div class="ls-corner ls-right"></div>`;
+ const timeEl = el.querySelector('.ls-time');
+ const dateEl = el.querySelector('.ls-date');
+ const tickLock = () => {
+ const d = new Date();
+ timeEl.textContent = formatClock(d, { clock24: sh.prefs().clock24 }).time.replace(/\s?[AP]M$/i, '');
+ timeEl.dateTime = d.toISOString();
+ dateEl.textContent = d.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric' });
+ };
+ tickLock();
+ const t = setInterval(tickLock, 1000);
+ paintAvatar(el.querySelector('.ls-av'));
+ el.querySelector('.ls-name').textContent = sh.displayName();
+ const left = el.querySelector('.ls-left');
+ const net = status.net;
+ left.innerHTML = `<span class="ls-chip" title="${esc(net.online ? `${net.label}, ${net.detail}` : 'Offline')}">${icon(net.online ? 'wifi' : 'plane', 18)}</span>` + (status.battery ? `<span class="ls-chip" title="${esc(status.battery.label)}"><span class="st-bat ${status.battery.tier}${status.battery.charging ? ' chg' : ''}" style="--lvl:${status.battery.pct}%"><i></i></span>${status.battery.pct}%</span>` : '');
+ const right = el.querySelector('.ls-right');
+ const rs = button('ls-chip', icon('restart', 18), 'Restart');
+ rs.addEventListener('click', (e) => (e.stopPropagation(), power('restart')));
+ const sd = button('ls-chip', icon('power', 18), 'Shut down');
+ sd.addEventListener('click', (e) => (e.stopPropagation(), power('shutdown')));
+ right.append(rs, sd);
+ const go = el.querySelector('.ls-go');
+ const reveal = () => {
+ if (el.classList.contains('sign')) return;
+ el.classList.add('sign');
+ go.focus({ preventScroll: true });
+ };
+ const unlock = () => {
+ clearInterval(t);
+ removeEventListener('keydown', onKey, true);
+ el.classList.add('out');
+ settle(el).then(() => el.remove());
+ lockEl = null;
+ };
+ function onKey(e) {
+ if (e.key === 'Tab') return;
+ e.stopPropagation();
+ if (!el.classList.contains('sign')) {
+ e.preventDefault();
+ reveal();
+ } else if (e.key === 'Escape') {
+ e.preventDefault();
+ el.classList.remove('sign');
+ }
+ }
+ go.addEventListener('click', (e) => {
+ e.stopPropagation();
+ unlock();
+ });
+ el.addEventListener('click', (e) => {
+ if (!e.target.closest('button')) reveal();
+ });
+ addEventListener('keydown', onKey, true);
+ root.append(el);
+ lockEl = el;
+ el.focus?.();
+ }
+
+ addEventListener('pagehide', () => clearTimeout(clockT));
+
+ return {
+ statusBtn,
+ clockBtn,
+ toast,
+ notify,
+ toggleQuick,
+ toggleNotes,
+ runDialog,
+ aboutDialog,
+ powerMenu,
+ power,
+ lock,
+ dialog,
+ paintAvatar,
+ get notifications() {
+ return notes.slice();
+ },
+ onNotifications(fn) {
+ noteListeners.add(fn);
+ return () => noteListeners.delete(fn);
+ },
+ get status() {
+ return { ...status, battery: batteryRef ? status.battery : null };
+ },
+ onStatus(fn) {
+ statusListeners.add(fn);
+ return () => statusListeners.delete(fn);
+ },
+ };
+}
diff --git a/src/desktop/chrome/logic.js b/src/desktop/chrome/logic.js
new file mode 100644
index 000000000..d5dcd981d
--- /dev/null
+++ b/src/desktop/chrome/logic.js
@@ -0,0 +1,124 @@
+// Pure rules behind the desktop chrome (taskbar status, notification centre,
+// Run dialog, power menu). No DOM here, so every rule is unit tested.
+
+/** Taskbar clock text. Seconds tick like a real system clock when asked. */
+export function formatClock(d, { clock24 = false, seconds = false } = {}) {
+ const time = d.toLocaleTimeString([], {
+ hour: clock24 ? '2-digit' : 'numeric',
+ minute: '2-digit',
+ ...(seconds ? { second: '2-digit' } : {}),
+ hour12: !clock24,
+ });
+ const date = d.toLocaleDateString([], { year: 'numeric', month: 'numeric', day: 'numeric' });
+ return { time, date };
+}
+
+/** Battery API snapshot to what the tray and quick settings show. Null when the browser has no battery. */
+export function batteryInfo(b) {
+ if (!b || !Number.isFinite(b.level)) return null;
+ const pct = Math.round(Math.min(1, Math.max(0, b.level)) * 100);
+ const secs = b.charging ? b.chargingTime : b.dischargingTime;
+ let eta = '';
+ if (Number.isFinite(secs) && secs > 0) {
+ const h = Math.floor(secs / 3600);
+ const m = Math.round((secs % 3600) / 60);
+ eta = h ? `${h} h ${m} min` : `${m} min`;
+ }
+ let label;
+ if (b.charging && pct >= 100) label = 'Fully charged';
+ else if (b.charging) label = eta ? `Charging, full in ${eta}` : 'Charging';
+ else label = eta ? `${eta} remaining` : 'On battery';
+ const tier = pct <= 10 ? 'critical' : pct <= 25 ? 'low' : 'ok';
+ return { pct, charging: !!b.charging, label, tier };
+}
+
+/** navigator.onLine + navigator.connection to a status line. */
+export function networkInfo({ online = true, type = '', effectiveType = '', downlink, rtt } = {}) {
+ if (!online) return { online: false, label: 'Offline', detail: 'No internet connection' };
+ const kind = { wifi: 'Wi-Fi', ethernet: 'Ethernet', cellular: 'Cellular', bluetooth: 'Bluetooth', wimax: 'WiMAX' }[type] || 'Connected';
+ const parts = [];
+ if (effectiveType) parts.push(effectiveType.toUpperCase());
+ if (Number.isFinite(downlink) && downlink > 0) parts.push(`${downlink >= 10 ? Math.round(downlink) : downlink.toFixed(1)} Mbps`);
+ if (Number.isFinite(rtt) && rtt > 0) parts.push(`${Math.round(rtt)} ms`);
+ return { online: true, label: kind, detail: parts.length ? parts.join(' / ') : 'Internet access' };
+}
+
+const MAX_NOTES = 50;
+
+/** Prepend a notification, newest first, capped. Returns a new list. */
+export function addNotification(list, n, now = Date.now(), max = MAX_NOTES) {
+ const title = String(n?.title || '').trim().slice(0, 120);
+ const body = String(n?.body || '').trim().slice(0, 400);
+ if (!title && !body) return list;
+ const note = { id: `${now.toString(36)}${Math.random().toString(36).slice(2, 6)}`, title: title || body, body: title ? body : '', app: typeof n?.app === 'string' ? n.app : '', at: now };
+ return [note, ...(Array.isArray(list) ? list : [])].slice(0, max);
+}
+
+/** Parse stored notifications defensively. */
+export function sanitizeNotifications(raw) {
+ let data = raw;
+ if (typeof raw === 'string') {
+ try {
+ data = JSON.parse(raw);
+ } catch {
+ return [];
+ }
+ }
+ if (!Array.isArray(data)) return [];
+ return data
+ .filter((n) => n && typeof n.id === 'string' && typeof n.title === 'string' && Number.isFinite(n.at))
+ .map((n) => ({ id: n.id, title: n.title.slice(0, 120), body: typeof n.body === 'string' ? n.body.slice(0, 400) : '', app: typeof n.app === 'string' ? n.app : '', at: n.at }))
+ .slice(0, MAX_NOTES);
+}
+
+/** "Just now", "5 min ago", "3 h ago", then a short date. */
+export function relTime(at, now = Date.now()) {
+ const s = Math.max(0, Math.round((now - at) / 1000));
+ if (s < 45) return 'Just now';
+ const m = Math.round(s / 60);
+ if (m < 60) return `${m} min ago`;
+ const h = Math.round(m / 60);
+ if (h < 24) return `${h} h ago`;
+ return new Date(at).toLocaleDateString([], { month: 'short', day: 'numeric' });
+}
+
+/**
+ * What the Run dialog should do with its input.
+ * 'url' opens an outside site in a new tab, 'path' a three.ws page,
+ * 'file' a path in the virtual file system, 'query' searches apps by name.
+ */
+export function parseRun(input) {
+ const v = String(input || '').trim();
+ if (!v) return { kind: 'empty' };
+ if (/^https?:\/\//i.test(v)) return { kind: 'url', value: v };
+ if (/^[\w-]+(\.[\w-]+)+(\/\S*)?$/.test(v) && !v.startsWith('/')) return { kind: 'url', value: `https://${v}` };
+ if (/^~(\/|$)/.test(v)) return { kind: 'file', value: v.replace(/^~/, '') || '/' };
+ if (/^\/(Desktop|Documents|Pictures|Downloads|Music|Videos|Trash)(\/|$)/.test(v)) return { kind: 'file', value: v };
+ if (v.startsWith('/')) return { kind: 'path', value: v };
+ return { kind: 'query', value: v.toLowerCase() };
+}
+
+/** Classic command aliases people type into Run. */
+export const RUN_ALIASES = {
+ cmd: 'terminal',
+ powershell: 'terminal',
+ bash: 'terminal',
+ sh: 'terminal',
+ terminal: 'terminal',
+ notepad: 'notepad',
+ calc: 'calculator',
+ explorer: 'files',
+ files: 'files',
+ taskmgr: 'taskmgr',
+ mspaint: 'paint',
+ paint: 'paint',
+ control: 'settings',
+ settings: 'settings',
+ 'ms-settings:': 'settings',
+ clock: 'clock',
+ weather: 'weather',
+ camera: 'camera',
+ photos: 'photos',
+ wmplayer: 'media',
+ winver: 'about',
+};
diff --git a/src/desktop/desktop.css b/src/desktop/desktop.css
index afe69f4fb..e4e2a32fd 100644
--- a/src/desktop/desktop.css
+++ b/src/desktop/desktop.css
@@ -740,55 +740,6 @@ body {
color: var(--accent);
}
-.widgets {
- left: 8px;
- bottom: calc(var(--task-h) + 10px);
- width: min(420px, calc(100vw - 16px));
- max-height: calc(100vh - var(--task-h) - 24px);
- overflow-y: auto;
- padding: 14px;
- display: flex;
- flex-direction: column;
- gap: 12px;
- transform-origin: bottom left;
- scrollbar-width: thin;
-}
-.wg-card {
- border-radius: 10px;
- background: var(--card);
- border: 1px solid var(--hr);
- padding: 14px;
-}
-.wg-card h3 {
- margin: 0 0 4px;
- font-size: 13px;
- font-weight: 600;
-}
-.wg-card p {
- margin: 0;
- color: var(--text2);
- font-size: 12.5px;
-}
-.wg-agent {
- display: grid;
- grid-template-columns: 130px 1fr;
- gap: 12px;
- align-items: center;
-}
-.wg-agent agent-3d {
- width: 130px;
- height: 170px;
- display: block;
- border-radius: 8px;
- overflow: hidden;
- background: var(--bg30);
-}
-.wg-actions {
- display: flex;
- flex-wrap: wrap;
- gap: 6px;
- margin-top: 10px;
-}
.os-btn {
display: inline-flex;
align-items: center;
@@ -815,31 +766,7 @@ body {
.os-btn.primary:hover {
filter: brightness(1.1);
}
-.wg-quick {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 6px;
-}
-.wg-quick button {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 6px;
- padding: 10px 4px;
- border-radius: var(--siz-radius2);
- font-size: 12px;
-}
-.wg-quick button:hover {
- background: var(--hover-b);
-}
-.calendar {
- right: 8px;
- bottom: calc(var(--task-h) + 10px);
- width: 300px;
- padding: 14px;
- transform-origin: bottom right;
-}
.cal-head {
display: flex;
align-items: center;
diff --git a/src/desktop/icon-layer.js b/src/desktop/icon-layer.js
index b9575461d..033c8352b 100644
--- a/src/desktop/icon-layer.js
+++ b/src/desktop/icon-layer.js
@@ -18,7 +18,7 @@ import {
const PAD = 8;
const DRAG_PX = 5;
-export function createIconLayer({ host, resolve, isKnown, defaults, load, save, launch, menu, size }) {
+export function createIconLayer({ host, resolve, isKnown, defaults, load, save, launch, menu, size, itemMenu, onDelete, onRename }) {
let items = [];
let selected = new Set();
let anchor = null;
@@ -228,11 +228,18 @@ export function createIconLayer({ host, resolve, isKnown, defaults, load, save,
const id = el.dataset.id;
if (!selected.has(id)) select([id], false);
const many = selected.size > 1;
- menu(e.clientX, e.clientY, [
- [many ? `Open ${selected.size} apps` : 'Open', 'external', () => [...selected].forEach(openIcon)],
- '-',
- [many ? 'Remove from desktop' : 'Remove from desktop', 'close', () => remove([...selected])],
- ]);
+ const ids = [...selected];
+ // The host can supply its own menu (files on the desktop open, rename and go to the trash).
+ const own = itemMenu?.(ids, () => ids.forEach(openIcon));
+ menu(
+ e.clientX,
+ e.clientY,
+ own || [
+ [many ? `Open ${selected.size} apps` : 'Open', 'external', () => ids.forEach(openIcon)],
+ '-',
+ ['Remove from desktop', 'close', () => remove(ids)],
+ ],
+ );
});
host.addEventListener('keydown', (e) => {
const el = e.target.closest('.os-icon');
@@ -242,7 +249,11 @@ export function createIconLayer({ host, resolve, isKnown, defaults, load, save,
e.preventDefault();
[...(selected.size ? selected : new Set([id]))].forEach(openIcon);
} else if (e.key === 'Delete') {
- remove(selected.size ? [...selected] : [id]);
+ const ids = selected.size ? [...selected] : [id];
+ if (!onDelete?.(ids)) remove(ids);
+ } else if (e.key === 'F2' && onRename) {
+ e.preventDefault();
+ onRename(id);
} else if (e.key === ' ') {
e.preventDefault();
select([id], false);
@@ -329,8 +340,27 @@ export function createIconLayer({ host, resolve, isKnown, defaults, load, save,
return true;
},
remove,
+ /** Keep an icon's spot when what it points at is renamed. */
+ rename(from, to) {
+ const it = items.find((i) => i.id === from);
+ if (!it || items.some((i) => i.id === to)) return false;
+ els.get(from)?.remove();
+ els.delete(from);
+ selected.delete(from);
+ it.id = to;
+ render();
+ persist();
+ return true;
+ },
has: (id) => items.some((i) => i.id === id),
- refresh() {
+ /** Redraw; `ids` rebuilds those icons from a fresh resolve (a file changed type or name). */
+ refresh(ids) {
+ (ids || []).forEach((id) => {
+ const el = els.get(id);
+ if (!el) return;
+ el.remove();
+ els.delete(id);
+ });
render();
},
selectAll() {
diff --git a/src/desktop/layout.js b/src/desktop/layout.js
index f699aef13..9988b1e59 100644
--- a/src/desktop/layout.js
+++ b/src/desktop/layout.js
@@ -273,13 +273,14 @@ export const MODES = ['dark', 'light', 'auto'];
* labelled taskbar. `menuH` and `dockH` are the bars the work area avoids.
*/
export const STYLES = {
- fluent: { label: 'Fluent', menuH: 0, dockH: 48 },
+ // Fluent's taskbar is a floating island: 48px tall with a 7px margin all round.
+ fluent: { label: 'Fluent', menuH: 0, dockH: 62 },
aqua: { label: 'Aqua', menuH: 28, dockH: 84 },
classic: { label: 'Classic', menuH: 0, dockH: 40 },
};
export const PREFS_VERSION = 1;
export const DEFAULT_PREFS = {
- wall: 'three',
+ wall: 'bubbles',
accent: ACCENTS[0],
mode: 'dark',
iconSize: 'medium',
@@ -290,8 +291,15 @@ export const DEFAULT_PREFS = {
startIn: 'world',
sound: true,
style: 'fluent',
+ brightness: 100,
+ volume: 70,
+ nightLight: false,
+ dnd: false,
+ saver: false,
};
+const pct = (v, lo, fallback) => (Number.isFinite(v) ? Math.round(Math.min(100, Math.max(lo, v))) : fallback);
+
/** Normalise a rectangle given two corner points (any drag direction). */
export function marqueeRect(ax, ay, bx, by) {
return { x: Math.min(ax, bx), y: Math.min(ay, by), w: Math.abs(ax - bx), h: Math.abs(ay - by) };
@@ -447,6 +455,11 @@ export function sanitizePrefs(raw, wallpaperIds) {
startIn: START_MODES.includes(d.startIn) ? d.startIn : DEFAULT_PREFS.startIn,
sound: d.sound !== false,
style: Object.hasOwn(STYLES, d.style) ? d.style : DEFAULT_PREFS.style,
+ brightness: pct(d.brightness, 30, DEFAULT_PREFS.brightness),
+ volume: pct(d.volume, 0, DEFAULT_PREFS.volume),
+ nightLight: d.nightLight === true,
+ dnd: d.dnd === true,
+ saver: d.saver === true,
};
}
diff --git a/src/desktop/shell.js b/src/desktop/shell.js
index d9d9699bf..9d8ecf794 100644
--- a/src/desktop/shell.js
+++ b/src/desktop/shell.js
@@ -6,6 +6,10 @@ import { ALL_APPS, APPS, CUSTOM_WALL, WALLPAPERS, appById } from './apps.js';
import { icon } from './icons.js';
import { createIconLayer } from './icon-layer.js';
import { createWM } from './wm.js';
+import { createChrome } from './chrome/index.js';
+import { formatClock, relTime } from './chrome/logic.js';
+import { appForPath, mountOsApp } from './os/host.js';
+import * as fs from './os/fs.js';
import {
ACCENTS,
DEFAULT_PREFS,
@@ -36,6 +40,7 @@ const KEY = {
welcomed: 'tws:welcomed',
prefs: 'tws:prefs',
icons: 'tws:icons',
+ iconsV2: 'tws:icons-v2',
};
const THEME_KEY = 'twx_theme';
const WALL_IDS = [...WALLPAPERS.map((w) => w.id), CUSTOM_WALL];
@@ -131,6 +136,22 @@ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&
const tile = (app, size = 'sm', glyph = 18) =>
`<span class="app-tile ${size}" style="--hue:${app.hue}">${icon(app.icon, glyph)}</span>`;
+const DESK_PREFIX = 'fs:/Desktop/';
+/** Desktop shortcuts into the file system, like a real computer's This PC and Recycle Bin. */
+const SYSTEM_ICONS = {
+ thispc: { id: 'thispc', title: 'This PC', hue: 210, icon: 'pc', desc: 'Your folders, files and storage', fsPath: '/', fsType: 'dir' },
+ recycle: { id: 'recycle', title: 'Recycle Bin', hue: 195, icon: 'trash', desc: 'Deleted files, ready to restore or empty', fsPath: fs.TRASH, fsType: 'dir' },
+};
+const FILE_LOOK = {
+ dir: { icon: 'folder', hue: 44 },
+ text: { icon: 'note', hue: 205 },
+ image: { icon: 'image', hue: 285 },
+ audio: { icon: 'music', hue: 330 },
+ video: { icon: 'video', hue: 8 },
+ model: { icon: 'cube', hue: 262 },
+ other: { icon: 'files', hue: 220 },
+};
+
/** Build launchable "page apps" from the site's own navigation data. */
async function loadCatalog() {
try {
@@ -166,7 +187,19 @@ async function loadCatalog() {
export async function createShell(root, opts = {}) {
const catalog = await loadCatalog();
- const resolveApp = (id) => appById(id) || catalog.find((a) => a.id === id) || pageFromId(id);
+ const resolveApp = (id) => appById(id) || SYSTEM_ICONS[id] || fileApp(id) || catalog.find((a) => a.id === id) || pageFromId(id);
+ // Files and folders saved on the Desktop show up as icons with `fs:<path>` ids.
+ const deskFiles = new Map();
+ function fileApp(id) {
+ if (typeof id !== 'string' || !id.startsWith(DESK_PREFIX)) return null;
+ const path = id.slice(3);
+ const name = fs.nameOf(path);
+ const node = deskFiles.get(path);
+ const type = node?.type || (fs.extOf(name) ? 'file' : 'dir');
+ const look = type === 'dir' ? FILE_LOOK.dir : FILE_LOOK[fs.kindOf(node?.mime || name)] || FILE_LOOK.other;
+ const desc = node && type === 'file' ? `${name}\n${formatBytes(node.size)}, modified ${new Date(node.mtime).toLocaleString()}` : name;
+ return { id, title: name, hue: look.hue, icon: look.icon, desc, fsPath: path, fsType: type };
+ }
function pageFromId(id) {
const p = pagePathOf(id);
if (!p) return null;
@@ -181,10 +214,9 @@ export async function createShell(root, opts = {}) {
icons.setAttribute('aria-label', 'Desktop');
const layer = h('div', 'os-layer');
const task = h('footer', 'os-task');
- const toasts = h('div', 'os-toasts');
- toasts.setAttribute('role', 'status');
- toasts.setAttribute('aria-live', 'polite');
- root.append(wall, icons, layer, task, toasts);
+ // Desktop widgets sit above the icons and below every window.
+ const widgetsHost = h('div', 'os-widgets-host');
+ root.append(wall, icons, widgetsHost, layer, task);
// ---------- preferences (the user profile and personalization) ----------
const loadPrefs = () => {
@@ -203,14 +235,14 @@ export async function createShell(root, opts = {}) {
const prefsListeners = new Set();
const dark = matchMedia('(prefers-color-scheme: dark)');
const effectiveTheme = () => (prefs.mode === 'auto' ? (dark.matches ? 'dark' : 'light') : prefs.mode);
- let tickClock = null;
let deskIcons = null;
// The bars the work area avoids for the current style. On a phone Aqua
// falls back to the Fluent taskbar (no menu bar, no magnifying dock).
const bars = () => {
const st = STYLES[prefs.style] || STYLES.fluent;
const small = innerWidth <= 720;
- return small ? { menuH: 0, dockH: prefs.style === 'aqua' ? STYLES.fluent.dockH : st.dockH } : { menuH: st.menuH, dockH: st.dockH };
+ // Phones get a docked 48px bar (no island, no menu bar, no magnifying dock).
+ return small ? { menuH: 0, dockH: prefs.style === 'classic' ? st.dockH : 48 } : { menuH: st.menuH, dockH: st.dockH };
};
let shownStyle = null;
@@ -259,7 +291,6 @@ export async function createShell(root, opts = {}) {
/* cross-origin frame */
}
});
- tickClock?.();
prefsListeners.forEach((fn) => fn(prefs));
}
function setPrefs(patch) {
@@ -272,12 +303,32 @@ export async function createShell(root, opts = {}) {
}
dark.addEventListener?.('change', () => prefs.mode === 'auto' && applyPrefs());
- function toast(msg) {
- const t = h('div', 'os-toast');
- t.textContent = msg;
- toasts.append(t);
- setTimeout(() => t.remove(), 4200);
- }
+ // ---------- system chrome (tray status, clock, quick settings, notifications, power, lock) ----------
+ let account = null;
+ const chrome = createChrome({
+ root,
+ store,
+ prefs: () => prefs,
+ setPrefs,
+ onPrefs: (fn) => (prefsListeners.add(fn), () => prefsListeners.delete(fn)),
+ openPop: (kind, el, trigger, onClose) => openPop(kind, el, trigger, onClose),
+ closePops: () => closePops(),
+ menu: (x, y, items, above) => menu(x, y, items, above),
+ launchId: (id, o) => launchId(id, o),
+ resolveApp: (id) => resolveApp(id),
+ searchApps: (q) => (q ? rankItems(q, everything()) : everything()),
+ openPath: (path) => openPath(path),
+ get wm() {
+ return wm;
+ },
+ save: () => save(),
+ displayName: () => displayName(),
+ account: () => account,
+ tile,
+ goClassic: () => goClassic(),
+ });
+ const toast = (msg) => chrome.toast(msg);
+ const notify = (n) => chrome.notify(n);
// ---------- recent ----------
const recent = () => {
@@ -300,7 +351,7 @@ export async function createShell(root, opts = {}) {
const wm = createWM({
layer,
getMetrics: () => ({ vw: innerWidth, vh: innerHeight, ...bars(), mobile: innerWidth <= 720 }),
- renderNative: (app, body) => renderNative(app, body),
+ renderNative: (app, body, win) => renderNative(app, body, win),
notify: toast,
getTaskRect: (id) => {
const b = mid.querySelector(`.os-tb.run[data-app="${CSS.escape(id)}"]`);
@@ -322,6 +373,7 @@ export async function createShell(root, opts = {}) {
function launch(app, o = {}) {
if (!app) return;
+ if (app.fsPath) return launch(resolveApp(appForPath(app.fsPath, app.fsType)), { ...o, arg: app.fsPath });
closePops();
if (app.id === 'settings' && o.section) {
if (wm.has('settings') && settingsGo) settingsGo(o.section);
@@ -331,6 +383,13 @@ export async function createShell(root, opts = {}) {
wm.open(app, o);
}
const launchId = (id, o) => launch(resolveApp(id), o);
+ /** Every launchable app: framed pages, Settings, All Apps, the native OS apps and the site catalog. */
+ const everything = () => [...ALL_APPS.filter((a) => !a.native || a.os || a.id === 'settings' || a.id === 'apps'), ...catalog];
+ /** Open a three.ws path in the app that owns it, or in a page window. */
+ function openPath(path) {
+ const app = everything().find((a) => a.href === path) || resolveApp(pageAppId(path));
+ if (app) launch(app, app.href === path ? {} : { path });
+ }
// ---------- taskbar ----------
const pinned = [...APPS, ...ALL_APPS.filter((a) => a.native)].filter((a) => a.dock);
@@ -345,6 +404,12 @@ export async function createShell(root, opts = {}) {
btnWidgets.setAttribute('aria-label', 'Widgets and your agent');
btnWidgets.setAttribute('aria-expanded', 'false');
btnWidgets.title = 'Widgets';
+ const btnAssist = h('button', 'os-tb os-assist', icon('assistant', 21));
+ btnAssist.type = 'button';
+ btnAssist.setAttribute('aria-label', 'Assistant');
+ btnAssist.setAttribute('aria-haspopup', 'dialog');
+ btnAssist.setAttribute('aria-expanded', 'false');
+ btnAssist.title = 'Assistant (Ctrl+Alt+C)';
const btnSearch = h('button', 'os-tb hide-sm', icon('search', 20));
btnSearch.type = 'button';
btnSearch.setAttribute('aria-label', 'Search apps and pages');
@@ -369,7 +434,7 @@ export async function createShell(root, opts = {}) {
[`Quit ${w ? w.title : ''}`.trim(), 'close', () => wm.close(id)],
]);
});
- left.append(btnWidgets, menuTitle);
+ left.append(btnWidgets, btnAssist, menuTitle);
const mid = h('div', 'os-task-mid');
const right = h('div', 'os-task-right');
task.append(left, mid, right);
@@ -538,20 +603,26 @@ export async function createShell(root, opts = {}) {
btnClassic.type = 'button';
btnClassic.title = 'Classic view';
btnClassic.setAttribute('aria-label', 'Switch to the classic website');
- const chip = h('a', 'os-chip', `${icon('user', 18)}<span>Sign in</span>`);
- chip.href = '/login';
- chip.title = 'Account';
- chip.addEventListener('click', (e) => {
- if (e.metaKey || e.ctrlKey) return;
- e.preventDefault();
- launch(resolveApp(chip.dataset.signedIn ? 'console' : pageAppId('/login')));
- });
- const clock = h('button', 'os-clock');
- clock.type = 'button';
- clock.setAttribute('aria-haspopup', 'dialog');
- clock.setAttribute('aria-expanded', 'false');
- tray.append(btnTheme, btnWorld, btnClassic, chip, clock);
- right.append(tray);
+ // The sliver at the far right edge, as on Windows: click to show the desktop, click again to bring everything back.
+ const btnDesk = h('button', 'os-showdesk hide-sm');
+ btnDesk.type = 'button';
+ btnDesk.title = 'Show desktop';
+ btnDesk.setAttribute('aria-label', 'Show desktop');
+ btnDesk.addEventListener('click', () => showDesktop());
+ tray.append(btnTheme, btnWorld, btnClassic, chrome.statusBtn, chrome.clockBtn);
+ right.append(tray, btnDesk);
+ let deskShown = null;
+ function showDesktop() {
+ closePops();
+ const open = running.filter((w) => !w.minimized);
+ if (open.length) {
+ deskShown = open.map((w) => w.id);
+ open.forEach((w) => wm.minimize(w.id));
+ } else if (deskShown) {
+ deskShown.filter((id) => wm.has(id)).forEach((id) => wm.focus(id));
+ deskShown = null;
+ }
+ }
const isLight = () => document.documentElement.getAttribute('data-theme') === 'light';
function syncTheme() {
@@ -580,23 +651,13 @@ export async function createShell(root, opts = {}) {
location.assign('/classic');
}
- tickClock = function () {
- const d = new Date();
- clock.innerHTML = `<span>${d.toLocaleTimeString([], { hour: prefs.clock24 ? '2-digit' : 'numeric', minute: '2-digit', hour12: !prefs.clock24 })}</span><span>${d.toLocaleDateString([], { month: 'numeric', day: 'numeric', year: 'numeric' })}</span>`;
- clock.setAttribute('aria-label', `${d.toLocaleString()}. Open calendar`);
- };
- tickClock();
- setInterval(tickClock, 15000);
-
- // auth chip (server session is the truth)
+ // Signed-in account: the server session is the source of truth.
fetch('/api/auth/me', { credentials: 'include' })
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
const u = data && data.user;
if (!u) return;
- chip.dataset.signedIn = '1';
- chip.querySelector('span').textContent = u.display_name || u.username || 'Account';
- chip.title = 'Open your console';
+ account = u;
userName = u.display_name || u.username || 'Account';
paintUser();
})
@@ -610,9 +671,7 @@ export async function createShell(root, opts = {}) {
function paintUser() {
if (!startUserEl) return;
startUserEl.querySelector('span').textContent = displayName();
- const av = startUserEl.querySelector('.avatar');
- av.textContent = initialsOf(userName || prefs.name);
- av.style.setProperty('--hue', prefs.avatarHue);
+ chrome.paintAvatar(startUserEl.querySelector('.avatar'));
}
prefsListeners.add(paintUser);
@@ -664,17 +723,46 @@ export async function createShell(root, opts = {}) {
const el = h('div', 'os-pop start-menu');
el.setAttribute('role', 'dialog');
el.setAttribute('aria-label', 'Start');
- const search = h('label', 'sm-search', `${icon('search', 18)}<input type="search" placeholder="Search apps and pages" aria-label="Search apps and pages" autocomplete="off" spellcheck="false">`);
- const input = search.querySelector('input');
- const body = h('div', 'sm-body');
- const foot = h('div', 'sm-foot');
- const user = h('button', 'sm-user', `<i class="avatar sm"></i><span></span>`);
+ const user = h('button', 'sm-user', `<i class="avatar"></i><span></span>`);
user.type = 'button';
- user.title = 'Your profile and settings';
+ user.title = 'Your profile and account';
startUserEl = user;
paintUser();
user.addEventListener('click', () => launchId('settings', { section: 'profile' }));
- const walk = h('button', 'sm-pwr sm-world', icon('world', 20));
+ const search = h('label', 'sm-search', `${icon('search', 18)}<input type="search" placeholder="Search apps, pages and files" aria-label="Search apps, pages and files" autocomplete="off" spellcheck="false">`);
+ const input = search.querySelector('input');
+ const head = h('div', 'sm-head');
+ head.append(user, search);
+
+ // Left: every app, A to Z. Right: folders, clock, pinned, recommended.
+ const side = h('nav', 'sm-side');
+ side.setAttribute('aria-label', 'All apps');
+ const body = h('div', 'sm-body');
+ const main = h('div', 'sm-main');
+ main.append(side, body);
+
+ const foot = h('div', 'sm-foot');
+ const folders = h('div', 'sm-folders');
+ [
+ ['Documents', 'files', '/Documents'],
+ ['Pictures', 'image', '/Pictures'],
+ ['Music', 'music', '/Music'],
+ ['Downloads', 'download', '/Downloads'],
+ ].forEach(([name, ic, path]) => {
+ const b = h('button', 'sm-folder', icon(ic, 18));
+ b.type = 'button';
+ b.title = name;
+ b.setAttribute('aria-label', `Open ${name}`);
+ b.addEventListener('click', () => launchId('files', { arg: path }));
+ folders.append(b);
+ });
+ const gear = h('button', 'sm-folder', icon('gear', 18));
+ gear.type = 'button';
+ gear.title = 'Settings';
+ gear.setAttribute('aria-label', 'Settings');
+ gear.addEventListener('click', () => launchId('settings'));
+ folders.append(gear);
+ const walk = h('button', 'sm-pwr sm-world', icon('world', 18));
walk.type = 'button';
walk.title = 'Walk the campus';
walk.setAttribute('aria-label', 'Leave the desk and walk the three.ws campus as your avatar');
@@ -684,53 +772,105 @@ export async function createShell(root, opts = {}) {
goWorld();
});
startWorldEl = walk;
- const pwr = h('button', 'sm-pwr', icon('classic', 20));
+ const classic = h('button', 'sm-pwr', icon('classic', 18));
+ classic.type = 'button';
+ classic.title = 'Classic view';
+ classic.setAttribute('aria-label', 'Switch to the classic website');
+ classic.addEventListener('click', goClassic);
+ const pwr = h('button', 'sm-pwr sm-power', icon('power', 18));
pwr.type = 'button';
- pwr.title = 'Classic view';
- pwr.setAttribute('aria-label', 'Switch to the classic website');
- pwr.addEventListener('click', goClassic);
+ pwr.title = 'Power';
+ pwr.setAttribute('aria-label', 'Power: lock, sign out, restart or shut down');
+ pwr.setAttribute('aria-haspopup', 'menu');
+ pwr.addEventListener('click', (e) => {
+ e.stopPropagation();
+ const r = pwr.getBoundingClientRect();
+ chrome.powerMenu(r.right, r.top - 6, true);
+ });
const actions = h('div', 'sm-foot-actions');
- actions.append(walk, pwr);
- foot.append(user, actions);
- el.append(search, body, foot);
+ actions.append(walk, classic, pwr);
+ foot.append(folders, actions);
+ el.append(head, main, foot);
let selectable = [];
let sel = -1;
- const everything = () => [...ALL_APPS.filter((a) => !a.native || a.id === 'settings' || a.id === 'apps'), ...catalog];
- function row(app) {
- const r = h('button', 'sm-row', `${tile(app, 'sm', 17)}<div><b>${esc(app.title)}</b><small>${esc(app.desc || app.href || '')}</small></div>`);
- r.type = 'button';
- r.addEventListener('click', () => launch(app));
- selectable.push(r);
- return r;
- }
- function appBtn(app) {
- const b = h('button', 'sm-app', `${tile(app, '', 22)}<span>${esc(app.title)}</span>`);
+ const pick = (b, fn) => {
b.type = 'button';
- b.addEventListener('click', () => launch(app));
+ b.addEventListener('click', fn);
selectable.push(b);
return b;
+ };
+ const row = (app) => pick(h('button', 'sm-row', `${tile(app, 'sm', 17)}<div><b>${esc(app.title)}</b><small>${esc(app.desc || app.href || '')}</small></div>`), () => launch(app));
+ const appBtn = (app) => pick(h('button', 'sm-app', `${tile(app, '', 22)}<span>${esc(app.title)}</span>`), () => launch(app));
+ const fileRow = (n) => {
+ const look = n.type === 'dir' ? FILE_LOOK.dir : FILE_LOOK[fs.kindOf(n.mime || n.name)] || FILE_LOOK.other;
+ const where = fs.parentOf(n.path).slice(1) || 'Home';
+ return pick(h('button', 'sm-row', `${tile(look, 'sm', 17)}<div><b>${esc(n.name)}</b><small>${esc(where)} / ${esc(relTime(n.mtime))}</small></div>`), () => launch({ id: n.path, fsPath: n.path, fsType: n.type }));
+ };
+
+ const sorted = everything()
+ .slice()
+ .sort((a, b) => a.title.localeCompare(b.title, undefined, { sensitivity: 'base' }));
+ function paintSide() {
+ side.replaceChildren(h('div', 'sm-h', '<span>All apps</span>'));
+ let letter = '';
+ sorted.forEach((a) => {
+ const L = /^[a-z]/i.test(a.title) ? a.title[0].toUpperCase() : '#';
+ if (L !== letter) {
+ letter = L;
+ side.append(h('div', 'sm-letter', esc(L)));
+ }
+ const b = h('button', 'sm-side-app', `${tile(a, 'sm', 15)}<span>${esc(a.title)}</span>`);
+ b.type = 'button';
+ b.addEventListener('click', () => launch(a));
+ side.append(b);
+ });
}
+
+ const clock = h('div', 'sm-clock');
+ let clockT = 0;
+ const tickClock = () => {
+ const d = new Date();
+ const { time } = formatClock(d, { clock24: prefs.clock24 });
+ clock.innerHTML = `<b>${esc(time)}</b><span>${esc(d.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric' }))}</span>`;
+ clockT = setTimeout(tickClock, 60_000 - (Date.now() % 60_000) + 20);
+ };
+
let showAll = false;
- function paint() {
+ let paintSeq = 0;
+ async function paint() {
+ const seq = ++paintSeq;
selectable = [];
sel = -1;
body.replaceChildren();
const q = input.value.trim();
+ el.classList.toggle('searching', !!q);
if (q) {
- const hits = rankItems(q, everything()).slice(0, 24);
- if (!hits.length) {
- body.append(h('div', 'sm-empty', `Nothing matches "${esc(q)}". Try an app name like Forge or Chat.`));
- return;
- }
- body.append(h('div', 'sm-h', '<span>Best matches</span>'));
+ const hits = rankItems(q, everything()).slice(0, 16);
const list = h('div', 'sm-list one');
- hits.forEach((a) => list.append(row(a)));
- body.append(list);
+ if (hits.length) {
+ body.append(h('div', 'sm-h', '<span>Best matches</span>'));
+ hits.forEach((a) => list.append(row(a)));
+ body.append(list);
+ }
+ const needle = q.toLowerCase();
+ const files = (await fs.walk('/').catch(() => []))
+ .filter((n) => !n.path.startsWith(`${fs.TRASH}/`) && n.name.toLowerCase().includes(needle))
+ .sort((a, b) => b.mtime - a.mtime)
+ .slice(0, 8);
+ if (seq !== paintSeq) return;
+ if (files.length) {
+ body.append(h('div', 'sm-h', '<span>Files and folders</span>'));
+ const fl = h('div', 'sm-list one');
+ files.forEach((n) => fl.append(fileRow(n)));
+ body.append(fl);
+ }
+ if (!hits.length && !files.length) body.append(h('div', 'sm-empty', `Nothing matches "${esc(q)}". Try an app like Forge, a folder like Documents, or press Ctrl+Alt+R to run a command.`));
return;
}
+ body.append(clock);
const hd = h('div', 'sm-h', `<span>${showAll ? 'All apps' : 'Pinned'}</span>`);
- const toggle = h('button', '', showAll ? 'Back' : `All apps ${'›'}`);
+ const toggle = h('button', 'sm-more', showAll ? 'Back' : `All ${icon('chevron', 12)}`);
toggle.type = 'button';
toggle.addEventListener('click', () => {
showAll = !showAll;
@@ -740,24 +880,23 @@ export async function createShell(root, opts = {}) {
body.append(hd);
if (showAll) {
const list = h('div', 'sm-list');
- everything().forEach((a) => list.append(row(a)));
+ sorted.forEach((a) => list.append(row(a)));
body.append(list);
return;
}
const grid = h('div', 'sm-grid');
- [...APPS, ALL_APPS.find((a) => a.id === 'settings'), ALL_APPS.find((a) => a.id === 'apps')].forEach((a) => grid.append(appBtn(a)));
+ const pins = [...APPS, ...['files', 'notepad', 'terminal', 'settings', 'apps'].map(appById)].filter(Boolean);
+ pins.forEach((a) => grid.append(appBtn(a)));
body.append(grid);
- const rec = recent().map(resolveApp).filter(Boolean).slice(0, 6);
- body.append(h('div', 'sm-h', '<span>Recommended</span>'));
- if (rec.length) {
- const list = h('div', 'sm-list');
- rec.forEach((a) => list.append(row(a)));
- body.append(list);
- } else {
- const list = h('div', 'sm-list');
- ['create', 'forge', 'discover', 'chat'].forEach((id) => list.append(row(appById(id))));
- body.append(list);
- }
+ const recHead = h('div', 'sm-h', '<span>Recommended</span>');
+ const recList = h('div', 'sm-list');
+ body.append(recHead, recList);
+ const apps = recent().map(resolveApp).filter((a) => a && !a.fsPath).slice(0, 4);
+ const files = await fs.recentFiles(4).catch(() => []);
+ if (seq !== paintSeq) return;
+ const items = [...files.map((n) => fileRow(n)), ...apps.map((a) => row(a))].slice(0, 6);
+ if (items.length) items.forEach((b) => recList.append(b));
+ else ['create', 'forge', 'notepad', 'discover'].map(appById).filter(Boolean).forEach((a) => recList.append(row(a)));
}
input.addEventListener('input', () => {
showAll = false;
@@ -772,164 +911,295 @@ export async function createShell(root, opts = {}) {
selectable[sel].scrollIntoView({ block: 'nearest' });
} else if (e.key === 'Enter') {
e.preventDefault();
- (selectable[sel >= 0 ? sel : 0])?.click();
+ selectable[sel >= 0 ? sel : 0]?.click();
}
});
- if (!openPop('start', el, btnStart, () => (startUserEl = null))) return;
+ const opened = openPop('start', el, btnStart, () => {
+ startUserEl = null;
+ clearTimeout(clockT);
+ });
+ if (!opened) return;
input.value = query;
+ tickClock();
+ paintSide();
paint();
input.focus({ preventScroll: true });
}
btnStart.addEventListener('click', () => toggleStart());
btnSearch.addEventListener('click', () => toggleStart());
- // ---------- Widgets ----------
- let agentLoaded = false;
+ // ---------- Widgets board, desktop widgets and the assistant ----------
+ // Loaded on demand so the desktop paints before their data does.
+ const widgetsMod = () => import('./widgets/index.js');
+ const assistantMod = () => import('./assistant/index.js');
+ const flyoutCtx = (anchor) => ({ root, anchor, launchId, toast, notify, prefs: () => prefs });
+ const flyoutFailed = (what) => (err) => notify({ title: `${what} could not open`, body: err?.message || 'Check your connection and try again.' });
btnWidgets.addEventListener('click', () => {
- const el = h('div', 'os-pop widgets');
- el.setAttribute('role', 'dialog');
- el.setAttribute('aria-label', 'Widgets');
- const agent = h('div', 'wg-card wg-agent');
- const stage = h('div', '', '');
- agent.append(stage);
- const info = h('div', '', '<h3>Your resident agent</h3><p>A living 3D agent, running on the same web component you can embed on any site.</p>');
- const acts = h('div', 'wg-actions');
- const talk = h('button', 'os-btn primary', `${icon('chat', 16)}Talk`);
- talk.type = 'button';
- talk.addEventListener('click', () => launchId('chat'));
- const make = h('button', 'os-btn', `${icon('sparkle', 16)}Make your own`);
- make.type = 'button';
- make.addEventListener('click', () => launchId('create'));
- acts.append(talk, make);
- info.append(acts);
- agent.append(info);
-
- const quick = h('div', 'wg-card');
- quick.append(h('h3', '', 'Jump in'));
- const q = h('div', 'wg-quick');
- ['forge', 'discover', 'marketplace', 'pulse', 'trenches', 'tour'].forEach((id) => {
- const a = appById(id);
- const b = h('button', '', `${tile(a, 'sm', 17)}<span>${esc(a.title)}</span>`);
- b.type = 'button';
- b.addEventListener('click', () => launch(a));
- q.append(b);
- });
- quick.append(q);
-
- const about = h('div', 'wg-card', '<h3>three.ws</h3><p>The 3D agent layer of the internet. Every window here is a real three.ws page. Prefer the original site? Use the classic view in the taskbar.</p>');
- el.append(agent, quick, about);
- if (!openPop('widgets', el, btnWidgets)) return;
- mountAgent(stage);
+ closePops();
+ assistantOpen && assistantMod().then((m) => m.closeAssistant());
+ widgetsMod()
+ .then((m) => m.toggleWidgets(flyoutCtx(btnWidgets)))
+ .catch(flyoutFailed('Widgets'));
});
- function mountAgent(stage) {
- const mk = () => {
- const a = document.createElement('agent-3d');
- a.setAttribute('src', 'https://three.ws/avatars/michelle.glb');
- a.setAttribute('aria-label', 'Resident 3D agent');
- stage.replaceChildren(a);
- };
- if (agentLoaded || customElements.get('agent-3d')) return mk();
- agentLoaded = true;
- const s = document.createElement('script');
- s.type = 'module';
- s.src = 'https://three.ws/agent-3d/latest/agent-3d.js';
- s.onload = mk;
- s.onerror = () => {
- stage.innerHTML = '<p>The 3D agent could not load. Check your connection and reopen Widgets.</p>';
- };
- document.head.append(s);
- }
-
- // ---------- Calendar ----------
- clock.addEventListener('click', () => {
- let view = new Date();
- view.setDate(1);
- const el = h('div', 'os-pop calendar');
- el.setAttribute('role', 'dialog');
- el.setAttribute('aria-label', 'Calendar');
- function paint() {
- const today = new Date();
- const first = new Date(view.getFullYear(), view.getMonth(), 1);
- const start = new Date(first);
- start.setDate(1 - first.getDay());
- const cells = [];
- for (let i = 0; i < 42; i++) {
- const d = new Date(start);
- d.setDate(start.getDate() + i);
- const cls = [d.getMonth() !== view.getMonth() ? 'mute' : '', d.toDateString() === today.toDateString() ? 'today' : ''].join(' ');
- cells.push(`<b class="${cls}">${d.getDate()}</b>`);
- }
- const dow = ['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((d) => `<i>${d}</i>`).join('');
- el.innerHTML =
- `<div class="cal-head"><span>${view.toLocaleDateString([], { month: 'long', year: 'numeric' })}</span><span>` +
- `<button type="button" data-d="-1" aria-label="Previous month">${icon('chevron', 14).replace('<svg', '<svg style="transform:rotate(180deg)"')}</button>` +
- `<button type="button" data-d="1" aria-label="Next month">${icon('chevron', 14)}</button></span></div>` +
- `<div class="cal-grid">${dow}${cells.join('')}</div>`;
- el.querySelectorAll('[data-d]').forEach((b) =>
- b.addEventListener('click', () => {
- view = new Date(view.getFullYear(), view.getMonth() + Number(b.dataset.d), 1);
- paint();
- }),
- );
- }
- paint();
- openPop('calendar', el, clock);
+ let assistantOpen = false;
+ btnAssist.addEventListener('click', () => {
+ closePops();
+ widgetsMod().then((m) => m.closeWidgets());
+ assistantMod()
+ .then((m) => (assistantOpen = m.toggleAssistant(flyoutCtx(btnAssist))))
+ .catch(flyoutFailed('The assistant'));
});
+ widgetsMod()
+ .then((m) =>
+ m.mountDesktopWidgets({
+ root,
+ desktop: widgetsHost,
+ launchId,
+ toast,
+ insets: () => {
+ const { menuH, dockH } = bars();
+ return { top: menuH + 12, right: 12, bottom: dockH + 12, left: 120 };
+ },
+ }),
+ )
+ .catch(() => {
+ /* the board is optional; the desktop works without it */
+ });
+ const editWidgets = () => widgetsMod().then((m) => m.editDesktopWidgets(true));
+ const addWidget = () => widgetsMod().then((m) => m.addDesktopWidget());
// ---------- context menu ----------
- function menu(x, y, items) {
+ /**
+ * Context menu. An item is '-' (separator) or [label, glyph, fn, sub?, hint?];
+ * `sub` (an item list) makes it open a submenu instead. `above` anchors the
+ * menu's bottom edge at y (menus opened from the taskbar).
+ */
+ function menu(x, y, items, above = false) {
closePops();
- const el = h('div', 'os-pop ctx');
- el.setAttribute('role', 'menu');
- items.forEach((it) => {
- if (it === '-') return el.append(h('hr'));
- const [label, ic, fn] = it;
- const b = h('button', '', `${icon(ic, 16)}<span>${esc(label)}</span>`);
- b.type = 'button';
- b.setAttribute('role', 'menuitem');
- b.addEventListener('click', () => {
- closePops();
- fn();
- });
- el.append(b);
- });
+ const el = buildMenu(items, () => closePops());
root.append(el);
const r = el.getBoundingClientRect();
el.style.left = `${Math.max(4, Math.min(x, innerWidth - r.width - 4))}px`;
const { menuH, dockH } = bars();
- el.style.top = `${Math.max(menuH + 4, Math.min(y, innerHeight - r.height - dockH - 4))}px`;
+ const top = above ? y - r.height : y;
+ el.style.top = `${Math.max(menuH + 4, Math.min(top, innerHeight - r.height - (above ? 4 : dockH + 4)))}px`;
el.style.bottom = 'auto';
pop = { kind: 'ctx', el, trigger: null };
el.querySelector('button')?.focus();
}
- root.addEventListener('contextmenu', (e) => {
- if (e.target.closest('.win, .os-task, .os-pop')) return;
- e.preventDefault();
- menu(e.clientX, e.clientY, [
- ['Select all', 'grid', () => deskIcons.selectAll()],
- ['Small icons', 'grid', () => setPrefs({ iconSize: 'small' })],
- ['Medium icons', 'grid', () => setPrefs({ iconSize: 'medium' })],
- ['Large icons', 'grid', () => setPrefs({ iconSize: 'large' })],
- ['Sort by name', 'folder', () => deskIcons.sortByName()],
- ['Auto arrange', 'folder', () => deskIcons.arrange()],
- ['Refresh', 'reload', () => deskIcons.refresh()],
+ function buildMenu(items, done, sub = false) {
+ const el = h('div', `os-pop ctx${sub ? ' ctx-sub' : ''}`);
+ el.setAttribute('role', 'menu');
+ let child = null;
+ const closeChild = () => {
+ child?.remove();
+ child = null;
+ el.querySelectorAll('[aria-expanded="true"]').forEach((b) => b.setAttribute('aria-expanded', 'false'));
+ };
+ items.forEach((it) => {
+ if (it === '-') return el.append(h('hr'));
+ const [label, ic, fn, kids, hint] = it;
+ const b = h('button', '', `${ic ? icon(ic, 16) : '<i class="ico" aria-hidden="true"></i>'}<span>${esc(label)}</span>${kids ? icon('chevron', 12) : hint ? `<kbd>${esc(hint)}</kbd>` : ''}`);
+ b.type = 'button';
+ b.setAttribute('role', 'menuitem');
+ if (kids) {
+ b.setAttribute('aria-haspopup', 'menu');
+ b.setAttribute('aria-expanded', 'false');
+ const open = () => {
+ if (b.getAttribute('aria-expanded') === 'true') return;
+ closeChild();
+ b.setAttribute('aria-expanded', 'true');
+ child = buildMenu(kids, done, true);
+ el.append(child);
+ const br = b.getBoundingClientRect();
+ const er = el.getBoundingClientRect();
+ const cr = child.getBoundingClientRect();
+ const right = er.right + cr.width + 4 < innerWidth;
+ child.style.left = right ? `${er.width - 4}px` : `${-cr.width + 4}px`;
+ child.style.top = `${Math.min(br.top - er.top - 5, innerHeight - er.top - cr.height - 8)}px`;
+ return child;
+ };
+ b.addEventListener('pointerenter', open);
+ b.addEventListener('click', (e) => {
+ e.stopPropagation();
+ open()?.querySelector('button')?.focus();
+ });
+ b.addEventListener('keydown', (e) => {
+ if (e.key === 'ArrowRight') {
+ e.preventDefault();
+ open()?.querySelector('button')?.focus();
+ }
+ });
+ } else {
+ b.addEventListener('pointerenter', closeChild);
+ b.addEventListener('click', (e) => {
+ e.stopPropagation();
+ done();
+ fn();
+ });
+ }
+ el.append(b);
+ });
+ el.addEventListener('keydown', (e) => {
+ const own = [...el.children].filter((c) => c.tagName === 'BUTTON');
+ const i = own.indexOf(document.activeElement);
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
+ if (i < 0) return;
+ e.preventDefault();
+ e.stopPropagation();
+ own[(i + (e.key === 'ArrowDown' ? 1 : -1) + own.length) % own.length].focus();
+ } else if (e.key === 'ArrowLeft' && sub) {
+ e.preventDefault();
+ e.stopPropagation();
+ const parent = el.parentElement;
+ parent?.querySelector('[aria-expanded="true"]')?.focus();
+ el.remove();
+ parent?.querySelectorAll('[aria-expanded="true"]').forEach((b) => b.setAttribute('aria-expanded', 'false'));
+ }
+ });
+ return el;
+ }
+ // ---------- desktop: context menu, files on the desktop ----------
+ async function newOnDesktop(kind) {
+ try {
+ const name = await fs.uniqueName('/Desktop', kind === 'dir' ? 'New folder' : 'New text document.txt');
+ const path = `/Desktop/${name}`;
+ if (kind === 'dir') await fs.mkdir(path);
+ else await fs.write(path, '', { mime: 'text/plain' });
+ await syncDesk();
+ renameFile(`fs:${path}`);
+ } catch (err) {
+ notify({ title: 'Could not create it', body: err?.message || String(err), app: 'files' });
+ }
+ }
+ function renameFile(id) {
+ const app = resolveApp(id);
+ if (!app?.fsPath || !id.startsWith(DESK_PREFIX)) return;
+ const body = h('div', 'run-body', '<label class="run-field"><span>Name:</span><input type="text" autocomplete="off" spellcheck="false" aria-label="New name"></label><p class="run-err" role="alert" hidden></p>');
+ const input = body.querySelector('input');
+ const err = body.querySelector('.run-err');
+ input.value = app.title;
+ const go = () => {
+ const next = input.value.trim();
+ if (!next || next === app.title) return true;
+ fs.rename(app.fsPath, next)
+ .then(() => {
+ deskIcons.rename(id, `fs:/Desktop/${next}`);
+ dlg.close();
+ })
+ .catch((e) => {
+ err.textContent = e?.message || String(e);
+ err.hidden = false;
+ });
+ return false;
+ };
+ const dlg = chrome.dialog({ title: 'Rename', glyph: 'edit', body, buttons: [['Rename', go, true], ['Cancel']] });
+ const dot = app.fsType === 'file' ? app.title.lastIndexOf('.') : -1;
+ input.setSelectionRange(0, dot > 0 ? dot : app.title.length);
+ input.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ if (go() !== false) dlg.close();
+ }
+ });
+ }
+ /** Send desktop files to the Recycle Bin. Returns true when every id was a file (handled). */
+ function trashFiles(ids) {
+ const files = ids.filter((id) => id.startsWith(DESK_PREFIX));
+ if (!files.length) return false;
+ Promise.all(files.map((id) => fs.remove(id.slice(3))))
+ .then(() => {
+ deskIcons.remove(files);
+ toast(files.length > 1 ? `${files.length} items moved to the Recycle Bin` : `${resolveApp(files[0])?.title || 'Item'} moved to the Recycle Bin`);
+ })
+ .catch((e) => notify({ title: 'Could not delete', body: e?.message || String(e), app: 'files' }));
+ const rest = ids.filter((id) => !id.startsWith(DESK_PREFIX));
+ if (rest.length) deskIcons.remove(rest);
+ return true;
+ }
+ async function syncDesk() {
+ let nodes;
+ try {
+ nodes = await fs.list('/Desktop');
+ } catch {
+ return;
+ }
+ const changed = [];
+ const live = new Set();
+ for (const n of nodes) {
+ const id = `fs:${n.path}`;
+ live.add(id);
+ const was = deskFiles.get(n.path);
+ if (!was ? deskIcons.has(id) : was.type !== n.type || was.mime !== n.mime) changed.push(id);
+ deskFiles.set(n.path, n);
+ }
+ for (const p of [...deskFiles.keys()]) if (!live.has(`fs:${p}`)) deskFiles.delete(p);
+ const gone = deskIcons.ids().filter((id) => id.startsWith(DESK_PREFIX) && !live.has(id));
+ if (gone.length) deskIcons.remove(gone);
+ live.forEach((id) => deskIcons.has(id) || deskIcons.add(id));
+ if (changed.length) deskIcons.refresh(changed);
+ }
+ fs.subscribe((paths) => paths.some((p) => p === '/Desktop' || p === '/') && syncDesk());
+
+ function desktopMenu(x, y) {
+ const size = prefs.iconSize;
+ const mark = (on) => (on ? 'check' : '');
+ menu(x, y, [
+ [
+ 'View',
+ 'grid',
+ null,
+ [
+ ['Large icons', mark(size === 'large'), () => setPrefs({ iconSize: 'large' })],
+ ['Medium icons', mark(size === 'medium'), () => setPrefs({ iconSize: 'medium' })],
+ ['Small icons', mark(size === 'small'), () => setPrefs({ iconSize: 'small' })],
+ '-',
+ ['Auto arrange icons', 'grid', () => deskIcons.arrange()],
+ ['Select all', 'check', () => deskIcons.selectAll(), null, 'Ctrl+A'],
+ ],
+ ],
+ ['Sort by', 'list', null, [['Name', 'list', () => deskIcons.sortByName()]]],
+ ['Refresh', 'reload', () => (syncDesk(), deskIcons.refresh())],
+ '-',
+ [
+ 'New',
+ 'plus',
+ null,
+ [
+ ['Folder', 'folder', () => newOnDesktop('dir')],
+ ['Text document', 'note', () => newOnDesktop('file')],
+ ],
+ ],
+ ['Edit widgets', 'widgets', editWidgets],
+ ['Add a widget', 'plus', addWidget],
'-',
- ['All Apps', 'search', () => launchId('apps')],
- ['Personalize', 'gear', () => launchId('settings', { section: 'personalize' })],
- ['Open Start', 'logo', () => toggleStart()],
+ ['Open in Terminal', 'terminal', () => launchId('terminal', { arg: '/Desktop' })],
+ ['Open Desktop folder', 'files', () => launchId('files', { arg: '/Desktop' })],
+ '-',
+ ['Run...', 'search', () => chrome.runDialog(), null, 'Ctrl+Alt+R'],
+ ['Display settings', 'desktop', () => launchId('settings', { section: 'personalize' })],
+ ['Personalize', 'paint', () => launchId('settings', { section: 'personalize' })],
+ ['About three.ws OS', 'logo', () => chrome.aboutDialog()],
'-',
['Walk the campus', 'world', goWorld],
['Switch to classic view', 'classic', goClassic],
['Close all windows', 'close', () => wm.closeAll()],
]);
+ }
+ root.addEventListener('contextmenu', (e) => {
+ if (e.target.closest('.win, .os-task, .os-pop, .os-dialog-wrap, .os-lockscreen, .os-power')) return;
+ e.preventDefault();
+ desktopMenu(e.clientX, e.clientY);
});
// ---------- desktop icons ----------
+ const DEFAULT_ICONS = () => ['thispc', 'recycle', ...[...APPS, ...ALL_APPS.filter((a) => a.native)].filter((a) => a.desktop).map((a) => a.id)];
deskIcons = createIconLayer({
host: icons,
resolve: resolveApp,
- isKnown: (id) => !!resolveApp(id),
- defaults: () => [...APPS, ...ALL_APPS.filter((a) => a.native)].filter((a) => a.desktop).map((a) => a.id),
+ // Desktop files are trusted until the folder is read, then syncDesk drops any that are gone.
+ isKnown: (id) => (typeof id === 'string' && id.startsWith(DESK_PREFIX)) || !!resolveApp(id),
+ defaults: DEFAULT_ICONS,
load: () => {
const raw = store.get(KEY.icons);
if (raw == null) return null;
@@ -943,19 +1213,101 @@ export async function createShell(root, opts = {}) {
launch,
menu,
size: prefs.iconSize,
+ itemMenu: (ids, open) => {
+ const files = ids.filter((id) => id.startsWith(DESK_PREFIX));
+ const sys = ids.length === 1 && SYSTEM_ICONS[ids[0]];
+ if (sys?.id === 'recycle')
+ return [
+ ['Open', 'external', open],
+ ['Empty Recycle Bin', 'trash', () => fs.emptyTrash().then(() => toast('Recycle Bin emptied'))],
+ '-',
+ ['Remove from desktop', 'close', () => deskIcons.remove(ids)],
+ ];
+ if (!files.length) return null;
+ const one = ids.length === 1 ? resolveApp(ids[0]) : null;
+ return [
+ ['Open', 'external', open, null, 'Enter'],
+ one?.fsType === 'file' && ['Open with Files', 'files', () => launchId('files', { arg: fs.parentOf(one.fsPath) })],
+ one?.fsType === 'file' && fs.kindOf(one.title) === 'image' && ['Set as desktop background', 'image', () => setFileWallpaper(one.fsPath)],
+ '-',
+ one && ['Rename', 'edit', () => renameFile(one.id), null, 'F2'],
+ ['Delete', 'trash', () => trashFiles(ids), null, 'Del'],
+ ].filter(Boolean);
+ },
+ onDelete: trashFiles,
+ onRename: renameFile,
});
icons.setAttribute('role', 'listbox');
icons.setAttribute('aria-label', 'Desktop');
icons.setAttribute('aria-multiselectable', 'true');
deskIcons.init((app) => tile(app, '', 24));
+ // People who set up their desktop before This PC and the Recycle Bin existed get them once.
+ if (!store.get(KEY.iconsV2)) {
+ ['thispc', 'recycle'].forEach((id) => deskIcons.add(id));
+ store.set(KEY.iconsV2, '1');
+ }
+ syncDesk();
icons.addEventListener('pointerdown', (e) => {
if (e.target === icons) closePops();
});
+ // Drop files from the real computer onto the desktop to keep them here.
+ icons.addEventListener('dragover', (e) => {
+ if (![...(e.dataTransfer?.types || [])].includes('Files')) return;
+ e.preventDefault();
+ e.dataTransfer.dropEffect = 'copy';
+ icons.classList.add('drop');
+ });
+ icons.addEventListener('dragleave', (e) => e.target === icons && icons.classList.remove('drop'));
+ icons.addEventListener('drop', async (e) => {
+ const list = [...(e.dataTransfer?.files || [])];
+ icons.classList.remove('drop');
+ if (!list.length) return;
+ e.preventDefault();
+ let ok = 0;
+ for (const f of list) {
+ try {
+ await fs.importFile(f, '/Desktop');
+ ok++;
+ } catch (err) {
+ notify({ title: `Could not copy ${f.name}`, body: err?.message || String(err), app: 'files' });
+ }
+ }
+ if (ok) toast(ok > 1 ? `${ok} files copied to the desktop` : `${list[0].name} copied to the desktop`);
+ });
+ async function setFileWallpaper(path) {
+ const f = await fs.read(path);
+ if (!f) return;
+ await idb.set(CUSTOM_WALL, f.blob);
+ setPrefs({ wall: CUSTOM_WALL });
+ applyWall();
+ }
// ---------- keyboard ----------
+ // System shortcuts. A browser keeps the Windows key and Ctrl+Alt+Del for itself,
+ // so the desktop uses Ctrl+Alt plus a letter, like a remote desktop session does.
+ const SYS_KEYS = {
+ r: () => chrome.runDialog(),
+ l: () => chrome.lock(),
+ d: () => showDesktop(),
+ a: () => chrome.toggleQuick(),
+ n: () => chrome.toggleNotes(),
+ t: () => launchId('terminal'),
+ e: () => launchId('files'),
+ i: () => launchId('settings'),
+ m: () => launchId('taskmgr'),
+ w: () => btnWidgets.click(),
+ c: () => btnAssist.click(),
+ };
addEventListener('keydown', (e) => {
const mod = e.metaKey || e.ctrlKey;
- if (mod && e.key.toLowerCase() === 'k') {
+ const sys = e.ctrlKey && e.altKey && !e.shiftKey && !e.metaKey && SYS_KEYS[e.key.toLowerCase()];
+ if (sys) {
+ e.preventDefault();
+ sys();
+ } else if (e.ctrlKey && e.key === 'Escape') {
+ e.preventDefault();
+ toggleStart();
+ } else if (mod && e.key.toLowerCase() === 'k') {
e.preventDefault();
closePops();
toggleStart();
@@ -985,6 +1337,7 @@ export async function createShell(root, opts = {}) {
// ---------- native apps ----------
const WALL_PREVIEW = {
+ bubbles: 'radial-gradient(circle 22px at 30% 35%,#c7b8ff99,transparent),radial-gradient(circle 30px at 70% 70%,#a6e9ff88,transparent),linear-gradient(140deg,#0c1238,#241052 50%,#071a3c)',
three: 'radial-gradient(70% 60% at 50% 110%,#8b5cf6aa,transparent 70%),#050505',
aurora: 'linear-gradient(215deg,#7a3fa8,#1f6fbf)',
midnight: 'linear-gradient(180deg,#1d2b5a,#05060d)',
@@ -1100,7 +1453,7 @@ export async function createShell(root, opts = {}) {
let current = 'profile';
const panes = { profile: paintProfile, personalize: paintPersonalize, desktop: paintDesktop, session: paintSession };
sections.forEach(([id, ic, label]) => {
- const b = h('button', '', `${icon(ic, 16)}<span>${label}</span>`);
+ const b = h('button', '', `${ic ? icon(ic, 16) : '<i class="ico" aria-hidden="true"></i>'}<span>${label}</span>`);
b.type = 'button';
b.dataset.section = id;
b.addEventListener('click', () => go(id));
@@ -1157,9 +1510,9 @@ export async function createShell(root, opts = {}) {
pane.append(h('h3', '', 'Account'));
pane.append(
setRow(
- chip.dataset.signedIn ? `Signed in as ${userName}` : 'Not signed in',
- chip.dataset.signedIn ? 'Your agents, wallets and usage live in the Console.' : 'Sign in to sync your agents and wallets across devices.',
- btn(chip.dataset.signedIn ? 'Open Console' : 'Sign in', () => launch(resolveApp(chip.dataset.signedIn ? 'console' : pageAppId('/login')))),
+ account ? `Signed in as ${userName}` : 'Not signed in',
+ account ? 'Your agents, wallets and usage live in the Console.' : 'Sign in to sync your agents and wallets across devices.',
+ btn(account ? 'Open Console' : 'Sign in', () => launch(resolveApp(account ? 'console' : pageAppId('/login')))),
),
);
}
@@ -1363,7 +1716,21 @@ export async function createShell(root, opts = {}) {
paint();
}
- function renderNative(app, body) {
+ function renderNative(app, body, win) {
+ if (app.os) {
+ mountOsApp(app, body, win, {
+ tile,
+ toast,
+ notify,
+ launchId,
+ wm,
+ store,
+ prefs: () => prefs,
+ setPrefs,
+ onPrefs: (fn) => (prefsListeners.add(fn), () => prefsListeners.delete(fn)),
+ });
+ return;
+ }
const wrap = h('div', 'native');
body.append(wrap);
if (app.id === 'settings') return renderSettings(wrap);
@@ -1420,6 +1787,11 @@ export async function createShell(root, opts = {}) {
launchId('welcome');
},
toast,
+ /** Post to the notification centre: { title, body, app }. */
+ notify,
+ lock: () => chrome.lock(),
+ run: () => chrome.runDialog(),
+ about: () => chrome.aboutDialog(),
store,
KEY,
get prefs() {
diff --git a/src/desktop/styles.css b/src/desktop/styles.css
index e55575053..ad9c3ad3b 100644
--- a/src/desktop/styles.css
+++ b/src/desktop/styles.css
@@ -951,7 +951,7 @@
border-bottom: 1px solid #fff;
margin: 3px 2px;
}
-.os[data-style='classic'] :is(.wg-card, .pk-body, .snap-cand) {
+.os[data-style='classic'] :is(.pk-body, .snap-cand) {
border-radius: 0;
border: 0;
background: #fff;
diff --git a/tests/desktop-chrome.test.js b/tests/desktop-chrome.test.js
new file mode 100644
index 000000000..91803fb27
--- /dev/null
+++ b/tests/desktop-chrome.test.js
@@ -0,0 +1,89 @@
+import { describe, it, expect } from 'vitest';
+import { formatClock, batteryInfo, networkInfo, addNotification, sanitizeNotifications, relTime, parseRun, RUN_ALIASES } from '../src/desktop/chrome/logic.js';
+
+describe('formatClock', () => {
+ const d = new Date(2026, 9, 11, 14, 5, 9);
+ it('adds seconds only when asked', () => {
+ expect(formatClock(d, { clock24: true }).time).not.toMatch(/09$/);
+ expect(formatClock(d, { clock24: true, seconds: true }).time).toMatch(/09/);
+ });
+ it('uses a 24 hour clock when set', () => {
+ expect(formatClock(d, { clock24: true }).time).toMatch(/^14/);
+ expect(formatClock(d, { clock24: false }).time).toMatch(/^2/);
+ });
+});
+
+describe('batteryInfo', () => {
+ it('is null without a battery', () => {
+ expect(batteryInfo(null)).toBeNull();
+ expect(batteryInfo({})).toBeNull();
+ });
+ it('describes discharge with time left and tiers', () => {
+ const b = batteryInfo({ level: 0.2, charging: false, dischargingTime: 5400, chargingTime: Infinity });
+ expect(b).toMatchObject({ pct: 20, charging: false, tier: 'low', label: '1 h 30 min remaining' });
+ expect(batteryInfo({ level: 0.05, charging: false, dischargingTime: Infinity }).tier).toBe('critical');
+ expect(batteryInfo({ level: 0.8, charging: false, dischargingTime: Infinity }).label).toBe('On battery');
+ });
+ it('describes charging and full', () => {
+ expect(batteryInfo({ level: 0.5, charging: true, chargingTime: 1200 }).label).toBe('Charging, full in 20 min');
+ expect(batteryInfo({ level: 1, charging: true, chargingTime: 0 }).label).toBe('Fully charged');
+ });
+});
+
+describe('networkInfo', () => {
+ it('reports offline', () => {
+ expect(networkInfo({ online: false })).toMatchObject({ online: false, label: 'Offline' });
+ });
+ it('names the link and its quality', () => {
+ const n = networkInfo({ online: true, type: 'wifi', effectiveType: '4g', downlink: 9.5, rtt: 50 });
+ expect(n.label).toBe('Wi-Fi');
+ expect(n.detail).toBe('4G / 9.5 Mbps / 50 ms');
+ expect(networkInfo({ online: true }).detail).toBe('Internet access');
+ });
+});
+
+describe('notifications', () => {
+ it('prepends newest first and caps', () => {
+ let list = [];
+ for (let i = 0; i < 60; i++) list = addNotification(list, { title: `n${i}` }, 1000 + i);
+ expect(list).toHaveLength(50);
+ expect(list[0].title).toBe('n59');
+ });
+ it('ignores empty notes and promotes a lone body to the title', () => {
+ expect(addNotification([], { title: ' ', body: '' })).toEqual([]);
+ expect(addNotification([], { body: 'Saved' })[0]).toMatchObject({ title: 'Saved', body: '' });
+ });
+ it('sanitizes stored lists', () => {
+ const good = addNotification([], { title: 'ok', body: 'b', app: 'files' }, 5);
+ expect(sanitizeNotifications(JSON.stringify([...good, { id: 3 }, null, 'x']))).toEqual(good);
+ expect(sanitizeNotifications('{bad')).toEqual([]);
+ expect(sanitizeNotifications({})).toEqual([]);
+ });
+});
+
+describe('relTime', () => {
+ const now = 1_000_000_000;
+ it('buckets', () => {
+ expect(relTime(now - 10_000, now)).toBe('Just now');
+ expect(relTime(now - 5 * 60_000, now)).toBe('5 min ago');
+ expect(relTime(now - 3 * 3_600_000, now)).toBe('3 h ago');
+ });
+});
+
+describe('parseRun', () => {
+ it('classifies input', () => {
+ expect(parseRun(' ')).toEqual({ kind: 'empty' });
+ expect(parseRun('https://three.ws/forge')).toEqual({ kind: 'url', value: 'https://three.ws/forge' });
+ expect(parseRun('example.com')).toEqual({ kind: 'url', value: 'https://example.com' });
+ expect(parseRun('/forge')).toEqual({ kind: 'path', value: '/forge' });
+ expect(parseRun('/Documents/a.txt')).toEqual({ kind: 'file', value: '/Documents/a.txt' });
+ expect(parseRun('~')).toEqual({ kind: 'file', value: '/' });
+ expect(parseRun('~/Pictures')).toEqual({ kind: 'file', value: '/Pictures' });
+ expect(parseRun('Notepad')).toEqual({ kind: 'query', value: 'notepad' });
+ });
+ it('maps the classic aliases to apps', () => {
+ expect(RUN_ALIASES.cmd).toBe('terminal');
+ expect(RUN_ALIASES.calc).toBe('calculator');
+ expect(RUN_ALIASES.winver).toBe('about');
+ });
+});
diff --git a/tests/desktop-layout.test.js b/tests/desktop-layout.test.js
index 40d1b8f8a..6a7efdb39 100644
--- a/tests/desktop-layout.test.js
+++ b/tests/desktop-layout.test.js
@@ -390,6 +390,16 @@ describe('preferences and session export', () => {
expect(sanitizePrefs({ style: 'toString' }, walls).style).toBe('fluent');
expect(sanitizePrefs({ style: 'vista' }, walls).style).toBe('fluent');
});
+ it('clamps the quick settings and keeps the switches boolean', () => {
+ const p = sanitizePrefs({ brightness: 5, volume: 140, nightLight: 'yes', dnd: true, saver: 1 }, walls);
+ expect(p.brightness).toBe(30);
+ expect(p.volume).toBe(100);
+ expect(p.nightLight).toBe(false);
+ expect(p.dnd).toBe(true);
+ expect(p.saver).toBe(false);
+ expect(sanitizePrefs({ brightness: 'dim', volume: Number.NaN }, walls)).toMatchObject({ brightness: 100, volume: 70 });
+ expect(sanitizePrefs({ volume: 33.6 }, walls).volume).toBe(34);
+ });
it('survives bad JSON', () => {
expect(sanitizePrefs('{oops', walls)).toEqual(DEFAULT_PREFS);
expect(sanitizePrefs(null, walls)).toEqual(DEFAULT_PREFS);