Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea81733
fix(server): staging and the hourly sweep refuse an org's .viewswitch…
2witstudios Nov 26, 2026
3ac9acc
fix(server): the library scan, org.json and a set's removal never rea…
2witstudios Nov 26, 2026
96957d5
fix(web,server): the Orgs show's library has its own cache key; the S…
2witstudios Nov 26, 2026
0da1dc0
fix(server): a new org is filled in staging and renamed into place; t…
2witstudios Nov 26, 2026
1e9340d
fix(server): a hand-edited settings.json is followed while the server…
2witstudios Nov 26, 2026
09e0932
fix(apple): each build has its own server log, the ad hoc build passe…
2witstudios Nov 26, 2026
aa655eb
feat(shared): checkPack warns about a show's name or initial in a scr…
2witstudios Nov 26, 2026
fb873db
fix(apple): the ad hoc build launches: library validation off for --u…
2witstudios Nov 26, 2026
0c8fe59
perf(web): a _shared/ change reloads only the views that use that fol…
2witstudios Nov 26, 2026
6bb6417
perf(server): one library change costs one scan: a finished scan is k…
2witstudios Nov 26, 2026
9f027ca
perf(server,web): a library change carries each changed view's hash, …
2witstudios Nov 26, 2026
fd97078
fix(server,shared,apple): flushes publish in order, style attributes …
2witstudios Nov 26, 2026
27f85ee
fix(server,web,apple): a linked staging token or projects/ is never w…
2witstudios Nov 26, 2026
7f41b16
fix(server): scene titles are read from the checked real path with O_…
2witstudios Nov 26, 2026
061e5a8
fix(web,server,shared,apple): the org's own views follow any shared c…
2witstudios Nov 26, 2026
67c40d9
fix(server): the title cache stamps through a no-link open too, so a …
2witstudios Nov 26, 2026
1e948e5
fix(server,web,apple): one failed flush can't stall the rest, the A→B…
2witstudios Nov 26, 2026
c117088
fix(server,shared): a named pipe named like a view can't hang the sca…
2witstudios Nov 26, 2026
fa9dcec
fix(server): every full read of a library file goes through one no-li…
2witstudios Nov 26, 2026
697440d
fix(server,shared): the scan's JSON and manifests read no-link and no…
2witstudios Nov 26, 2026
ac6b42a
fix(server,shared): a read-only starter's folders are made writable t…
2witstudios Nov 26, 2026
6cb25bc
fix(server): read_file, write_file, the on-air guard, duplicate and n…
2witstudios Nov 26, 2026
e258e7b
refactor(server): an install reads staged files straight from raw wit…
2witstudios Nov 26, 2026
ddb1b83
fix(server,shared): a view's <style> comments still warn (a page's fi…
2witstudios Nov 26, 2026
7813fd6
fix(server): the guide and the library kit read non-blocking plain fi…
2witstudios Nov 26, 2026
ef9448e
fix(server,shared): a file the on-air scan can't read marks its list …
2witstudios Nov 26, 2026
5f0f7c8
fix(server): the guard names an on-air file it can't read instead of …
2witstudios Nov 26, 2026
046c4b6
fix(server,shared): stale on-air refs don't block agents, customize c…
2witstudios Nov 26, 2026
117f237
fix(server): the unreadable-file refusal says what it now means (a di…
2witstudios Nov 26, 2026
f10118d
fix(server): an on-air ref is unknown only when /library/ would serve…
2witstudios Nov 26, 2026
26d0941
test(server): the kit leaves a folder or pipe alone, and an on-air fi…
2witstudios Nov 26, 2026
c3d3d0d
fix(server): resolveInLibrary says no permission as that and passes a…
2witstudios Nov 26, 2026
8f5a9e5
fix(server): an on-air ref that is a dangling link lists where it poi…
2witstudios Nov 26, 2026
807bc78
fix(server): on-air refs are followed through links for every ref, fr…
2witstudios Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ jobs:
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .bun-version
# Swift 6 language mode makes a possible data race (a captured var mutated from another
# thread, say) a build error, where the package's own mode only warns.
- run: swift build --build-tests -Xswiftc -swift-version -Xswiftc 6 -Xswiftc -warnings-as-errors
working-directory: apps/apple/Kit
- run: swift test
working-directory: apps/apple/Kit
22 changes: 20 additions & 2 deletions apps/apple/Kit/Sources/ViewSwitcherKit/ServerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public struct Launch: Sendable {
}
}

