An open-source, self-hosted system for apps built with web technologies.
Revert waiting for Programs before the new Theme's view: a sandboxed frame paints live over the frozen view, so the wait showed its early change longer
zohayrslilehee8ead36755b
diff --git a/source/client/core/link-manager/desktop-preferences-state.ts b/source/client/core/link-manager/desktop-preferences-state.tsindex 4684911..54fa8db 100644--- a/source/client/core/link-manager/desktop-preferences-state.ts+++ b/source/client/core/link-manager/desktop-preferences-state.ts@@ -1,23 +1,11 @@import { type DesktopPreferences } from "@phreshos/core"import { Tunnel } from "@the-link/core"-/**- * The longest a change waits for one Program to show it. A Program built before Programs confirmed- * what they show never does, and the change goes on without it.- */-const showingLimit = 150-/** Complete effective preferences owned by one browser Desktop. */export default class DesktopPreferencesState {public readonly tunnel = new Tunnel()- /** The Programs told of the current change that have not shown it yet, by their pane. */- private readonly showing = new Map<string, Readonly<{ shown: Promise<void>, resolve: () => void }>>()-- /** Settles once the current preferences are shown, here and by every Program told of them. */- private settled: Promise<void> = Promise.resolve()-public constructor(private current: DesktopPreferences) {}public get value() {@@ -25,53 +13,15 @@ export default class DesktopPreferencesState {return this.current}- /**- * Makes these the effective preferences and tells every Program that follows them. It settles- * once each Program told has shown them, or has had its time: a change the Desktop shows in- * one step, such as a new Theme, waits for it, so Programs change in the same step.- */- public update(preferences: DesktopPreferences) {+ public async update(preferences: DesktopPreferences) {- if (samePreferences(this.current, preferences)) return this.settled+ if (samePreferences(this.current, preferences)) returnthis.current = preferences- this.settled = (async () => {-- // This event is intentionally local: Desktop preferences do not belong- // to the System transport or to any other Desktop representation.- await this.tunnel.publish("change", preferences)-- await Promise.all([...this.showing.values()].map(waiting => waiting.shown))- })()-- return this.settled- }-- /** One Program is told of the current change; the change is shown once it says so, or its time is up. */- public telling(pane: string) {-- this.showing.get(pane)?.resolve()-- let resolve!: () => void- const shown = new Promise<void>(settle => { resolve = settle })- const timer = setTimeout(() => done(), showingLimit)- const done = () => {-- clearTimeout(timer)-- if (this.showing.get(pane)?.shown === shown) this.showing.delete(pane)-- resolve()- }-- this.showing.set(pane, { shown, resolve: done })- }-- /** A Program says it shows the current preferences. */- public shown(pane: string) {-- this.showing.get(pane)?.resolve()+ // This event is intentionally local: Desktop preferences do not belong+ // to the System transport or to any other Desktop representation.+ await this.tunnel.publish("change", preferences)}}diff --git a/source/client/view/appearance/desktop-preferences.tsx b/source/client/view/appearance/desktop-preferences.tsxindex 2fb729f..047aac0 100644--- a/source/client/view/appearance/desktop-preferences.tsx+++ b/source/client/view/appearance/desktop-preferences.tsx@@ -36,7 +36,6 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chilconst pending = useRef<PendingCommit | null>(null)const revision = useRef(0)const transaction = useRef<AppearanceTransaction>(defaultAppearance.transaction)- const show = useRef<Show | null>(null)const update = useCallback(function (change: DesktopPreferencesUpdate) {if (change.theme !== undefined) {@@ -60,10 +59,6 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chiltransaction.current = value}, [])- const setShow = useCallback(function (value: Show | null) {- show.current = value- }, [])-useEffect(() => {if (samePreferences(current.current, desired)) return@@ -85,9 +80,6 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chilpending.current = { preferences: desired, resolve }setPreferences(desired)})-- // Programs show the new Theme in their own frames; the new view is taken once they do.- if (revision.current === change) await show.current?.(desired)})}, [desired])@@ -113,7 +105,7 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chilpending.current = null}, [])- const owner = useMemo(() => ({ preferences, update, setTransaction, setShow }), [preferences, update, setTransaction, setShow])+ const owner = useMemo(() => ({ preferences, update, setTransaction }), [preferences, update, setTransaction])return <DesktopPreferencesContext.Provider value={owner}>{children}</DesktopPreferencesContext.Provider>}@@ -168,14 +160,10 @@ function useMediaPreference(query: string) {)}-/** Tells the Programs of new preferences, settling once they show them. */-type Show = (preferences: DesktopPreferences) => Promise<void>-interface DesktopPreferencesOwner {readonly preferences: DesktopPreferencesreadonly update: (change: DesktopPreferencesUpdate) => voidreadonly setTransaction: (transaction: AppearanceTransaction) => void- readonly setShow: (show: Show | null) => void}interface PendingCommit {diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.tsindex 01ed7a2..bcf3b73 100644--- a/source/client/view/components/desktop-host/client-process-boundary.ts+++ b/source/client/view/components/desktop-host/client-process-boundary.ts@@ -534,9 +534,6 @@ export default class ClientProcessBoundary extends TheLink {if (!this.stopDesktopPreferences) this.stopDesktopPreferences = this.authManager.linkManager.desktopPreferences.tunnel.subscribe("change", (preferences: unknown) => {- // The change counts as shown once this Program says it shows it too.- this.authManager.linkManager.desktopPreferences.telling(this.pane)-this.deliver("host-desktop-preferences", "change", preferences).catch(() => undefined)})diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex ae0f2c2..1795521 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -327,14 +327,6 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "desktopPreferences") return [authManager.linkManager.desktopPreferences.value]- // This pane shows the preferences it was last told of.- if (word === "desktop-preferences-shown") {-- authManager.linkManager.desktopPreferences.shown(pane)-- return []- }-if (word === "updateDesktopPreferences") {await access.require("desktopPreferences", [])diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsxindex ad38535..ede3c9d 100644--- a/source/client/view/structure/structure.tsx+++ b/source/client/view/structure/structure.tsx@@ -10,7 +10,7 @@ import usePromise from "@libs/react-promise"import { useDesktopPreferences } from "../appearance/desktop-preferences"import { useRememberSystemAppearance } from "../appearance/appearance"import Authentication from "./authentication/authentication"-import { useCallback, useEffect, useLayoutEffect, useState } from "react"+import { useCallback, useEffect, useState } from "react"import Readiness, { useReadiness, useReady } from "@libs/readiness"import { type DesktopPreferencesUpdate } from "@phreshos/core"import { cssEasing } from "../appearance/motion"@@ -136,7 +136,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {useReady(connectionRequirement)- const { preferences, update, setShow } = useDesktopPreferences()+ const { preferences, update } = useDesktopPreferences()const inbound = ReactTunnel.useFactory(linkManager.$inbound)@@ -152,12 +152,6 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {void linkManager.updateDesktopPreferences(preferences)}, [linkManager, preferences])- // A new Theme reaches the Programs within the Desktop's own change, so they change with it.- useLayoutEffect(function () {- setShow(next => linkManager.updateDesktopPreferences(next))- return () => setShow(null)- }, [linkManager, setShow])-return <LinkManagerContext.Provider value={linkManager}><Authentication />diff --git a/tests/desktop-preferences-state.test.ts b/tests/desktop-preferences-state.test.tsdeleted file mode 100644index 6390076..0000000--- a/tests/desktop-preferences-state.test.ts+++ /dev/null@@ -1,37 +0,0 @@-import assert from "node:assert/strict"-import { test } from "vitest"-import DesktopPreferencesState from "@client/core/link-manager/desktop-preferences-state"--const light = { theme: "light", animations: true, scale: 1 } as const-const dark = { theme: "dark", animations: true, scale: 1 } as const--test("a change settles once every Program told of it shows it", async () => {-- const state = new DesktopPreferencesState(light)- state.tunnel.subscribe("change", () => { state.telling("settings") })-- let settled = false- const change = state.update(dark).then(() => { settled = true })-- await new Promise(resolve => setTimeout(resolve, 20))- assert.equal(settled, false)-- // The same preferences again wait for the same showing.- assert.equal(state.update(dark), state.update(dark))-- state.shown("settings")- await change- assert.equal(settled, true)-})--test("a Program that never says it shows a change is not waited for past its time", async () => {-- const state = new DesktopPreferencesState(light)- state.tunnel.subscribe("change", () => { state.telling("older-program") })-- const started = Date.now()- await state.update(dark)- const waited = Date.now() - started-- assert.ok(waited >= 140 && waited < 400, `waited ${waited} ms`)-})