An open-source, self-hosted system for apps built with web technologies.
The System announces startup changes, and pin and changePermissions by their new names
zohayrslileh8bff0cf4268b
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.tsindex 11bb435..72b8d99 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -207,6 +207,16 @@ export default class ProgramManager extends TheLink {return this.arrived(payload)}+ @Subscribe("/startup-change")+ protected async startupChanged(payload: ProgramRecord | null, launch: unknown) {++ if (!payload) return+ const program = this.programs.get(payload.identity)+ if (!program || program.reference !== payload.reference) return+ program.startup = launch !== null+ await this.$inbound.publish("/startup", program, launch)+ }+@Subscribe("/pinned")protected async pinnedChanged(payload: ProgramRecord | null, pinned: boolean) {diff --git a/source/client/core/link-manager/auth-manager/program-manager/program.ts b/source/client/core/link-manager/auth-manager/program-manager/program.tsindex 26cbec3..20e2ade 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program.ts@@ -42,6 +42,12 @@ export default class Program {/** Effective authority synchronized with the authoritative Program state. */public permissions: Permissions+ /** The media types it opens, as its definition declares them. */+ public readonly opens: readonly string[]++ /** Whether it starts with the System. */+ public startup: boolean+public constructor(programManager: ProgramManager, payload: ProgramRecord) {this.programManager = programManager@@ -71,6 +77,10 @@ export default class Program {this.client = payload.clientthis.permissions = parsePermissions(payload.permissions)++ this.opens = payload.opens++ this.startup = payload.startup}public updatePermissions(permissions: unknown) {diff --git a/source/client/view/components/desktop-host/announcements.ts b/source/client/view/components/desktop-host/announcements.tsindex e478eb4..97a208d 100644--- a/source/client/view/components/desktop-host/announcements.ts+++ b/source/client/view/components/desktop-host/announcements.ts@@ -188,14 +188,19 @@ export default function useAnnouncements(authManager: AuthManager, panes: Map<stprograms.useSubscribe("/pinned", useCallback((entry: Program | null, pinned: boolean) => {if (!entry || typeof pinned !== "boolean") returnconst record = sdkProgram(entry)- post(entry.identity, "host-program", "pinned", entry.identity, record, pinned)- post(entry.identity, "program-host", "pinned", entry.reference, pinned)+ post(entry.identity, "host-program", "pin", entry.identity, record, pinned)+ post(entry.identity, "program-host", "pin", entry.reference, pinned)}, [post]))programs.useSubscribe("/permissions", useCallback((entry: Program | null) => {if (!entry) returnconst record = sdkProgram(entry)- post(entry.identity, "host-program", "permissions", entry.identity, record)- post(entry.identity, "program-host", "permissions", entry.reference, record)+ post(entry.identity, "host-program", "changePermissions", entry.identity, record)+ post(entry.identity, "program-host", "changePermissions", entry.reference, record)+ }, [post]))+ programs.useSubscribe("/startup", useCallback((entry: Program | null, launch: unknown) => {+ if (!entry) return+ post(entry.identity, "host-program", "changeStartup", entry.identity, sdkProgram(entry), launch)+ post(entry.identity, "program-host", "changeStartup", entry.reference, launch)}, [post]))programs.useSubscribe("/store-change", useCallback((reference: unknown, key: unknown, snapshot: unknown) => {diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 55da759..e6da1bb 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -19,6 +19,7 @@ import {parsePermission,parsePermissionName,parsePermissions,+ opensType,parseSystemProgramListOptions,parseSystemServiceListOptions,type PermissionRequestInput,@@ -217,8 +218,11 @@ export default function host(authManager: AuthManager, pane: string, viewport: Dif (word === "host-program-list") {- const { installed } = parseSystemProgramListOptions(args[0])- const programs = [...programManager.programs.values()].filter(program => installed === undefined || program.installed === installed)+ const { installed, opens, startup } = parseSystemProgramListOptions(args[0])+ const programs = [...programManager.programs.values()].filter(program =>+ (installed === undefined || program.installed === installed)+ && (opens === undefined || opensType(program.opens, opens))+ && (startup === undefined || program.startup === startup))const visible = []for (const program of programs) if (await access.canProgram(program)) visible.push(program)diff --git a/source/server/core/link-manager/auth-manager/program-manager/entry.ts b/source/server/core/link-manager/auth-manager/program-manager/entry.tsindex 4826ba1..aa8e66e 100644--- a/source/server/core/link-manager/auth-manager/program-manager/entry.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/entry.ts@@ -1,4 +1,5 @@import Program from "./program"+import ProgramStateStorage from "./state"import type { Permissions, ProgramSnapshot } from "@phreshos/core"/**@@ -53,8 +54,12 @@ export default class Entry {permissions: this.permissions(),- installed: this.installed- } satisfies ProgramSnapshot & { permissions: Permissions }+ installed: this.installed,++ // Whether it starts with the System, so a list can be filtered+ // where it is held. The launch itself stays behind `startup.get()`.+ startup: new ProgramStateStorage(this.program).startup() !== null+ } satisfies ProgramSnapshot & { permissions: Permissions, startup: boolean }}public toJSON() {diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.tsindex a402adb..54130b2 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -266,8 +266,8 @@ export default class ProgramManager extends TheLink {const permissions = entry.permissions()await Promise.all([- this.authManager.processManager.announceHost("program", entry.identity, "permissions", entry.identity, entry),- this.authManager.processManager.announceSubject("program", entry.identity, "permissions", entry.program.reference, permissions),+ this.authManager.processManager.announceHost("program", entry.identity, "changePermissions", entry.identity, entry),+ this.authManager.processManager.announceSubject("program", entry.identity, "changePermissions", entry.program.reference, permissions),this.$outbound.publish("/permissions-change", entry.record())])}@@ -682,6 +682,8 @@ export default class ProgramManager extends TheLink {if (isDeepStrictEqual(state.startup(), launch)) returnstate.setStartup(launch)+ await this.announceStartup(program, launch)+return}@@ -690,12 +692,29 @@ export default class ProgramManager extends TheLink {if (state.startup() === null) returnstate.setStartup(null)+ await this.announceStartup(program, null)+return}throw new Error(`The host does not know the startup operation "${operation}"`)}+ // Said once the record is written, whoever set or removed it: the+ // Program itself, the owner's Settings, or the terminal.+ private async announceStartup(program: Program, launch: Launch | null) {++ const entry = this.programs.get(program.identity)++ if (!entry || entry.program !== program) return++ await Promise.all([+ this.authManager.processManager.announceHost("program", entry.identity, "changeStartup", entry.identity, entry, launch),+ this.authManager.processManager.announceSubject("program", entry.identity, "changeStartup", entry.program.reference, launch),+ this.$outbound.publish("/startup-change", entry.record(), launch)+ ])+ }+/** Read or change the pinned state and publish only effective transitions. */public async pinned(program: Program, operation: "get" | "pin" | "unpin"): Promise<boolean> {const state = new ProgramStateStorage(program)@@ -707,7 +726,10 @@ export default class ProgramManager extends TheLink {state.setPinned(pinned)const entry = this.find(program.identity)- await this.authManager.processManager.announceHost("program", entry.identity, "pinned", entry.identity, entry, pinned)+ await Promise.all([+ this.authManager.processManager.announceHost("program", entry.identity, "pin", entry.identity, entry, pinned),+ this.authManager.processManager.announceSubject("program", entry.identity, "pin", entry.program.reference, pinned)+ ])await this.$outbound.publish("/pinned", entry.record(), pinned)return pinned}diff --git a/source/server/core/system.ts b/source/server/core/system.tsindex 82ee7f4..7c52def 100644--- a/source/server/core/system.ts+++ b/source/server/core/system.ts@@ -57,7 +57,8 @@ export default class System {return [...this.programManager.programs.values()].filter(entry =>(options.installed === undefined || entry.installed === options.installed)- && (options.opens === undefined || opensType(entry.program.config.opens ?? [], options.opens)))+ && (options.opens === undefined || opensType(entry.program.config.opens ?? [], options.opens))+ && (options.startup === undefined || entry.record().startup === options.startup))}public findProgram(identity: string) {diff --git a/tests/permission-synchronization.test.ts b/tests/permission-synchronization.test.tsindex a1c2940..f97d107 100644--- a/tests/permission-synchronization.test.ts+++ b/tests/permission-synchronization.test.ts@@ -20,7 +20,8 @@ function record(permissions: ProgramRecord["permissions"]): ProgramRecord {hasAgent: false,server: null,client: null,- permissions+ permissions,+ startup: false}}diff --git a/tests/program-creation.test.ts b/tests/program-creation.test.tsindex bb4e31a..6d3d8fb 100644--- a/tests/program-creation.test.ts+++ b/tests/program-creation.test.ts@@ -121,25 +121,60 @@ test("permission changes publish one complete effective snapshot through both Prexpect(records).toHaveLength(1)expect(records[0]).toMatchObject({ permissions })expect(announceHost).toHaveBeenCalledExactlyOnceWith(- "program", program.identity, "permissions", program.identity, manager.find(program.identity)+ "program", program.identity, "changePermissions", program.identity, manager.find(program.identity))expect(announceSubject).toHaveBeenCalledExactlyOnceWith(- "program", program.identity, "permissions", program.reference, permissions+ "program", program.identity, "changePermissions", program.reference, permissions)})test("pinning emits Program and global events only when the boolean changes", async context => {- const { manager, definition, announceHost } = fixture(context)+ const { manager, definition, announceHost, announceSubject } = fixture(context)const program = await manager.create(definition())announceHost.mockClear()+ announceSubject.mockClear()await manager.pinned(program, "pin")await manager.pinned(program, "pin")await manager.pinned(program, "unpin")expect(announceHost.mock.calls.map(([, owner, event, , , pinned]) => [owner, event, pinned])).toEqual([- [program.identity, "pinned", true],- [program.identity, "pinned", false]+ [program.identity, "pin", true],+ [program.identity, "pin", false]+ ])+ expect(announceSubject.mock.calls.map(([, , event, subject, pinned]) => [event, subject, pinned])).toEqual([+ ["pin", program.reference, true],+ ["pin", program.reference, false]+ ])+})++test("startup changes emit Program and global events, and filter the Program list", async context => {+ const { manager, definition, announceHost, announceSubject } = fixture(context)+ const program = await manager.create(definition())+ const records: unknown[][] = []+ const stop = manager.$outbound.subscribe("/startup-change", (record, launch) => { records.push([record, launch]) })+ context.onTestFinished(stop)+ announceHost.mockClear()+ announceSubject.mockClear()++ await manager.startup(program, "set", { name: "background" })+ await manager.startup(program, "set", { name: "background" })+ expect(manager.find(program.identity).record().startup).toBe(true)+ await manager.startup(program, "remove")+ await manager.startup(program, "remove")+ expect(manager.find(program.identity).record().startup).toBe(false)++ expect(announceHost.mock.calls.map(([, owner, event, , , launch]) => [owner, event, launch])).toEqual([+ [program.identity, "changeStartup", { name: "background" }],+ [program.identity, "changeStartup", null]+ ])+ expect(announceSubject.mock.calls.map(([, , event, subject, launch]) => [event, subject, launch])).toEqual([+ ["changeStartup", program.reference, { name: "background" }],+ ["changeStartup", program.reference, null]+ ])+ expect(records.map(([record, launch]) => [(record as { startup: boolean }).startup, launch])).toEqual([+ [true, { name: "background" }],+ [false, null]])})