All files / app-play/src/ui/options runtime-defaults.ts

62.5% Statements 5/8
37.5% Branches 3/8
100% Functions 2/2
62.5% Lines 5/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                1x 4x       2x           1x   1x        
import { defaultBrowserWorkerCount } from '@be-music/player-browser/compute';
import { readDeviceSignals, resolveDefaultSkinEffects } from '../../device-profile.ts';
import { DEFAULT_RENDER_RESOLUTION, nearestRenderResolution, renderResolutionSteps } from '../../render-resolution.ts';
import { BE_MUSIC_SKINS } from '../../services/built-in-skins.ts';
import type { RuntimeDefaultResolver } from './layout.ts';
 
/** Applies the device profile and the currently loaded themes to the JSON's runtime defaults. */
export function runtimeOptionDefaults(firstLR2Theme: () => string | undefined): RuntimeDefaultResolver {
  return (policy) => {
    switch (policy) {
      case 'builtInSkin':
        return BE_MUSIC_SKINS.resolve(undefined).id;
      case 'lr2Theme':
        return firstLR2Theme();
      case 'skinEffects':
        return resolveDefaultSkinEffects(undefined, readDeviceSignals());
      case 'renderResolution':
        return nearestRenderResolution(renderResolutionSteps(window.devicePixelRatio || 1), DEFAULT_RENDER_RESOLUTION);
      case 'workers':
        return defaultBrowserWorkerCount(navigator.hardwareConcurrency);
      case 'bgaUseWebCodecs':
        return 'VideoEncoder' in globalThis;
    }
  };
}