@unisim/sdk 0.227.0 → 0.229.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -5
- package/dist/Selection.d.ts +19 -3
- package/dist/Selection.d.ts.map +1 -1
- package/dist/Selection.js +10 -5
- package/dist/Selection.js.map +1 -1
- package/dist/TuneSync.d.ts +2 -0
- package/dist/TuneSync.d.ts.map +1 -0
- package/dist/TuneSync.js +182 -0
- package/dist/TuneSync.js.map +1 -0
- package/dist/defaultView.d.ts +11 -0
- package/dist/defaultView.d.ts.map +1 -1
- package/dist/defaultView.js +69 -12
- package/dist/defaultView.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +10 -2
- package/dist/provider.js.map +1 -1
- package/dist/selectionCopy.d.ts +10 -0
- package/dist/selectionCopy.d.ts.map +1 -1
- package/dist/selectionCopy.js +24 -0
- package/dist/selectionCopy.js.map +1 -1
- package/dist/themeStore.d.ts +8 -0
- package/dist/themeStore.d.ts.map +1 -1
- package/dist/themeStore.js +21 -1
- package/dist/themeStore.js.map +1 -1
- package/dist/tuneSyncCore.d.ts +52 -0
- package/dist/tuneSyncCore.d.ts.map +1 -0
- package/dist/tuneSyncCore.js +162 -0
- package/dist/tuneSyncCore.js.map +1 -0
- package/dist/userPrefs.d.ts.map +1 -1
- package/dist/userPrefs.js +28 -15
- package/dist/userPrefs.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -425,12 +425,65 @@ preferences** that each app can override.
|
|
|
425
425
|
(migration 0151) holds `{ language, colorScheme }`. On sign-in the row wins and is applied
|
|
426
426
|
without being written back; with no row, one is seeded **only** from values this device
|
|
427
427
|
explicitly stored (never defaults or the browser locale); every global change upserts the
|
|
428
|
-
pair. Fire-and-forget and silent on failure; skipped in mock mode. App overrides are
|
|
429
|
-
|
|
428
|
+
pair. Fire-and-forget and silent on failure; skipped in mock mode. App overrides are not part
|
|
429
|
+
of this row; since 0.229.0 they sync through the app's own row (next section). ⚠️ This deliberately lets a signed-in person's language cross between the Universal
|
|
430
430
|
Apps and Assess — the separation below exists for anonymous visitors on a shared machine,
|
|
431
431
|
which a row keyed on the user's id cannot affect.
|
|
432
432
|
- `npm run test:preferences` (51 checks) and `npm run test:profile-menu-order` (53).
|
|
433
433
|
|
|
434
|
+
### Tune this app follows the account (since 0.229.0)
|
|
435
|
+
|
|
436
|
+
James, 2026-10-30: *"mobile app and web app settings in tune this app should be saved and synced
|
|
437
|
+
to their account … Global rule"*; and 2026-10-26: *"if the person changed any tuning before signing
|
|
438
|
+
in, save it for that app on their profile; if they changed nothing, import their Global Tuning"*.
|
|
439
|
+
|
|
440
|
+
**Every app gets it by bumping the SDK; there's no app code.** `<UniversalProvider>` renders a
|
|
441
|
+
`TuneSync` itself (not in mock mode).
|
|
442
|
+
|
|
443
|
+
- **What syncs, per app:** the app's colour-scheme override (its `createThemeStore`), its language
|
|
444
|
+
override (`setAppLanguage`), and every default view (`useDefaultView` / `<DefaultViewSelect>`).
|
|
445
|
+
The app's own Tune rows aren't included yet; that's phase 2's `createSyncedSettings`.
|
|
446
|
+
- **Where:** its own `user_app_prefs` row, `app = 'tune:<product>'`, with
|
|
447
|
+
`data = { at, colorScheme, language, views }` and nothing else. ⚠️ It isn't a key in the app's
|
|
448
|
+
`<product>` row, because that row belongs to `useUserPrefs`, and every version of `useUserPrefs`
|
|
449
|
+
upserts its whole bag. A phone build one version behind the website would wipe the key. "Call me"
|
|
450
|
+
has its own row for the same reason. No migration: `app` is free text (0151), and the stamp sits
|
|
451
|
+
inside `data`.
|
|
452
|
+
- **The rules** (`tuneSyncCore.ts`):
|
|
453
|
+
- Signed in means synced. Signed out, or an anonymous trial, means this device only.
|
|
454
|
+
- **One stamp per app.** Any change to the three stamps the whole set, and the newer set wins.
|
|
455
|
+
Two devices never merge field by field. A change is pushed about 60 ms after it is made, so a
|
|
456
|
+
Reset to defaults that clears all three is one write. The row is read on sign-in and again
|
|
457
|
+
on resume (throttled to 30 s, like Global Tuning).
|
|
458
|
+
- **A device that never changed anything says nothing.** It has no stamp, so it takes the
|
|
459
|
+
account's set if there is one and never writes its own. Picking the value already there is
|
|
460
|
+
not a change.
|
|
461
|
+
- **A guest's change wins on sign-in.** A change made signed out is stamped as the guest's, and
|
|
462
|
+
when a session arrives (signed in here, or recognised through the shared cookie) it is saved
|
|
463
|
+
for that app on the profile, even over a newer row. The guest's global language or colour
|
|
464
|
+
scheme becomes the app's override on sign-in (0.207.0), and that conversion is saved the same
|
|
465
|
+
way. A guest who changed nothing gets the account's app set and its Global Tuning.
|
|
466
|
+
- **On a shared device, another account's stamp counts as no stamp** (`uid` in the device's
|
|
467
|
+
stamp), so one person's look is never pushed onto the next person's row.
|
|
468
|
+
- **Reset to defaults** is a change like any other: the empty set goes up, and the account's
|
|
469
|
+
other devices follow.
|
|
470
|
+
- Fire-and-forget and silent on failure. A failed write leaves this device newer than the row,
|
|
471
|
+
so the next pull writes it again.
|
|
472
|
+
- **Device storage:** the values stay where they were (table above, and
|
|
473
|
+
`unisim:default-view:<product>:<id>`), so apps still read them synchronously. The stamp is
|
|
474
|
+
localStorage `unisim:tune-stamp:<product>` = `{ at, uid } | { at, guest: true }`.
|
|
475
|
+
- ⚠️ **No stamp means existing choices stay on their device.** An override chosen before 0.229.0
|
|
476
|
+
isn't pushed until it's changed again. If the account already has a row, that row replaces it.
|
|
477
|
+
- **An app that synced its look itself** (BlackBook's `useTuneLook`, until 0.229.0) should drop
|
|
478
|
+
that, or the look syncs twice.
|
|
479
|
+
- **`useUserPrefs.setPref` writes in the caller's event (fixed 0.229.0).** It used to write inside
|
|
480
|
+
a state updater. React runs a queued updater only when it next renders the component, so a sheet
|
|
481
|
+
that closed on pick (after a state update of its own) dropped the pick, on the device and on the
|
|
482
|
+
account.
|
|
483
|
+
- `npm run test:tune-sync`: 21 rule checks plus 31 in a browser. `test:guest-tuning` and
|
|
484
|
+
`test:preferences` now expect a guest's tuning, and an app override, to reach the app's tune row
|
|
485
|
+
(never the `suite` row).
|
|
486
|
+
|
|
434
487
|
### One app: no Global Tuning (since 0.144.0)
|
|
435
488
|
James, 2026-09-17: *"start with app and show global once they start using a second app, or if
|
|
436
489
|
they are part of an enterprise? It's kinda pointless if they only use one app"*.
|
|
@@ -486,8 +539,9 @@ should have a reset defaults button."* Universal Jukebox's library tabs are the
|
|
|
486
539
|
- **`<DefaultViewSelect id label fallback views />`** — the same choice as a Tune this app row,
|
|
487
540
|
for anybody who can't double-tap. Pass it in `appPreferences`. It follows the dialog's
|
|
488
541
|
colourway (`PreferencesThemeContext`).
|
|
489
|
-
- **Storage:** localStorage `unisim:default-view:<config.product>:<id>`.
|
|
490
|
-
|
|
542
|
+
- **Storage:** localStorage `unisim:default-view:<config.product>:<id>`. Since 0.229.0 it also
|
|
543
|
+
follows a signed-in account, in the app's `tune:<product>` row (see "Tune this app follows the
|
|
544
|
+
account"); before that it was per device. `readDefaultView(product, id)` / `writeDefaultView(...)` are for
|
|
491
545
|
a store that needs the value outside React, such as a zustand store's initial state.
|
|
492
546
|
- **Reset to defaults is in EVERY Tune this app now.** Before 0.170.0 it showed only when the app
|
|
493
547
|
passed `onResetDefaults`. The SDK's part of the reset always runs:
|
|
@@ -525,7 +579,8 @@ Universal BlackBook; `npm run test:growing-textarea` checks it in Chromium.
|
|
|
525
579
|
|
|
526
580
|
The suite rule for lists (James, 2026-10-30; `Docs_UNI_SIM/new-universal-app.md` §2): every
|
|
527
581
|
list of things a person made has a tick box per row, **Select all**, and once something is
|
|
528
|
-
ticked the count, **Delete selected** (asks first, says how many
|
|
582
|
+
ticked the count, **Delete selected** (asks first, says how many; **Remove selected** with
|
|
583
|
+
`action="remove"`) and **Clear**. The bar stays
|
|
529
584
|
out of the way until something is ticked, and hides while the list is empty.
|
|
530
585
|
|
|
531
586
|
```tsx
|
|
@@ -566,6 +621,16 @@ const sel = useSelection(rows.map((r) => r.id))
|
|
|
566
621
|
default, dark under a `dark` / `data-theme="dark"` / `data-u-ground="dark"` ancestor. The
|
|
567
622
|
layout is layered like the buttons, so Tailwind utilities on the bar (`ml-auto`) win.
|
|
568
623
|
`SELECTION_CSS` is the sheet for a page with no build step.
|
|
624
|
+
- **Remove, not delete (since 0.228.0):** where the rows only leave this list and the things
|
|
625
|
+
themselves stay — recent files, songs taken out of a library, tracks taken off a shelf —
|
|
626
|
+
pass `action="remove"`. The button says **Remove selected** (secondary rank, a minus icon,
|
|
627
|
+
not red), the confirm "Remove 3 files from this list?" with no "cannot be undone", and the
|
|
628
|
+
phone sheet's button is a plain **Remove**. `onDelete` is still the callback. Pick by what
|
|
629
|
+
the action really does: if the thing is gone afterwards, it is Delete.
|
|
630
|
+
|
|
631
|
+
```tsx
|
|
632
|
+
<SelectionBar sel={sel} action="remove" noun={{ one: 'file', other: 'files' }} onDelete={(ids) => forgetRecents(ids)} />
|
|
633
|
+
```
|
|
569
634
|
- Lifted from Universal Invoices; `npm run test:selection` checks it in Chromium.
|
|
570
635
|
|
|
571
636
|
### New features: a one-time sheet with their switches (since 0.202.0)
|
package/dist/Selection.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface SelectCheckboxProps {
|
|
|
47
47
|
* beside) a row that opens on click.
|
|
48
48
|
*/
|
|
49
49
|
export declare function SelectCheckbox({ checked, onChange, label, indeterminate, disabled, className, id }: SelectCheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
/** What <SelectionBar>'s main action does: destroys the rows, or only takes them off this list. */
|
|
51
|
+
export type SelectionAction = 'delete' | 'remove';
|
|
50
52
|
/** The noun for the confirm: `{ one, other }`, already in the app's language. */
|
|
51
53
|
export type SelectionNoun = string | {
|
|
52
54
|
one: string;
|
|
@@ -55,8 +57,21 @@ export type SelectionNoun = string | {
|
|
|
55
57
|
export interface SelectionBarProps {
|
|
56
58
|
/** From {@link useSelection}. */
|
|
57
59
|
sel: ListSelection;
|
|
58
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Deletes the ticked rows (or, with `action="remove"`, takes them off the
|
|
62
|
+
* list); called after the person confirms. The selection clears once it
|
|
63
|
+
* resolves.
|
|
64
|
+
*/
|
|
59
65
|
onDelete: (ids: string[]) => void | Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* What the bar's main action does to the ticked rows. `'delete'` (default):
|
|
68
|
+
* **Delete selected**, Danger rank, "Delete 3 documents? This cannot be
|
|
69
|
+
* undone." `'remove'` (0.228.0): the rows leave this list but the things
|
|
70
|
+
* themselves stay — recent files, songs taken out of a library, tracks taken
|
|
71
|
+
* off a shelf: **Remove selected**, a secondary button, "Remove 3 files from
|
|
72
|
+
* this list?" with a plain (not red) confirm.
|
|
73
|
+
*/
|
|
74
|
+
action?: SelectionAction;
|
|
60
75
|
/**
|
|
61
76
|
* What a row is, for the confirm: "Delete 3 documents?". `{ one, other }`
|
|
62
77
|
* in the app's language; a plain string is pluralised the English way
|
|
@@ -85,8 +100,9 @@ export interface SelectionBarProps {
|
|
|
85
100
|
}
|
|
86
101
|
/**
|
|
87
102
|
* "Select all" always (so a long list can be emptied in two clicks); the
|
|
88
|
-
* count, Delete selected
|
|
103
|
+
* count, Delete selected (or Remove selected, `action="remove"`) and Clear
|
|
104
|
+
* once something is ticked. Renders nothing
|
|
89
105
|
* while the list is empty.
|
|
90
106
|
*/
|
|
91
|
-
export declare function SelectionBar({ sel, onDelete, noun, onDuplicate, onExport, extra, confirm, total, size, language, className, }: SelectionBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
107
|
+
export declare function SelectionBar({ sel, onDelete, action, noun, onDuplicate, onExport, extra, confirm, total, size, language, className, }: SelectionBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
92
108
|
//# sourceMappingURL=Selection.d.ts.map
|
package/dist/Selection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAA;IAClD,4GAA4G;IAC5G,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACxE,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,uCAAuC;IACvC,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAeD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,QAAQ,EACR,MAAiB,EACjB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,KAAK,EACL,OAAO,EACP,KAAiB,EACjB,IAAW,EACX,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,kDAyEnB"}
|
package/dist/Selection.js
CHANGED
|
@@ -80,13 +80,15 @@ export function SelectCheckbox({ checked, onChange, label, indeterminate = false
|
|
|
80
80
|
}
|
|
81
81
|
/** English plurals, for a noun passed as a plain string: "company" → "companies". */
|
|
82
82
|
const englishPlural = (noun) => (/[^aeiou]y$/.test(noun) ? `${noun.slice(0, -1)}ies` : `${noun}s`);
|
|
83
|
+
const MinusIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: [_jsx("circle", { cx: "12", cy: "12", r: "9" }), _jsx("path", { d: "M8 12h8" })] }));
|
|
83
84
|
const BinIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: _jsx("path", { d: "M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3" }) }));
|
|
84
85
|
/**
|
|
85
86
|
* "Select all" always (so a long list can be emptied in two clicks); the
|
|
86
|
-
* count, Delete selected
|
|
87
|
+
* count, Delete selected (or Remove selected, `action="remove"`) and Clear
|
|
88
|
+
* once something is ticked. Renders nothing
|
|
87
89
|
* while the list is empty.
|
|
88
90
|
*/
|
|
89
|
-
export function SelectionBar({ sel, onDelete, noun, onDuplicate, onExport, extra, confirm, total = sel.total, size = 'sm', language, className, }) {
|
|
91
|
+
export function SelectionBar({ sel, onDelete, action = 'delete', noun, onDuplicate, onExport, extra, confirm, total = sel.total, size = 'sm', language, className, }) {
|
|
90
92
|
useSelectionStyles();
|
|
91
93
|
const fromProvider = useOptionalLanguage();
|
|
92
94
|
const lang = language ?? fromProvider ?? (typeof document !== 'undefined' ? document.documentElement.lang || null : null);
|
|
@@ -120,11 +122,14 @@ export function SelectionBar({ sel, onDelete, noun, onDuplicate, onExport, extra
|
|
|
120
122
|
const remove = async () => {
|
|
121
123
|
if (busy)
|
|
122
124
|
return;
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
+
const removing = action === 'remove';
|
|
126
|
+
const message = (removing ? copy.confirmRemove : copy.confirmDelete).replace('{count}', String(n)).replace('{noun}', nounFor(n));
|
|
127
|
+
const ok = confirm
|
|
128
|
+
? await confirm(message, n)
|
|
129
|
+
: await phoneConfirm({ message, confirmLabel: removing ? copy.removeButton : copy.confirmButton, danger: !removing });
|
|
125
130
|
if (ok)
|
|
126
131
|
await run(() => onDelete(ids()), true);
|
|
127
132
|
};
|
|
128
|
-
return (_jsxs("div", { className: cx('u-sel-bar', className), children: [_jsxs("label", { className: "u-sel-all", children: [_jsx(SelectCheckbox, { checked: sel.all, indeterminate: sel.some, onChange: sel.toggleAll, label: copy.selectAll }), _jsx("span", { "aria-live": "polite", children: n ? copy.selected.replace('{count}', String(n)) : copy.selectAll })] }), n > 0 && (_jsxs(_Fragment, { children: [_jsx(Button, { rank: "danger", size: size, icon: _jsx(BinIcon, {}), disabled: busy, onClick: () => void remove(), children: copy.deleteSelected }), onDuplicate && (_jsx(Button, { size: size, disabled: busy, onClick: () => void run(() => onDuplicate(ids()), true), children: copy.duplicate })), onExport && (_jsx(Button, { size: size, disabled: busy, onClick: () => void run(() => onExport(ids()), false), children: copy.exportSpreadsheet })), extra, _jsx(Button, { size: size, disabled: busy, onClick: sel.clear, children: copy.clear })] }))] }));
|
|
133
|
+
return (_jsxs("div", { className: cx('u-sel-bar', className), children: [_jsxs("label", { className: "u-sel-all", children: [_jsx(SelectCheckbox, { checked: sel.all, indeterminate: sel.some, onChange: sel.toggleAll, label: copy.selectAll }), _jsx("span", { "aria-live": "polite", children: n ? copy.selected.replace('{count}', String(n)) : copy.selectAll })] }), n > 0 && (_jsxs(_Fragment, { children: [action === 'remove' ? (_jsx(Button, { size: size, icon: _jsx(MinusIcon, {}), className: "u-sel-act u-sel-act--remove", disabled: busy, onClick: () => void remove(), children: copy.removeSelected })) : (_jsx(Button, { rank: "danger", size: size, icon: _jsx(BinIcon, {}), className: "u-sel-act", disabled: busy, onClick: () => void remove(), children: copy.deleteSelected })), onDuplicate && (_jsx(Button, { size: size, disabled: busy, onClick: () => void run(() => onDuplicate(ids()), true), children: copy.duplicate })), onExport && (_jsx(Button, { size: size, disabled: busy, onClick: () => void run(() => onExport(ids()), false), children: copy.exportSpreadsheet })), extra, _jsx(Button, { size: size, disabled: busy, onClick: sel.clear, children: copy.clear })] }))] }));
|
|
129
134
|
}
|
|
130
135
|
//# sourceMappingURL=Selection.js.map
|
package/dist/Selection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Selection.js","sourceRoot":"","sources":["../src/Selection.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChG,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,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AI,CACd,KAAC,MAAM,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,YACxF,IAAI,CAAC,SAAS,GACR,CACV,EACA,QAAQ,IAAI,CACX,KAAC,MAAM,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,YACtF,IAAI,CAAC,iBAAiB,GAChB,CACV,EACA,KAAK,EACN,KAAC,MAAM,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,YACnD,IAAI,CAAC,KAAK,GACJ,IACR,CACJ,IACG,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TuneSync.d.ts","sourceRoot":"","sources":["../src/TuneSync.tsx"],"names":[],"mappings":"AAgDA,wBAAgB,QAAQ,IAAI,IAAI,CAqI/B"}
|
package/dist/TuneSync.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// Tune this app follows the account (since 0.229.0). The rules are in
|
|
3
|
+
// tuneSyncCore.ts; this applies them for the provider's app. Rendered by
|
|
4
|
+
// <UniversalProvider> itself (not in mock mode), so every app gets it by
|
|
5
|
+
// bumping the SDK — no app code.
|
|
6
|
+
//
|
|
7
|
+
// • A change on this device (theme store override, app language override,
|
|
8
|
+
// a default view) is stamped at once; signed in, it is pushed a moment
|
|
9
|
+
// later (one write for a Reset to defaults that clears all three).
|
|
10
|
+
// • When a session arrives, and again on resume (throttled like the Global
|
|
11
|
+
// Tuning pull), the app's `tune:<product>` row is read and the newer side
|
|
12
|
+
// wins: the row is applied here, or this device's set is written to it.
|
|
13
|
+
// • A guest's change (made signed out) is written to the row on sign-in.
|
|
14
|
+
//
|
|
15
|
+
// ⚠️ Fire-and-forget and silent, like the Global Tuning row: offline, an RLS
|
|
16
|
+
// refusal or a self-hosted fork without the table cost the sync and nothing
|
|
17
|
+
// else. A failed write leaves this device's stamp newer than the row, so the
|
|
18
|
+
// next pull writes it again.
|
|
19
|
+
//
|
|
20
|
+
// ⚠️ Rendered BEFORE the provider's children, and child effects run before a
|
|
21
|
+
// parent's: the change listener is in place before the provider's guest-
|
|
22
|
+
// adoption effect (GUEST_TUNED_PREFIX) turns a guest's global choice into this
|
|
23
|
+
// app's override, so that adoption is stamped and saved like any change.
|
|
24
|
+
import { useEffect, useRef, useState } from 'react';
|
|
25
|
+
import { appLanguageKey, useUniversal } from './provider.js';
|
|
26
|
+
import { readAllDefaultViews, replaceDefaultViews } from './defaultView.js';
|
|
27
|
+
import { readAppColorSchemeOverride, setAppColorSchemeOverride } from './themeStore.js';
|
|
28
|
+
import { resolveLanguage } from './i18n.js';
|
|
29
|
+
import { decideTuneSync, normaliseViews, onTuneChange, parseTuneRow, quietly, readTuneStamp, tuneRowApp, writeTuneStamp, } from './tuneSyncCore.js';
|
|
30
|
+
/** At most one re-read of the row per this long, on resume. */
|
|
31
|
+
const RESUME_THROTTLE_MS = 30_000;
|
|
32
|
+
/** Changes closer together than this go up as one write. */
|
|
33
|
+
const PUSH_DELAY_MS = 60;
|
|
34
|
+
export function TuneSync() {
|
|
35
|
+
const { supabase, session, config, setAppLanguage } = useUniversal();
|
|
36
|
+
const product = config.product;
|
|
37
|
+
// A person, not an anonymous trial: signed in = synced.
|
|
38
|
+
const user = session?.user;
|
|
39
|
+
const uid = user && !user.is_anonymous ? user.id : null;
|
|
40
|
+
const live = useRef({ supabase, product, uid, setAppLanguage });
|
|
41
|
+
live.current = { supabase, product, uid, setAppLanguage };
|
|
42
|
+
// The last row seen: its colour scheme is carried on a page with no theme
|
|
43
|
+
// store, which has none of its own to report.
|
|
44
|
+
const lastRow = useRef(null);
|
|
45
|
+
const timer = useRef(null);
|
|
46
|
+
// The set this page last wrote (`uid:at`), so a pull that lands just after
|
|
47
|
+
// a change's own write does not send it again. A new page retries.
|
|
48
|
+
const sent = useRef(null);
|
|
49
|
+
const snapshot = () => {
|
|
50
|
+
const { product } = live.current;
|
|
51
|
+
const scheme = readAppColorSchemeOverride();
|
|
52
|
+
let language = null;
|
|
53
|
+
try {
|
|
54
|
+
language = resolveLanguage(window.localStorage.getItem(appLanguageKey(product)));
|
|
55
|
+
}
|
|
56
|
+
catch { /* ignore */ }
|
|
57
|
+
return {
|
|
58
|
+
colorScheme: scheme === undefined ? (lastRow.current?.colorScheme ?? null) : scheme,
|
|
59
|
+
language,
|
|
60
|
+
views: normaliseViews(readAllDefaultViews(product)),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const push = (at) => {
|
|
64
|
+
const { supabase, product, uid } = live.current;
|
|
65
|
+
if (!uid)
|
|
66
|
+
return;
|
|
67
|
+
const data = { at, ...snapshot() };
|
|
68
|
+
lastRow.current = data;
|
|
69
|
+
sent.current = `${uid}:${at}`;
|
|
70
|
+
writeTuneStamp(product, { at, uid });
|
|
71
|
+
try {
|
|
72
|
+
void supabase
|
|
73
|
+
.from('user_app_prefs')
|
|
74
|
+
.upsert({ user_id: uid, app: tuneRowApp(product), data }, { onConflict: 'user_id,app' })
|
|
75
|
+
.then(() => { }, () => { });
|
|
76
|
+
}
|
|
77
|
+
catch { /* see the header */ }
|
|
78
|
+
};
|
|
79
|
+
const apply = (row) => {
|
|
80
|
+
const { product, uid, setAppLanguage } = live.current;
|
|
81
|
+
const hasThemeStore = readAppColorSchemeOverride() !== undefined;
|
|
82
|
+
quietly(() => {
|
|
83
|
+
if (hasThemeStore)
|
|
84
|
+
setAppColorSchemeOverride(row.colorScheme);
|
|
85
|
+
setAppLanguage(row.language ? resolveLanguage(row.language) : null);
|
|
86
|
+
replaceDefaultViews(product, row.views);
|
|
87
|
+
});
|
|
88
|
+
// Stamped as agreed only when all of it landed: a page with no theme
|
|
89
|
+
// store could not apply a colour scheme, so the next page tries again.
|
|
90
|
+
if (uid && (hasThemeStore || row.colorScheme === null))
|
|
91
|
+
writeTuneStamp(product, { at: row.at, uid });
|
|
92
|
+
};
|
|
93
|
+
// ── A change on this device ────────────────────────────────────────────────
|
|
94
|
+
useEffect(() => onTuneChange((changed) => {
|
|
95
|
+
const { product, uid } = live.current;
|
|
96
|
+
if (changed && changed !== product)
|
|
97
|
+
return;
|
|
98
|
+
const at = Date.now();
|
|
99
|
+
writeTuneStamp(product, uid ? { at, uid } : { at, guest: true });
|
|
100
|
+
if (!uid)
|
|
101
|
+
return;
|
|
102
|
+
if (timer.current)
|
|
103
|
+
clearTimeout(timer.current);
|
|
104
|
+
timer.current = setTimeout(() => {
|
|
105
|
+
timer.current = null;
|
|
106
|
+
push(readTuneStamp(live.current.product)?.at ?? at);
|
|
107
|
+
}, PUSH_DELAY_MS);
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
}), []);
|
|
110
|
+
// A write still waiting when the provider goes is sent now, not lost.
|
|
111
|
+
useEffect(() => () => {
|
|
112
|
+
if (!timer.current)
|
|
113
|
+
return;
|
|
114
|
+
clearTimeout(timer.current);
|
|
115
|
+
timer.current = null;
|
|
116
|
+
push(readTuneStamp(live.current.product)?.at ?? Date.now());
|
|
117
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
|
+
}, []);
|
|
119
|
+
// ── Re-read on resume (phone apps stay resident) ───────────────────────────
|
|
120
|
+
const [pull, setPull] = useState(0);
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (!uid || typeof window === 'undefined')
|
|
123
|
+
return;
|
|
124
|
+
let last = Date.now();
|
|
125
|
+
const again = () => {
|
|
126
|
+
if (Date.now() - last < RESUME_THROTTLE_MS)
|
|
127
|
+
return;
|
|
128
|
+
last = Date.now();
|
|
129
|
+
setPull((n) => n + 1);
|
|
130
|
+
};
|
|
131
|
+
const onVisibility = () => { if (document.visibilityState === 'visible')
|
|
132
|
+
again(); };
|
|
133
|
+
const onPageShow = (e) => { if (e.persisted)
|
|
134
|
+
again(); };
|
|
135
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
136
|
+
window.addEventListener('pageshow', onPageShow);
|
|
137
|
+
return () => {
|
|
138
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
139
|
+
window.removeEventListener('pageshow', onPageShow);
|
|
140
|
+
};
|
|
141
|
+
}, [uid]);
|
|
142
|
+
// ── Sign-in (and resume): newer side wins ──────────────────────────────────
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (!uid || typeof window === 'undefined')
|
|
145
|
+
return;
|
|
146
|
+
let cancelled = false;
|
|
147
|
+
void (async () => {
|
|
148
|
+
try {
|
|
149
|
+
const { data, error } = await supabase
|
|
150
|
+
.from('user_app_prefs')
|
|
151
|
+
.select('data')
|
|
152
|
+
.eq('app', tuneRowApp(product))
|
|
153
|
+
.maybeSingle();
|
|
154
|
+
if (cancelled || error)
|
|
155
|
+
return;
|
|
156
|
+
const remote = parseTuneRow(data?.data);
|
|
157
|
+
if (remote)
|
|
158
|
+
lastRow.current = remote;
|
|
159
|
+
// Read now, not before the await: a change made meanwhile (the guest
|
|
160
|
+
// adoption on sign-in, say) is part of the answer.
|
|
161
|
+
const local = readTuneStamp(product);
|
|
162
|
+
const action = decideTuneSync(local, remote, uid);
|
|
163
|
+
if (action === 'apply' && remote)
|
|
164
|
+
apply(remote);
|
|
165
|
+
else if (action === 'push' && local) {
|
|
166
|
+
// A change's own write still waiting on its timer will send it.
|
|
167
|
+
if (timer.current)
|
|
168
|
+
return;
|
|
169
|
+
if (local.guest)
|
|
170
|
+
push(Date.now());
|
|
171
|
+
else if (sent.current !== `${uid}:${local.at}`)
|
|
172
|
+
push(local.at);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch { /* no sync this time — see the header */ }
|
|
176
|
+
})();
|
|
177
|
+
return () => { cancelled = true; };
|
|
178
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
179
|
+
}, [supabase, product, uid, pull]);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=TuneSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TuneSync.js","sourceRoot":"","sources":["../src/TuneSync.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,sEAAsE;AACtE,yEAAyE;AACzE,yEAAyE;AACzE,iCAAiC;AACjC,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;AACvE,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,2EAA2E;AAC3E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,6BAA6B;AAC7B,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,+EAA+E;AAC/E,yEAAyE;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EACL,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,aAAa,EACb,UAAU,EACV,cAAc,GAGf,MAAM,mBAAmB,CAAA;AAE1B,+DAA+D;AAC/D,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,4DAA4D;AAC5D,MAAM,aAAa,GAAG,EAAE,CAAA;AAExB,MAAM,UAAU,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B,IAAI,KAAK,CAAC,KAAK;wBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;yBAC5B,IAAI,IAAI,CAAC,OAAO,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;wBAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;gBAChE,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAC,wCAAwC,CAAC,CAAC;QACtD,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAA,CAAC,CAAC,CAAA;QACjC,uDAAuD;IACzD,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;IAElC,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/defaultView.d.ts
CHANGED
|
@@ -10,6 +10,17 @@ export declare const DEFAULT_VIEW_DOUBLE_TAP_MS = 350;
|
|
|
10
10
|
export declare function readDefaultView(product: string, id: string): string | null;
|
|
11
11
|
/** Store (or, with `null`, forget) one view row's default. */
|
|
12
12
|
export declare function writeDefaultView(product: string, id: string, view: string | null): void;
|
|
13
|
+
/**
|
|
14
|
+
* Every default view `product` has on this device, id → view. For Tune sync
|
|
15
|
+
* (TuneSync.tsx); an app reads one with {@link readDefaultView}.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readAllDefaultViews(product: string): Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Make `views` the whole set of `product`'s default views on this device: the
|
|
20
|
+
* account's set arriving from another device. Not a change of this device's
|
|
21
|
+
* own, so it is not stamped (TuneSync runs it quietly).
|
|
22
|
+
*/
|
|
23
|
+
export declare function replaceDefaultViews(product: string, views: Record<string, string>): void;
|
|
13
24
|
/**
|
|
14
25
|
* Forget every default view `product` has. Reset to defaults calls this, so an
|
|
15
26
|
* app gets it without wiring anything.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultView.d.ts","sourceRoot":"","sources":["../src/defaultView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA6F,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAGrI,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"defaultView.d.ts","sourceRoot":"","sources":["../src/defaultView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA6F,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAGrI,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAsCrD,yEAAyE;AACzE,eAAO,MAAM,0BAA0B,MAAM,CAAA;AAwB7C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG1E;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CASvF;AAcD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAW3E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAOxF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAQvD;AAgCD,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,MAAM;IACrD;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,EAAE,CAAA;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,KAAK,EAA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C,EAAE;IAAE,QAAQ,EAAE,MAAM;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;KAAE,CAAA;CAAE,GACrF,MAAM,IAAI,CAYZ"}
|
package/dist/defaultView.js
CHANGED
|
@@ -5,6 +5,7 @@ import { useUniversal } from './provider.js';
|
|
|
5
5
|
import { t } from './i18n.js';
|
|
6
6
|
import { MENU } from './menuTheme.js';
|
|
7
7
|
import { clearWhatsNewSeen } from './whatsNew.js';
|
|
8
|
+
import { noteTuneChange } from './tuneSyncCore.js';
|
|
8
9
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
9
10
|
// Double-tap a view button to make it the default — every app, one behaviour.
|
|
10
11
|
//
|
|
@@ -24,11 +25,19 @@ import { clearWhatsNewSeen } from './whatsNew.js';
|
|
|
24
25
|
// • the same choice as a row in Tune this app (<DefaultViewSelect />), for
|
|
25
26
|
// anybody who cannot double-tap.
|
|
26
27
|
//
|
|
27
|
-
// WHERE IT LIVES. localStorage, `unisim:default-view:<product>:<id
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
28
|
+
// WHERE IT LIVES. localStorage, `unisim:default-view:<product>:<id>`. The
|
|
29
|
+
// product in the key is what lets **Reset to defaults** clear every default
|
|
30
|
+
// view an app has without the app listing them (clearDefaultViews), including
|
|
31
|
+
// ones on screens that are not mounted at the time.
|
|
32
|
+
//
|
|
33
|
+
// ⚠️ AND, SIGNED IN, THE ACCOUNT (since 0.229.0). This said "never the account"
|
|
34
|
+
// until then — a default view was how one device liked to open. James's global
|
|
35
|
+
// rule of 2026-10-30 overrides that: everything in Tune this app is saved and
|
|
36
|
+
// synced to the account. So every default view an app has rides in its
|
|
37
|
+
// `tune:<product>` row with its colour scheme and language override (newest
|
|
38
|
+
// change wins, one stamp per app — tuneSyncCore.ts, TuneSync.tsx). The writers
|
|
39
|
+
// below tell the sync about a real change; the device copy here is still the
|
|
40
|
+
// one the app reads, synchronously, so a view never waits on the network.
|
|
32
41
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
33
42
|
/** Two taps on one button closer together than this are a double tap. */
|
|
34
43
|
export const DEFAULT_VIEW_DOUBLE_TAP_MS = 350;
|
|
@@ -74,6 +83,7 @@ export function readDefaultView(product, id) {
|
|
|
74
83
|
export function writeDefaultView(product, id, view) {
|
|
75
84
|
if (typeof window === 'undefined')
|
|
76
85
|
return;
|
|
86
|
+
const changed = readDefaultView(product, id) !== view;
|
|
77
87
|
try {
|
|
78
88
|
if (view === null)
|
|
79
89
|
window.localStorage.removeItem(storageKey(product, id));
|
|
@@ -82,6 +92,57 @@ export function writeDefaultView(product, id, view) {
|
|
|
82
92
|
}
|
|
83
93
|
catch { /* private mode: the default just does not stick */ }
|
|
84
94
|
notify();
|
|
95
|
+
if (changed)
|
|
96
|
+
noteTuneChange(product);
|
|
97
|
+
}
|
|
98
|
+
function productKeys(product) {
|
|
99
|
+
const prefix = `${PREFIX}${product}:`;
|
|
100
|
+
const keys = [];
|
|
101
|
+
try {
|
|
102
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
103
|
+
const k = window.localStorage.key(i);
|
|
104
|
+
if (k && k.startsWith(prefix))
|
|
105
|
+
keys.push(k);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch { /* ignore */ }
|
|
109
|
+
return keys;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Every default view `product` has on this device, id → view. For Tune sync
|
|
113
|
+
* (TuneSync.tsx); an app reads one with {@link readDefaultView}.
|
|
114
|
+
*/
|
|
115
|
+
export function readAllDefaultViews(product) {
|
|
116
|
+
if (typeof window === 'undefined')
|
|
117
|
+
return {};
|
|
118
|
+
const prefix = `${PREFIX}${product}:`;
|
|
119
|
+
const out = {};
|
|
120
|
+
try {
|
|
121
|
+
for (const k of productKeys(product)) {
|
|
122
|
+
const v = window.localStorage.getItem(k);
|
|
123
|
+
if (v)
|
|
124
|
+
out[k.slice(prefix.length)] = v;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch { /* ignore */ }
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Make `views` the whole set of `product`'s default views on this device: the
|
|
132
|
+
* account's set arriving from another device. Not a change of this device's
|
|
133
|
+
* own, so it is not stamped (TuneSync runs it quietly).
|
|
134
|
+
*/
|
|
135
|
+
export function replaceDefaultViews(product, views) {
|
|
136
|
+
if (typeof window === 'undefined')
|
|
137
|
+
return;
|
|
138
|
+
try {
|
|
139
|
+
for (const k of productKeys(product))
|
|
140
|
+
window.localStorage.removeItem(k);
|
|
141
|
+
for (const [id, view] of Object.entries(views))
|
|
142
|
+
window.localStorage.setItem(storageKey(product, id), view);
|
|
143
|
+
}
|
|
144
|
+
catch { /* ignore */ }
|
|
145
|
+
notify();
|
|
85
146
|
}
|
|
86
147
|
/**
|
|
87
148
|
* Forget every default view `product` has. Reset to defaults calls this, so an
|
|
@@ -90,19 +151,15 @@ export function writeDefaultView(product, id, view) {
|
|
|
90
151
|
export function clearDefaultViews(product) {
|
|
91
152
|
if (typeof window === 'undefined')
|
|
92
153
|
return;
|
|
93
|
-
const
|
|
154
|
+
const doomed = productKeys(product);
|
|
94
155
|
try {
|
|
95
|
-
const doomed = [];
|
|
96
|
-
for (let i = 0; i < window.localStorage.length; i++) {
|
|
97
|
-
const k = window.localStorage.key(i);
|
|
98
|
-
if (k && k.startsWith(prefix))
|
|
99
|
-
doomed.push(k);
|
|
100
|
-
}
|
|
101
156
|
for (const k of doomed)
|
|
102
157
|
window.localStorage.removeItem(k);
|
|
103
158
|
}
|
|
104
159
|
catch { /* ignore */ }
|
|
105
160
|
notify();
|
|
161
|
+
if (doomed.length > 0)
|
|
162
|
+
noteTuneChange(product);
|
|
106
163
|
}
|
|
107
164
|
function ensurePopKeyframes() {
|
|
108
165
|
if (typeof document === 'undefined' || document.getElementById(POP_KEYFRAMES))
|