/// The installed app's bundle id: its server log is the one people (and support) look for.
public let releaseBundleID = "com.twowitstudios.viewswitcher.mac"

/// Where this build's server log goes, so builds never share one: the installed app's is
/// ~/Library/Logs/ViewSwitcher/server.log; another build of the app (Debug's `.mac.dev`) gets its own
/// file beside it (server-dev.log); an end-to-end run writes into its own folder. Sharing one would
/// mix their lines in Show Server Log, and a run's capLog could start the installed app's log over.
public func serverLogFile(home: URL, bundleID: String?, e2eDir: URL?) -> URL {
if let e2eDir { return e2eDir.appendingPathComponent("server.log") }
let logs = home.appendingPathComponent("Library/Logs/ViewSwitcher")
guard let id = bundleID, id != releaseBundleID else { return logs.appendingPathComponent("server.log") }
let suffix = id.hasPrefix(releaseBundleID + ".") ? String(id.dropFirst(releaseBundleID.count + 1)) : id
let safe = suffix.map { $0.isLetter || $0.isNumber || $0 == "." || $0 == "-" ? $0 : "-" }
return logs.appendingPathComponent("server-\(String(safe)).log")
}

public enum ServerError: LocalizedError, Equatable {
case portTaken(String)
case startFailed(String)
Expand Down Expand Up @@ -245,8 +261,10 @@ func processFacts(_ pid: Int32) -> ProcessFacts? {
let size = Int32(MemoryLayout<proc_bsdinfo>.size)
guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, size) == size else { return nil }
var buf = [CChar](repeating: 0, count: Int(MAXPATHLEN) * 4)
guard proc_pidpath(pid, &buf, UInt32(buf.count)) > 0 else { return nil }
return ProcessFacts(path: String(cString: buf), uid: info.pbi_uid, ppid: info.pbi_ppid)
let length = proc_pidpath(pid, &buf, UInt32(buf.count))
guard length > 0 else { return nil }
let path = String(decoding: buf.prefix(Int(length)).map { UInt8(bitPattern: $0) }, as: UTF8.self)
return ProcessFacts(path: path, uid: info.pbi_uid, ppid: info.pbi_ppid)
}

/// Whether `pid` is a leftover of the server this app launches: that same executable, run by this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,18 @@ final class ServerControllerTests: XCTestCase {
capLog(log, max: 1000)
XCTAssertEqual(try Data(contentsOf: log).count, 0, "a big log starts over")
}

func testEachBuildHasItsOwnServerLog() {
let home = URL(fileURLWithPath: "/Users/someone")
let logs = "/Users/someone/Library/Logs/ViewSwitcher/"
XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: nil).path, logs + "server.log", "the installed app")
XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID + ".dev", e2eDir: nil).path, logs + "server-dev.log", "bun run mac:dev")
XCTAssertEqual(serverLogFile(home: home, bundleID: nil, e2eDir: nil).path, logs + "server.log")
XCTAssertEqual(serverLogFile(home: home, bundleID: "org.example/odd", e2eDir: nil).path, logs + "server-org.example-odd.log", "never a path out of the folder")
let e2e = URL(fileURLWithPath: "/tmp/vs-e2e-control")
XCTAssertEqual(serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: e2e).path, "/tmp/vs-e2e-control/server.log", "an end-to-end run, whatever its build")
let all = [serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: nil), serverLogFile(home: home, bundleID: releaseBundleID + ".dev", e2eDir: nil), serverLogFile(home: home, bundleID: releaseBundleID, e2eDir: e2e)]
XCTAssertEqual(Set(all).count, all.count)
}
}
#endif
11 changes: 11 additions & 0 deletions apps/apple/Mac/AdHoc.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- mac:build --unsigned only (scripts/build.sh). An ad hoc signature has no team, and the hardened
runtime's library validation refuses a framework (Sparkle) whose team doesn't match the app's,
so an ad hoc app on the runtime can't launch without this. A Developer ID build never has it. -->
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions apps/apple/Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}

