Files
Juan Fernando CastroandDaniel Salazar 768b52c10e refactor(push): push database and key names are written once, and the desktop reads its push record through puter.js (#4653)
* refactor(push): the database and key names are written once for the page and both workers

pushNames.js holds the puter-push database name, its stores, key prefixes
and the subscription-changed message. pushStore.js re-exports them.

push-sw.js and the GUI's sw.js are served as they are (push-sw.js also
from npm's src/), so neither can import the module. Each carries a block
generated from pushNames.js by tools/pushWorkerNames.mjs. The puter.js
webpack build and the GUI build fail while either block is stale, and a
test compares the names in both worker sources with the page module's.

* refactor(push): the desktop reads the confirmed endpoint and the mark through puter.js

puter.js now records the endpoint the server confirmed, and clears the
subscription-changed mark, inside the Puter GUI as on a website. Three
internal methods give the desktop what it kept itself: _webPushRecord()
reads both, _noteWebPushSynced() records an endpoint a status check
confirmed, and _dropRemovedWebPush() ends a removed subscription and
forgets its receipt and the mark.

webPushClient.js no longer opens the puter-push database or keeps its
own localStorage record. An endpoint an earlier build kept there is read
while puter.js has none, and removed once puter.js records one, so an
already synced browser keeps its status without registering again. With
a puter.js that lacks the methods, the client reads nothing from it and
keeps the old record.

* refactor(push): one-line comments on the push names and the record methods

* fix(push): the worker names check reads CRLF checkouts, lives in tools/ and runs in PR CI

The block helper moves to tools/pushNamesBlock.mjs, so it isn't part of
the published puter.js sources. It compares and rewrites on LF text and
writes back the file's own line endings. Both workers are pinned to LF
in .gitattributes. The puter.js tests run when the GUI's sw.js or its
build changes, and the GUI build checks sw.js before anything else.

* fix(push): the desktop keeps a removed browser off with a puter.js that has no push record

The desktop loads puter.js from its own URL, so it can run one without
_webPushRecord(). The client then uses pushStore.js's helpers itself: it
reads and clears the subscription-changed mark, ends a removed
subscription and forgets its receipt and the mark, clears the mark after
enable(), and keeps the confirmed endpoint in localStorage as before.

_noteWebPushSynced() resolves whether it recorded the endpoint, and the
localStorage endpoint is removed only after puter.js has it. A cached
status reads only the mark before answering. The accessors carry JSDoc
types.

* fix(push): the removed-elsewhere check also asks about the endpoint in localStorage

When loads alternate between puter.js versions, localStorage can hold a
newer confirmed endpoint than puter.js does. The background check now
asks about both, with the mark's old endpoint, before registering.

* fix(push): with an older puter.js the desktop also asks about the endpoint puter.js recorded

Once puter.js has recorded the confirmed endpoint, the desktop drops its
localStorage copy. A later load that runs an older puter.js then read
neither, so a browser that lost its subscription after being removed in
Puter could register again. The fallback now reads puter.js's record from
the store directly.

* refactor(puter-js): the push record reads use try/catch instead of .catch()

---------

Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
2026-11-16 09:06:23 -07:00
..