Back to The Bathyal Post
SOURCE / PINNED RELEASE

Made of little things.

The Bathyal Post

Release
fa6ce530b9f3…
Author-recorded commit
b255b3c9fd49…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-55c50b9a042

Archive hash verified: 03cf62191e7476c5…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/napplet-settings.ts
import { config } from '@napplet/sdk';
import settingsSchema from '../config.schema.json';
import { runtimeHasDomain } from './domain-availability.js';

export function observeMotion(change: (reduced: boolean) => void) {
  const preference = matchMedia('(prefers-reduced-motion: reduce)');
  let still = false;
  let closed = false;
  let subscription: { close(): void } | undefined;
  const update = () => { if (!closed) change(still || preference.matches); };
  preference.addEventListener('change', update);
  update();
  if (runtimeHasDomain('config')) void (async () => {
    try {
      if (!config.schema) await config.registerSchema(settingsSchema as Parameters<typeof config.registerSchema>[0]);
      if (closed) return;
      subscription = config.subscribe((values) => {
        still = values.stillChart === true;
        update();
      });
    } catch { /* The user's system preference remains effective offline. */ }
  })();
  return () => {
    closed = true;
    preference.removeEventListener('change', update);
    subscription?.close();
  };
}