func showLog() {
// A server this app attached to (bun run dev, another build's) writes its own log, not this
// build's: show the logs folder, where the installed app's and a Debug build's are, rather than a file it doesn't use.
if supervisor.state == .attached {
let folder = Env.logFile.deletingLastPathComponent()
try? FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
Outside.openFolder(folder)
return
}
capLog(Env.logFile)
if !FileManager.default.fileExists(atPath: Env.logFile.path) { FileManager.default.createFile(atPath: Env.logFile.path, contents: nil) }
Outside.openFolder(Env.logFile)
Expand Down
3 changes: 2 additions & 1 deletion apps/apple/Mac/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum Env {
static var e2e: Bool { e2eDir != nil }
static let updatesEnabled = vars["VIEWSWITCHER_UPDATES"] != "0"
static let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0"
static let logFile = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Logs/ViewSwitcher/server.log")
/// This build's own server log (serverLogFile): the installed app's, Debug's or an e2e run's.
static let logFile = serverLogFile(home: FileManager.default.homeDirectoryForCurrentUser, bundleID: Bundle.main.bundleIdentifier, e2eDir: e2eDir)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/// A new secret each launch, for the pairing endpoints only this app may call (apps/server: /api/remote…).
/// It goes to the server in its environment and never leaves this Mac.
static let adminToken: String = {
Expand Down
10 changes: 7 additions & 3 deletions apps/apple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ bun apps/apple/AppStore/check.ts # App Store listing lengths
Quit stops only a server it started. The server exits by itself if the app dies
(`VIEWSWITCHER_PARENT_PID`, `apps/server/src/parent-watch.ts`); an app relaunched before it has gone
finds it through `/api/info` (`sidecar`, `parentPid`, `pid`) and replaces it instead of attaching.
Server calls go through ViewSwitcherKit's `ServerAPI`. Its output goes to
`~/Library/Logs/ViewSwitcher/server.log`, restarted past 5 MB.
Server calls go through ViewSwitcherKit's `ServerAPI`. Its output goes to a log of
that build's own (Kit's `serverLogFile`), restarted past 5 MB: the installed app's is
`~/Library/Logs/ViewSwitcher/server.log`, a Debug build's (`bun run mac:dev`) `server-dev.log` beside it,
and an e2e run's `server.log` in its control folder. Show Server Log opens this build's (the logs folder while attached to a server it didn't start).
- `StatusMenuBuilder.swift`: the menu-bar menu, from ViewSwitcherKit's `StatusMenu` (what it lists for a state).
- Debug builds have their own bundle id, so `bun run mac:dev` runs beside an installed ViewSwitcher
(one at a time is per bundle id) with its own settings, login item and notification permission;
Expand Down Expand Up @@ -167,7 +169,9 @@ secure timestamp. `scripts/build.sh` checks all of it after the export.
| `Sparkle.framework` (Autoupdate, Updater.app, XPC services) | Sparkle's own | Signed by the Developer ID export. |

Not needed, so not granted: `allow-unsigned-executable-memory`, `disable-library-validation`,
`allow-dyld-environment-variables`, and no sandbox. The server reads the library folder the user picks,
`allow-dyld-environment-variables`, and no sandbox. One exception, never shipped: `mac:build --unsigned` signs the
app ad hoc with `Mac/AdHoc.entitlements` (`disable-library-validation`), because an ad hoc app has no team for
Sparkle's to match and the hardened runtime wouldn't load it; `build.sh` refuses a Developer ID build that carries it. The server reads the library folder the user picks,
spawns `open` and `git`, and talks to usbmuxd's socket for the iPad.

The sidecar is built with `bun build --compile` once for each architecture, merged with `lipo` into one
Expand Down
15 changes: 12 additions & 3 deletions apps/apple/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ lipo -archs "$PAYLOAD/viewswitcher-server"
step "ViewSwitcher.app (xcodebuild archive, Release, universal)"
xcodegen --quiet
rm -rf "$BUILD/ViewSwitcher.xcarchive" "$BUILD/export"
signing=(CODE_SIGN_IDENTITY="-" CODE_SIGN_STYLE=Manual)
# Ad hoc: on the hardened runtime like a release, with library validation off (Mac/AdHoc.entitlements),
# since an ad hoc app has no team for Sparkle's to match and couldn't launch otherwise. Merged onto the
# app's own entitlements, as the setting replaces them rather than adding to them.
ADHOC_ENT="$BUILD/adhoc.entitlements"
cp Mac/ViewSwitcher.entitlements "$ADHOC_ENT"
/usr/libexec/PlistBuddy -c "Merge Mac/AdHoc.entitlements" "$ADHOC_ENT" >/dev/null
signing=(CODE_SIGN_IDENTITY="-" CODE_SIGN_STYLE=Manual CODE_SIGN_ENTITLEMENTS="$ADHOC_ENT")
[ -n "$IDENTITY" ] && signing=(CODE_SIGN_IDENTITY="$IDENTITY" CODE_SIGN_STYLE=Manual DEVELOPMENT_TEAM="$TEAM")
xcodebuild -project ViewSwitcher.xcodeproj -scheme ViewSwitcher -configuration Release -derivedDataPath "$DD" \
-archivePath "$BUILD/ViewSwitcher.xcarchive" -destination "generic/platform=macOS" "${signing[@]}" -quiet archive
Expand Down Expand Up @@ -185,9 +191,12 @@ has() { local out; out="$("${@:2}" 2>&1 || true)"; [[ "$out" == *"$1"* ]]; }
has "x86_64 arm64" lipo -archs "$APP/Contents/MacOS/ViewSwitcher" || { echo "the app isn't universal" >&2; exit 1; }
has "x86_64 arm64" lipo -archs "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't universal" >&2; exit 1; }
has "com.apple.security.cs.allow-jit" codesign -d --entitlements - --xml "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar lost its allow-jit entitlement" >&2; exit 1; }
has "flags=0x10000(runtime)" codesign -dv "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't on the hardened runtime" >&2; exit 1; }
has "flags=0x10000(runtime)" codesign -dv "$APP" || { echo "the app isn't on the hardened runtime" >&2; exit 1; }
source "$APPLE/scripts/sign-check.sh"
hardened_runtime "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't on the hardened runtime" >&2; exit 1; }
hardened_runtime "$APP" || { echo "the app isn't on the hardened runtime" >&2; exit 1; }
if [ -n "$IDENTITY" ]; then
# Library validation stays on in anything Developer ID signed: only the ad hoc build turns it off.
has "disable-library-validation" codesign -d --entitlements - --xml "$APP" && { echo "the app turns off library validation (Mac/AdHoc.entitlements is for --unsigned only)" >&2; exit 1; }
has "TeamIdentifier=$TEAM" codesign -dv "$APP" || { echo "the app isn't signed by $TEAM" >&2; exit 1; }
has "TeamIdentifier=$TEAM" codesign -dv "$APP/Contents/Helpers/viewswitcher-server" || { echo "the sidecar isn't signed by $TEAM" >&2; exit 1; }
fi
Expand Down
9 changes: 9 additions & 0 deletions apps/apple/scripts/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ try {
const o = (await state()).opened;
return o.includes(`${BASE}/`) && o.some((p) => resolve(p) === resolve(library) || p.endsWith(library.split("/").pop()!));
}, 5000), "menu bar: Open in Browser and Open Library Folder");
// This run's server log is its own, never the installed app's (~/Library/Logs/ViewSwitcher/server.log).
const ownLog = join(control, "server.log");
check(existsSync(ownLog) && readFileSync(ownLog, "utf8").includes("[viewswitcher]"), "the server logs into this run's own folder");
await cmd("menu", { item: "Show Server Log" });
check(await until(async () => (await state()).opened.includes(ownLog), 5000), "Show Server Log opens this run's log");

