Skip to content

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

Correct Program command and wallpaper lifecycles

zohayrslileh8c8ccc4605bf
diff --git a/scripts/contracts/worker-runtime.ts b/scripts/contracts/worker-runtime.ts
index a10c412..5d4196c 100644
--- a/scripts/contracts/worker-runtime.ts
+++ b/scripts/contracts/worker-runtime.ts
@@ -1,10 +1,10 @@
import assert from "node:assert/strict"
import { mkdtemp, rm, writeFile } from "node:fs/promises"
import { tmpdir } from "node:os"
-import { join, resolve } from "node:path"
+import { delimiter, join, resolve } from "node:path"
import { pathToFileURL } from "node:url"
import { decode, encode } from "@msgpack/msgpack"
-import { WorkerServerRuntime } from "@server/core/link-manager/auth-manager/process-manager/server-runtime"
+import { commandServerEnvironment, WorkerServerRuntime } from "@server/core/link-manager/auth-manager/process-manager/server-runtime"
import Program from "@server/core/link-manager/auth-manager/program-manager/program"
import type { ProgramConfig } from "@server/core/link-manager/auth-manager/program-manager/config"
@@ -12,6 +12,11 @@ const directory = await mkdtemp(join(tmpdir(), "phresh-worker-runtime-"))
const entry = join(directory, "server.mjs")
const codec = pathToFileURL(resolve("node_modules/@msgpack/msgpack/dist.esm/index.mjs")).href
+assert.equal(
+ commandServerEnvironment(directory, { Path: "/native/bin" }).Path,
+ `${join(directory, "node_modules", ".bin")}${delimiter}/native/bin`
+)
+
await writeFile(entry, `
import { parentPort } from "node:worker_threads"
import { decode, encode } from ${JSON.stringify(codec)}
diff --git a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx b/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
index 7237188..875d9e7 100644
--- a/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
+++ b/source/client/view/structure/desktop/wallpaper/wallpaper.tsx
@@ -12,7 +12,7 @@ type WallpaperSource = Readonly<{
/**
* Displays only a completely loaded wallpaper source.
*
- * A filename asks for a served image and `null` selects the Desktop fallback.
+ * A filename asks for a served image and `null` selects the bundled wallpaper.
* The previous loaded source stays visible until its replacement is ready.
*/
export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps) {
@@ -29,23 +29,31 @@ export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps)
}, [application.doors.uploads, file])
- const fallback = useMemo<WallpaperSource>(() => ({ key: "bundled", source: bundledWallpaper }), [])
- const [displayed, setDisplayed] = useState<WallpaperSource>(fallback)
+ const [displayed, setDisplayed] = useState<WallpaperSource | null>(null)
const [previous, setPrevious] = useState<WallpaperSource | null>(null)
+ const loadedSources = useRef(new Set<string>())
const transition = useRef<number | null>(null)
useEffect(() => () => {
if (transition.current !== null) clearTimeout(transition.current)
}, [])
- const sources = desired.key === displayed.key
- ? previous ? [previous, displayed] : [displayed]
- : previous ? [previous, displayed, desired] : [displayed, desired]
+ const sources = distinct([previous, displayed, desired])
+
+ useEffect(() => {
+ if (loadedSources.current.has(desired.key)) display(desired)
+ }, [desired])
function loaded(source: WallpaperSource) {
+ loadedSources.current.add(source.key)
+
+ display(source)
+ }
+
+ function display(source: WallpaperSource) {
if (source.key !== desired.key) return
- if (source.key === displayed.key) {
+ if (source.key === displayed?.key) {
onReady?.()
return
}
@@ -56,10 +64,12 @@ export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps)
setDisplayed(source)
onReady?.()
- transition.current = window.setTimeout(() => {
- setPrevious(null)
- transition.current = null
- }, 700)
+ if (displayed) {
+ transition.current = window.setTimeout(() => {
+ setPrevious(null)
+ transition.current = null
+ }, 700)
+ }
}
function failed(source: WallpaperSource) {
@@ -72,7 +82,9 @@ export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps)
source={source}
- visible={source.key === displayed.key}
+ visible={source.key === displayed?.key}
+
+ transitioning={previous !== null}
onLoad={() => loaded(source)}
@@ -81,14 +93,30 @@ export function WallpaperBackground({ file, onReady }: WallpaperBackgroundProps)
/>)}</>
}
-function WallpaperLayer({ source, visible, onLoad, onError }: { source: WallpaperSource, visible: boolean, onLoad: () => void, onError: () => void }) {
+function distinct(sources: readonly (WallpaperSource | null)[]) {
+ const keys = new Set<string>()
+
+ return sources.filter((source): source is WallpaperSource => {
+ if (!source || keys.has(source.key)) return false
+ keys.add(source.key)
+ return true
+ })
+}
+
+function WallpaperLayer({ source, visible, transitioning, onLoad, onError }: {
+ source: WallpaperSource
+ visible: boolean
+ transitioning: boolean
+ onLoad: () => void
+ onError: () => void
+}) {
return <>
<div
aria-hidden="true"
- className={`pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat transition-opacity duration-700 ease-out ${visible ? "opacity-100" : "opacity-0"}`}
+ className={`pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat ${transitioning ? "transition-opacity duration-700 ease-out" : ""} ${visible ? "opacity-100" : "opacity-0"}`}
style={{ backgroundImage: `url(${source.source})` }}
diff --git a/source/server/core/link-manager/auth-manager/process-manager/server-runtime.ts b/source/server/core/link-manager/auth-manager/process-manager/server-runtime.ts
index 0594350..534c8a1 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/server-runtime.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/server-runtime.ts
@@ -1,7 +1,7 @@
import ProcessTree from "@libs/process-tree"
import { spawn, type ChildProcess } from "node:child_process"
import { Worker } from "node:worker_threads"
-import { join } from "node:path"
+import { delimiter, join } from "node:path"
export interface ServerRuntime {
@@ -41,12 +41,7 @@ export class CommandServerRuntime implements ServerRuntime {
serialization: "advanced",
- env: {
-
- ...process.env,
-
- PATH: `${join(process.cwd(), "node_modules", ".bin")}:${process.env.PATH}`
- }
+ env: commandServerEnvironment(directory)
})
if (typeof this.child.send !== "function") throw new Error("The server process has no IPC channel")
@@ -76,6 +71,21 @@ export class CommandServerRuntime implements ServerRuntime {
public stop() { this.tree.stop() }
}
+/** Give a Server command the package-local tools belonging to its execution directory. */
+export function commandServerEnvironment(directory: string, environment: NodeJS.ProcessEnv = process.env) {
+
+ const key = Object.keys(environment).find(name => name.toLowerCase() === "path") ?? "PATH"
+
+ const inherited = environment[key]
+
+ return {
+
+ ...environment,
+
+ [key]: [join(directory, "node_modules", ".bin"), inherited].filter(Boolean).join(delimiter)
+ }
+}
+
/** One JavaScript Server running as an isolate inside the System process. */
export class WorkerServerRuntime implements ServerRuntime {