An open-source, self-hosted system for apps built with web technologies.
Connect desktop theme resolution
zohayrslileh4c06de52588d
diff --git a/bun.lock b/bun.lockindex 148c05e..03f9dd2 100644--- a/bun.lock+++ b/bun.lock@@ -16,6 +16,7 @@"gsap": "^3.15.0","hono": "^4.13.2","keyv": "^5.6.0",+ "next-themes": "^0.4.6","node-rsa": "^2.0.0","react": "^19.2.8","react-aria": "^3.51.0",@@ -455,6 +456,8 @@"nanoid": ["[email protected]", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w=="],+ "next-themes": ["[email protected]", "", { "peerDependencies": { "react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc", "react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc" } }, "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA=="],+"node-releases": ["[email protected]", "", {}, "sha512-D9UOmYG3UH1V+ENW56t5QXBwJw1YEY18ruVeus89Rw+SyIgjPkCO84bRzO3uNIYosJbNwiabWVn48o3uJLjxFQ=="],"node-rsa": ["[email protected]", "", { "dependencies": { "@noble/hashes": "^2.2.0" } }, "sha512-7yfzccmBd5rm7pALJf709tPwLL987WvdT7LC/QK5Oxa5S2aabdBPjxRDxhWKkbfCc9/FiC82lwSc+ulGZHH44g=="],diff --git a/package.json b/package.jsonindex 95d2760..210b504 100644--- a/package.json+++ b/package.json@@ -46,6 +46,7 @@"gsap": "^3.15.0","hono": "^4.13.2","keyv": "^5.6.0",+ "next-themes": "^0.4.6","node-rsa": "^2.0.0","react": "^19.2.8","react-aria": "^3.51.0",diff --git a/source/client/core/link-manager/link-manager.ts b/source/client/core/link-manager/link-manager.tsindex 41122df..ebf03b5 100644--- a/source/client/core/link-manager/link-manager.ts+++ b/source/client/core/link-manager/link-manager.ts@@ -46,9 +46,9 @@ export default class LinkManager extends TheLink {this.nativeTheme.addEventListener("change", this.nativeThemeChanged)}- public async updateTheme(preference: ThemePreference) {- this.themePreference = preference- await this.theme.update(this.effectiveTheme())+ public async updateTheme(theme: ThemePreference) {+ this.themePreference = theme+ await this.$inbound.publish("/change-theme", theme)}private effectiveTheme(): Theme {diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsxindex 4ac30d7..b9a52ff 100644--- a/source/client/view/appearance/appearance.tsx+++ b/source/client/view/appearance/appearance.tsx@@ -1,19 +1,24 @@import ReducedMotion from "@libs/react-motion"import { standardAppearance } from "@phreshos/core"+import { ThemeProvider } from "next-themes"import { ReactNode } from "react"import "./appearance.css"export default function ({ children, reducedMotion }: AppearanceProps) {- return <ReducedMotion reduced={reducedMotion}>+ return <ThemeProvider attribute="class" defaultTheme="system">- <div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: standardAppearance.background.light }}>+ <ReducedMotion reduced={reducedMotion}>- {children}+ <div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: standardAppearance.background.light }}>- </div>+ {children}- </ReducedMotion>+ </div>++ </ReducedMotion>++ </ThemeProvider>}interface AppearanceProps {diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsxindex e8ca99e..74e489e 100644--- a/source/client/view/structure/structure.tsx+++ b/source/client/view/structure/structure.tsx@@ -4,14 +4,15 @@ import { TransmittedLinkManager } from "@server/core/link-manager/link-manager"import SocketLink from "@libs/the-link/plugins/client-link/socket-link"import LinkManager from "@client/core/link-manager/link-manager"import { AppearanceProvider, useResolveTheme } from "@phreshos/react-ui"+import { useTheme } from "next-themes"import Loading from "../components/loading"import Alert from "../components/alert"import { ApplicationContext, LinkManagerContext } from "../contexts"import usePromise from "@libs/react-promise"import Authentication from "./authentication/authentication"-import { useCallback, useState } from "react"+import { useCallback, useEffect, useState } from "react"import Readiness, { useReady } from "@libs/readiness/main"-import { standardAppearance } from "@phreshos/core"+import { standardAppearance, type ThemePreference } from "@phreshos/core"const startupRequirements = ["connection", "session", "wallpaper"] as const@@ -100,9 +101,21 @@ function ConnectedDesktop({ linkManager }: { linkManager: LinkManager }) {useReady("connection")+ const { resolvedTheme, setTheme } = useTheme()++ const inbound = ReactTunnel.useFactory(linkManager.$inbound)++ inbound.useSubscribe("/change-theme", useCallback(function (theme: ThemePreference) {+ setTheme(theme === "default" ? "system" : theme)+ }, [setTheme]))+const appearance = useProperty(linkManager.appearance)- const theme = useProperty(linkManager.theme)+ const theme = resolvedTheme === "dark" ? "dark" : "light"++ useEffect(function () {+ void linkManager.theme.update(theme)+ }, [linkManager, theme])return <LinkManagerContext.Provider value={linkManager}>