// ------------------------------------------------------------ the page may change things; other sites may not
const fromPage = await evalJs<number>(`return (await fetch("/api/onair", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ path: ${JSON.stringify(orgScene)}, label: "Be right back" }) })).status`);
Expand Down Expand Up @@ -440,6 +445,10 @@ try {
check(await until(async () => (await state()).server?.owned === false), "the app attaches instead of starting another");
check(listeners().length === 1 && listeners()[0] === own.pid, "only that server listens");
check((await state()).menu.includes("Quit ViewSwitcher (server keeps running)"), "menu says Quit leaves it running");
// An attached server writes its own log, not this build's: Show Server Log opens the logs folder instead.
const openedBeforeLog = (await state()).opened.length;
await cmd("menu", { item: "Show Server Log" });
check(await until(async () => (await state()).opened.slice(openedBeforeLog).some((p) => resolve(p) === resolve(control)), 5000), "attached: Show Server Log opens the logs folder, not this build's log");
check(await quit(app), "Quit ends the app");
await sleep(800);
check(await answers(), "after Quit, the server it didn't start is still running");
Expand Down
11 changes: 11 additions & 0 deletions apps/apple/scripts/sign-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Checks build.sh runs on what it signed. Sourced; also sourced by sign-check.test.ts.

# Whether the code at <path> is signed for the hardened runtime: the runtime bit (0x10000) of its
# code directory's flags, whatever else is set beside it. A Developer ID signature reads
# flags=0x10000(runtime), an ad hoc one (mac:build --unsigned) flags=0x10002(adhoc,runtime).
hardened_runtime() {
local out flags
out="$(codesign -dv "$1" 2>&1 || true)"
flags="$(sed -n 's/.*CodeDirectory .*flags=0x\([0-9a-fA-F]*\).*/\1/p' <<<"$out" | head -1)"
[ -n "$flags" ] && (( (16#$flags & 16#10000) != 0 ))
}
34 changes: 34 additions & 0 deletions apps/apple/scripts/sign-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// sign-check.sh's hardened-runtime check on real code signatures (copies of /usr/bin/true, signed
// here), run through macOS's own bash (3.2), as build.sh runs it.
import { afterAll, describe, expect, test } from "bun:test";
import { copyFileSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

const check = join(import.meta.dir, "sign-check.sh");
const dir = mkdtempSync(join(tmpdir(), "vs-sign-"));
afterAll(() => rmSync(dir, { recursive: true, force: true }));
const canSign = process.platform === "darwin" && Bun.which("codesign") !== null;

/** A copy of /usr/bin/true signed ad hoc with `options`; its path. */
function signed(name: string, options: string[]) {
const path = join(dir, name);
copyFileSync("/usr/bin/true", path);
const r = Bun.spawnSync(["codesign", "--force", ...options, "--sign", "-", path]);
if (r.exitCode !== 0) throw new Error(r.stderr.toString());
return path;
}
const hardened = (path: string) => Bun.spawnSync(["/bin/bash", "-c", `source "${check}"; hardened_runtime "$1"`, "_", path]).exitCode === 0;

describe.skipIf(!canSign)("hardened_runtime", () => {
test("an ad hoc signature on the hardened runtime (mac:build --unsigned) passes", () => {
expect(hardened(signed("adhoc-runtime", ["--options", "runtime"]))).toBe(true);
});
test("a signature without the runtime fails, and so does unsigned or missing code", () => {
expect(hardened(signed("adhoc", []))).toBe(false);
expect(hardened(join(dir, "nothing-here"))).toBe(false);
const plain = join(dir, "plain.txt");
writeFileSync(plain, "not code");
expect(hardened(plain)).toBe(false);
});
});
7 changes: 7 additions & 0 deletions apps/server/src/agent-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ describe("agentGuard", () => {
expect(agentGuard({ setting: "not-live", live: false, onAir: partial, action: write("daisy/assets/anything.png") }).ok).toBe(true);
expect(agentGuard({ setting: "always", live: true, onAir: partial, action: write("daisy/assets/anything.png") }).ok).toBe(true);
});
test("when the view on air loads a file the scan couldn't read, every write is refused while live, naming that file", () => {
const blind = { ...onAir, loadsUnreadable: ["daisy/templates/_shared/linked.css"] };
const g = agentGuard({ setting: "not-live", live: true, onAir: blind, action: write("daisy/assets/anything.png") });
expect(g.ok).toBe(false);
expect(g.ok ? "" : g.reason).toContain("loads daisy/templates/_shared/linked.css, which ViewSwitcher couldn't read just now");
expect(agentGuard({ setting: "not-live", live: false, onAir: blind, action: write("daisy/assets/anything.png") }).ok).toBe(true);
});
test("a template set's view on air: its set's transition and _shared/ are on stream, another set's aren't", () => {
const setView = { path: "daisy/templates/neon/brb.html", transition: "daisy/templates/neon/_shared/transition.html" };
const ok = (path: string) => agentGuard({ setting: "not-live", live: true, onAir: setView, action: write(path) }).ok;
Expand Down
15 changes: 11 additions & 4 deletions apps/server/src/agent-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type GuardInput = {
* The scene on air, the transition that plays for it, and the library files those load (their
* stylesheets, scripts, pictures, video, fonts: scene-refs.ts loadedFiles).
*/
onAir: { path: string; transition?: string | null; loads?: string[]; loadsComplete?: boolean } | null;
onAir: { path: string; transition?: string | null; loads?: string[]; loadsComplete?: boolean; loadsUnreadable?: string[] } | null;
action: GuardAction;
};

Expand All @@ -24,7 +24,7 @@ export type GuardResult = { ok: true } | { ok: false; reason: string };
* org's shared files, and anything else those load. Compared without case, as the Mac's disk does
* ("Templates/_Shared" is the same folder).
*/
function onStream(onAir: NonNullable<GuardInput["onAir"]>, path: string): "scene" | "transition" | "shared" | "loaded" | "tooMany" | null {
function onStream(onAir: NonNullable<GuardInput["onAir"]>, path: string): "scene" | "transition" | "shared" | "loaded" | "tooMany" | "unreadable" | null {
const p = path.toLowerCase();
const scene = onAir.path.toLowerCase();
if (p === scene) return "scene";
Expand All @@ -36,10 +36,14 @@ function onStream(onAir: NonNullable<GuardInput["onAir"]>, path: string): "scene
if (onAir.loads?.some((l) => l.toLowerCase() === p)) return "loaded";
// The scan of what the scene loads stopped at its limit: anything might be on stream.
if (onAir.loadsComplete === false) return "tooMany";
// It loads a file the scan couldn't read: what that loads is unknown, so anything might be.
if (onAir.loadsUnreadable?.length) return "unreadable";
return null;
}

const REASONS = {
const REASONS: Record<Exclude<ReturnType<typeof onStream>, null>, string | ((onAir: NonNullable<GuardInput["onAir"]>) => string)> = {
unreadable: (onAir) =>
`The view on air loads ${onAir.loadsUnreadable!.slice(0, 3).join(", ")}, which ViewSwitcher couldn't read just now (a disk error, or the file changed while it was checked), so it can't tell what that file loads, and while you're live agents can't change library files. Check that file, or wait until you're off air.`,
scene: "That view is on air and you're live. Make a stream copy with customize_scene (or duplicate_scene) and change that, or wait until you're off air (OBS stops streaming and recording).",
transition: "That is the transition for the view on air, and you're live. Wait until you're off air to change it.",
shared: "Files in templates/_shared/ (and a template set's own _shared/) shape the view on air, and you're live. Wait until you're off air, or put the change in a stream copy of the view (customize_scene).",
Expand All @@ -57,7 +61,10 @@ export function agentGuard({ setting, live, onAir, action }: GuardInput): GuardR
if (!live || !onAir) return { ok: true };
for (const p of action.paths) {
const hit = onStream(onAir, p);
if (hit) return { ok: false, reason: REASONS[hit] };
if (hit) {
const reason = REASONS[hit];
return { ok: false, reason: typeof reason === "string" ? reason : reason(onAir) };
}
}
return { ok: true };
}
Loading
Loading