Patch headers and comments: concise

Document the patch calling convention once in lib/default.nix; patch
headers say what, target, hook, state and contracts. Comments only, no
code changes.
This commit is contained in:
Pierre Kisters committed 2026-09-27 23:57:50 +02:00
1 parent 4bb0fdd863
commit 4c843c3ce4
22 files changed
+346 -553

No files matched your search

+21 -11
View File
@@ -1,13 +1,23 @@
# Shared helpers of the runtime Steam UI patches.
# - finders.js: signature-based lookup of webpack modules/exports and React
# fibers (no module ids or minified names);
# - signatures.json: the signatures the patches use, per patch, also read by
# Shared helpers of the runtime Steam UI patches:
# - finders.js: signature-based lookup of webpack modules/exports and fibers;
# - signatures.json: per-patch signatures, also read by
# scripts/check-signatures.mjs (run it after a Steam update);
# - hooks.js: shared method hooks (one wrapper per method for all patches,
# e.g. the SteamVR dashboard mailbox's SendMessage);
# - mkPatch: turns a patch written as a function expression
# `(find, sigs, opts, hooks) => …` into the single expression the injectors
# evaluate: (<patch>)(<finders.js>, <signatures>, <opts>, <hooks.js>).
# - hooks.js: one shared wrapper per hooked method (e.g. SendMessage);
# - mkPatch: builds the expression the injector evaluates.
#
# Patch convention: a patch file is a function expression
# (find, sigs, opts, hooks) => <status string or Promise of one>
# (trailing parameters may be omitted), called as
# (<patch>)(<finders.js>, <signatures>, <opts>, <hooks.js>)
# with find = lib/finders.js, sigs = its module signatures, opts = the JSON
# options from its module, hooks = lib/hooks.js. The injector re-evaluates it
# on every new JS context and periodically, so it must be idempotent: keep
# state on a window.__sfui* global (or on the wrapped function), return
# "unchanged" when already applied (not logged) and tear down/re-apply when
# its VERSION or options differ. Bump VERSION whenever the patch code changes.
# A matching unpatch.js (plain expression) reverts it when the service stops.
# Patches needing none of the arguments may be plain expressions without
# mkPatch (e.g. launcher-menu/order).
{ pkgs }:
let
sigFile = builtins.fromJSON (builtins.readFile ./signatures.json);
@@ -17,8 +27,8 @@ in {
hooks = ./hooks.js;
# name: file name (and default signatures entry); src: the patch file;
# signatures: module signatures passed as `sigs` (default: the entry `name`
# of signatures.json, else none); opts: JSON-serialisable options.
# signatures: `sigs` (default: signatures.json entry `name`, else none);
# opts: JSON-serialisable options.
mkPatch = { name, src, signatures ? sigFile.patches.${name}.modules or { }, opts ? { } }:
pkgs.writeText "${name}.js" ''
(${builtins.readFile src}