Skip to content

An open-source, self-hosted system for apps built with web technologies.

Adopt nested appearance colors

zohayrslileh1c1b7175102a
diff --git a/scripts/contracts/appearance.ts b/scripts/contracts/appearance.ts
index 9142f98..d7a13c8 100644
--- a/scripts/contracts/appearance.ts
+++ b/scripts/contracts/appearance.ts
@@ -10,7 +10,10 @@ import { join } from "node:path"
assert.deepEqual(appearanceSchema.parse(defaultAppearance), defaultAppearance)
assert.throws(() => appearanceSchema.parse({}))
-assert.throws(() => appearanceSchema.parse({ ...defaultAppearance, accent: defaultAppearance.primary }))
+assert.throws(() => appearanceSchema.parse({
+ ...defaultAppearance,
+ colors: { ...defaultAppearance.colors, accent: defaultAppearance.colors.primary }
+}))
assert.throws(() => appearanceSchema.parse({ ...defaultAppearance, spacing: { light: 12, dark: 12 } }))
assert.throws(() => appearanceSchema.parse({
...defaultAppearance,
@@ -28,18 +31,20 @@ assert.deepEqual(manager.value, defaultAppearance)
assert(Object.isFrozen(manager.value))
for (const role of ["background", "foreground", "primary", "secondary", "success", "warning", "danger", "info"] as const) {
- assert.deepEqual(await store.get(`appearance:${role}`), defaultAppearance[role])
+
+ assert.deepEqual((await store.get("appearance:colors"))[role], defaultAppearance.colors[role])
const color = { light: "oklch(60% 0.2 260)", dark: "var(--custom-color)" }
- await manager.update({ ...manager.value, [role]: color })
- assert.deepEqual(manager.value[role], color)
- assert.deepEqual(await store.get(`appearance:${role}`), color)
- assert(Object.isFrozen(manager.value[role]))
+ await manager.update({ ...manager.value, colors: { ...manager.value.colors, [role]: color } })
+ assert.deepEqual(manager.value.colors[role], color)
+ assert.deepEqual((await store.get("appearance:colors"))[role], color)
+ assert(Object.isFrozen(manager.value.colors[role]))
const current = manager.value
for (const invalid of [undefined, { light: "red" }, { light: "red", dark: "" }]) {
- await assert.rejects(manager.update({ ...current, [role]: invalid }))
+
+ await assert.rejects(manager.update({ ...current, colors: { ...current.colors, [role]: invalid } }))
assert.equal(manager.value, current)
- assert.deepEqual(await store.get(`appearance:${role}`), color)
+ assert.deepEqual((await store.get("appearance:colors"))[role], color)
}
}
@@ -55,19 +60,20 @@ assert.deepEqual(manager.value.shadow, shadow)
assert.deepEqual(await store.get("appearance:shadow"), shadow)
assert.deepEqual((await AppearanceManager.open(store, new UploadManager(new FileManager(directory)))).value.shadow, shadow)
for (const invalid of [{ ...shadow.light, blur: -1 }, { ...shadow.light, opacity: 1.1 }, { ...shadow.light, x: Infinity }]) {
+
await assert.rejects(manager.update({ ...manager.value, shadow: { ...shadow, light: invalid } }))
assert.deepEqual(manager.value.shadow, shadow)
}
const updated = {
...defaultAppearance,
- background: { light: "white", dark: "black" }
+ colors: { ...defaultAppearance.colors, background: { light: "white", dark: "black" } }
}
await manager.update(updated)
-assert.deepEqual(manager.value.background, updated.background)
-assert.deepEqual(await store.get("appearance:background"), updated.background)
+assert.deepEqual(manager.value.colors.background, updated.colors.background)
+assert.deepEqual((await store.get("appearance:colors")).background, updated.colors.background)
assert.equal(await store.get("appearance:theme"), undefined)
await rm(directory, { recursive: true, force: true })
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index ae3faac..a3f74fc 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -15,7 +15,7 @@ export default function ({ children }: PropsWithChildren) {
function AppearanceRoot({ children }: PropsWithChildren) {
const { preferences } = useDesktopPreferences()
- const background = defaultAppearance.background[preferences.theme]
+ const background = defaultAppearance.colors.background[preferences.theme]
return <ReducedMotion reduced={!preferences.animations}>
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 95cfef2..1cc8d87 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -29,7 +29,7 @@ export default function Workspace() {
const desktopWallpaper = useResolveTheme(appearance.desktopWallpaper)
- const foreground = useResolveTheme(appearance.foreground)
+ const foreground = useResolveTheme(appearance.colors.foreground)
const theme = useTheme()
diff --git a/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx b/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx
index 854c882..3ec53e3 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/processes/process-item.tsx
@@ -33,7 +33,7 @@ export default function ProcessItem({ process, program }: Readonly<{ process: Pr
<Button
size="xsmall"
- color="danger"
+ color="danger:base"
pending={ending.isPending}
aria-label={`End process ${process.name ?? process.identity}`}
onPress={() => void ending.safeExecute()}
diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsx
index 327cf7f..7bfbc21 100644
--- a/source/client/view/structure/desktop/windows/snap-preview.tsx
+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx
@@ -78,7 +78,7 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, re
>
<Surface
data-snap-preview-frame
- opacity="small"
+ material={{ opacity: "small" }}
className={`absolute ${bare ? "inset-0" : ""}`}
style={bare ? undefined : windowPaintInsets(shown.position, shown.size, paintSurfaceSize, windowPaintInset)}
/>
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index 46f4372..39176e5 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -31,7 +31,7 @@ export default function () {
? "opacity-100"
: "pointer-events-none opacity-0 transition-opacity duration-200 ease-out"}
- style={{ backgroundColor: defaultAppearance.background.light }}
+ style={{ backgroundColor: defaultAppearance.colors.background.light }}
/>}
@@ -132,7 +132,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {
function ConnectedAppearance({ children }: { children: React.ReactNode }) {
- const background = useResolveTheme(LinkManagerContext.useValue().appearance.value.background)
+ const background = useResolveTheme(LinkManagerContext.useValue().appearance.value.colors.background)
return <div className="grid min-h-0" style={{ backgroundColor: background }}>{children}</div>
}
diff --git a/source/server/core/appearance-manager.ts b/source/server/core/appearance-manager.ts
index fdef152..f812031 100644
--- a/source/server/core/appearance-manager.ts
+++ b/source/server/core/appearance-manager.ts
@@ -33,14 +33,16 @@ const shadowSchema = z.strictObject({
/** The sole schema for authoritative System Appearance state. */
export const appearanceSchema: z.ZodType<Appearance> = z.strictObject({
- background: themed(z.string().min(1)),
- foreground: themed(z.string().min(1)),
- primary: themed(z.string().min(1)),
- secondary: themed(z.string().min(1)),
- success: themed(z.string().min(1)),
- warning: themed(z.string().min(1)),
- danger: themed(z.string().min(1)),
- info: themed(z.string().min(1)),
+ colors: z.strictObject({
+ background: themed(z.string().min(1)),
+ foreground: themed(z.string().min(1)),
+ primary: themed(z.string().min(1)),
+ secondary: themed(z.string().min(1)),
+ success: themed(z.string().min(1)),
+ warning: themed(z.string().min(1)),
+ danger: themed(z.string().min(1)),
+ info: themed(z.string().min(1))
+ }),
spacing: shared(bounded(appearanceLimits.spacing)),
radius: shared(bounded(appearanceLimits.radius)),
shadow: themed(shadowSchema),