klaudio 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +33 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaudio",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Add sound effects to your coding sessions — play sounds when tasks complete, notifications arrive, and more",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -453,21 +453,10 @@ const GameSoundsScreen = ({ game, sounds, onSelectSound, onDone, onBack }) => {
453
453
  // Sort files: voice first, then by priority
454
454
  const sortedFiles = hasCategories ? sortFilesByPriority(game.files) : game.files;
455
455
 
456
- // Fetch durations for visible files
457
- useEffect(() => {
458
- for (const f of sortedFiles.slice(0, 50)) {
459
- if (!fileDurations[f.path]) {
460
- getWavDuration(f.path).then((dur) => {
461
- if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
462
- });
463
- }
464
- }
465
- }, [game.files]);
466
-
467
- // Filter files by category
456
+ // Filter files by category (no hard cap — SelectInput handles visible window)
468
457
  const categoryFiles = activeCategory && activeCategory !== "all"
469
- ? sortedFiles.filter((f) => f.category === activeCategory).slice(0, 50)
470
- : sortedFiles.slice(0, 50);
458
+ ? sortedFiles.filter((f) => f.category === activeCategory)
459
+ : sortedFiles;
471
460
 
472
461
  // Stop current playback helper
473
462
  const stopPlayback = useCallback(() => {
@@ -479,6 +468,35 @@ const GameSoundsScreen = ({ game, sounds, onSelectSound, onDone, onBack }) => {
479
468
  setElapsed(0);
480
469
  }, []);
481
470
 
471
+ // Pre-fetch durations: first 15 on category enter, ±15 around highlighted file
472
+ useEffect(() => {
473
+ const end = Math.min(categoryFiles.length, 15);
474
+ for (let i = 0; i < end; i++) {
475
+ const f = categoryFiles[i];
476
+ if (!fileDurations[f.path]) {
477
+ getWavDuration(f.path).then((dur) => {
478
+ if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
479
+ });
480
+ }
481
+ }
482
+ }, [activeCategory]);
483
+
484
+ useEffect(() => {
485
+ if (!highlightedFile || highlightedFile === "_skip") return;
486
+ const idx = categoryFiles.findIndex((f) => f.path === highlightedFile);
487
+ if (idx < 0) return;
488
+ const start = Math.max(0, idx - 15);
489
+ const end = Math.min(categoryFiles.length, idx + 16);
490
+ for (let i = start; i < end; i++) {
491
+ const f = categoryFiles[i];
492
+ if (!fileDurations[f.path]) {
493
+ getWavDuration(f.path).then((dur) => {
494
+ if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
495
+ });
496
+ }
497
+ }
498
+ }, [highlightedFile, categoryFiles]);
499
+
482
500
  // Auto-preview: play sound when highlighted file changes (with debounce)
483
501
  useEffect(() => {
484
502
  if (!autoPreview || !highlightedFile || highlightedFile === "_skip") {
@@ -715,7 +733,7 @@ const GameSoundsScreen = ({ game, sounds, onSelectSound, onDone, onBack }) => {
715
733
  const filterLower = filter.toLowerCase();
716
734
  const allFileItems = categoryFiles.map((f) => {
717
735
  const dur = fileDurations[f.path];
718
- const durStr = dur != null ? ` (${dur > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS + "s max" : dur + "s"})` : "";
736
+ const durStr = dur != null ? ` (${dur}s${dur > MAX_PLAY_SECONDS ? `, preview ${MAX_PLAY_SECONDS}s` : ""})` : "";
719
737
  const catTag = (!activeCategory || activeCategory === "all") && f.category && f.category !== "other"
720
738
  ? `[${(CATEGORY_LABELS[f.category] || f.category).toUpperCase()}] ` : "";
721
739
  const name = f.displayName || f.name;