Skip to content

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

Tell the Programs of a new Theme when the Desktop's views are ready to cross

zohayrslileh8c271125cf73
diff --git a/source/client/view/appearance/desktop-preferences.tsx b/source/client/view/appearance/desktop-preferences.tsx
index 047aac0..22c30c8 100644
--- a/source/client/view/appearance/desktop-preferences.tsx
+++ b/source/client/view/appearance/desktop-preferences.tsx
@@ -32,6 +32,8 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chil
const desiredScale = resolveStoredDesktopScale(storedScale.value)
const desired = useMemo<DesktopPreferences>(() => ({ theme: desiredTheme, animations: desiredAnimations, scale: desiredScale }), [desiredAnimations, desiredScale, desiredTheme])
const [preferences, setPreferences] = useState(desired)
+ // What the Programs are told: a new Theme once the Desktop starts crossing to it, so they cross with it.
+ const [announced, setAnnounced] = useState(desired)
const current = useRef(preferences)
const pending = useRef<PendingCommit | null>(null)
const revision = useRef(0)
@@ -70,6 +72,7 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chil
if (!themeChanged) {
setPreferences(desired)
+ setAnnounced(desired)
return
}
@@ -80,6 +83,8 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chil
pending.current = { preferences: desired, resolve }
setPreferences(desired)
})
+ }, () => {
+ if (revision.current === change) setAnnounced(desired)
})
}, [desired])
@@ -105,7 +110,7 @@ export default function DesktopPreferencesProvider({ children }: Readonly<{ chil
pending.current = null
}, [])
- const owner = useMemo(() => ({ preferences, update, setTransaction }), [preferences, update, setTransaction])
+ const owner = useMemo(() => ({ preferences, announced, update, setTransaction }), [preferences, announced, update, setTransaction])
return <DesktopPreferencesContext.Provider value={owner}>{children}</DesktopPreferencesContext.Provider>
}
@@ -162,6 +167,8 @@ function useMediaPreference(query: string) {
interface DesktopPreferencesOwner {
readonly preferences: DesktopPreferences
+ /** The preferences the Programs are told of, which follow a new Theme once the Desktop starts showing it. */
+ readonly announced: DesktopPreferences
readonly update: (change: DesktopPreferencesUpdate) => void
readonly setTransaction: (transaction: AppearanceTransaction) => void
}
diff --git a/source/client/view/appearance/theme-transition.ts b/source/client/view/appearance/theme-transition.ts
index 89072fa..275fb60 100644
--- a/source/client/view/appearance/theme-transition.ts
+++ b/source/client/view/appearance/theme-transition.ts
@@ -22,12 +22,17 @@ type ActiveTransition = Readonly<{
const active = new WeakMap<Document, ActiveTransition>()
const revisions = new WeakMap<Document, number>()
-/** Applies one theme state change through the document's old and new rendered views. */
+/**
+ * Applies one theme state change through the document's old and new rendered views. `ready` runs
+ * when the views are ready to cross, or once the change is applied when nothing crosses: what
+ * should change together with the Desktop, such as the Programs in their frames, starts then.
+ */
export function transitionTheme(
document: Document,
transaction: AppearanceTransaction,
animated: boolean,
- update: () => Promise<void>
+ update: () => Promise<void>,
+ ready: () => void = () => undefined
) {
const target = document as ViewTransitionDocument
const revision = (revisions.get(document) ?? 0) + 1
@@ -39,7 +44,7 @@ export function transitionTheme(
previous?.transition.skipTransition()
active.delete(document)
clearTransition(document)
- return update()
+ return update().then(ready)
}
const root = document.documentElement
@@ -61,11 +66,13 @@ export function transitionTheme(
previous?.transition.skipTransition()
active.delete(document)
clearTransition(document)
- return update()
+ return update().then(ready)
}
active.set(document, { revision, transition: view })
+ settle(view.ready, ready)
+
// The new view is live, not a still image: any late commit would animate
// inside it. Changes stay instant until the whole transition finishes.
settle(view.finished, () => {
diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsx
index ede3c9d..fe963d3 100644
--- a/source/client/view/structure/structure.tsx
+++ b/source/client/view/structure/structure.tsx
@@ -136,7 +136,7 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {
useReady(connectionRequirement)
- const { preferences, update } = useDesktopPreferences()
+ const { announced, update } = useDesktopPreferences()
const inbound = ReactTunnel.useFactory(linkManager.$inbound)
@@ -149,8 +149,8 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {
useRememberSystemAppearance(appearance)
useEffect(function () {
- void linkManager.updateDesktopPreferences(preferences)
- }, [linkManager, preferences])
+ void linkManager.updateDesktopPreferences(announced)
+ }, [linkManager, announced])
return <LinkManagerContext.Provider value={linkManager}>