Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- **Core reader for source rigs (feedpak 1.18.0).** A pack can declare what a
### Added
- Library card actions can now provide per-song label and icon callbacks, so
plugins can render dynamic card badges without DOM patching.
- **Core reader for source rigs (feedpak 1.18.0).** A pack can declare what a
MIDI part should sound like by binding a rig; core now reads that binding and
hands it to the client instead of dropping it. Three parts: the
`tone_changes` WS message carries the pack's rig bindings (`base_rig`, and
Expand Down
11 changes: 8 additions & 3 deletions static/capabilities/library-card-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* register(spec) -> unregister() spec: { id, pluginId, label, icon?,
* placement?('menu'|'inline'|'overlay'), order?, destructive?,
* applies?(song)->bool, enabled?(song)->bool, run(song, ctx) }
* label/icon may be strings or (song)->string functions.
* list(song) -> [actionSummary] applicable actions, sorted
* run(id, song, ctx) -> Promise<{ ok, outcome, result?|error? }>
* snapshot() -> redaction-safe registry snapshot
Expand All @@ -39,8 +40,8 @@
return {
id: String(spec.id),
pluginId: String(spec.pluginId || 'unknown'),
label: String(spec.label || spec.id),
icon: spec.icon || '',
label: typeof spec.label === 'function' ? spec.label : () => String(spec.label || spec.id),
icon: typeof spec.icon === 'function' ? spec.icon : () => String(spec.icon || ''),
placement: PLACEMENTS.includes(spec.placement) ? spec.placement : 'menu',
order: Number.isFinite(spec.order) ? spec.order : 100,
destructive: !!spec.destructive,
Expand Down Expand Up @@ -87,7 +88,11 @@
if (!applicable) continue;
let enabled = true;
try { enabled = a.enabled(song) !== false; } catch (e) { enabled = true; }
out.push({ id: a.id, pluginId: a.pluginId, label: a.label, icon: a.icon, placement: a.placement, order: a.order, destructive: a.destructive, enabled });
let label = a.id;
try { label = String(a.label(song) || a.id); } catch (e) { label = a.id; }
let icon = '';
try { icon = String(a.icon(song) || ''); } catch (e) { icon = ''; }
out.push({ id: a.id, pluginId: a.pluginId, label, icon, placement: a.placement, order: a.order, destructive: a.destructive, enabled });
}
out.sort((x, y) => (x.order - y.order) || x.label.localeCompare(y.label));
return out;
Expand Down
31 changes: 31 additions & 0 deletions tests/js/library_card_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ test('enabled() reflected in the summary but action still listed', () => {
assert.strictEqual(on.enabled, true);
});

test('label and icon callbacks resolve per listed song', () => {
freshIds();
reg.register({
id: 'difficulty',
label: (s) => `${s.progress}%`,
icon: (s) => (s.progress >= 90 ? '*' : ''),
run() {},
});
assert.deepStrictEqual(
reg.list({ filename: 'easy.sloppak', progress: 42 }).map((a) => ({ label: a.label, icon: a.icon })),
[{ label: '42%', icon: '' }],
);
assert.deepStrictEqual(
reg.list({ filename: 'done.sloppak', progress: 96 }).map((a) => ({ label: a.label, icon: a.icon })),
[{ label: '96%', icon: '*' }],
);
});

test('label and icon callback errors fall back safely', () => {
freshIds();
reg.register({
id: 'bad-dynamic',
label() { throw new Error('label unavailable'); },
icon() { throw new Error('icon unavailable'); },
run() {},
});
const [action] = reg.list({ filename: 'song.sloppak' });
assert.strictEqual(action.label, 'bad-dynamic');
assert.strictEqual(action.icon, '');
});

test('run() invokes the handler and reports handled', async () => {
freshIds();
let got = null;
Expand Down
Loading