Back to Poly Dogfight
SOURCE / PINNED RELEASE

Made of little things.

Poly Dogfight

Release
ad11a55ec88c…
Author-recorded commit
483e0e0c5000…
License
LICENSE
Author’s source reference
nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/poly-dogfight

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

src/shell-keys.ts
/**
 * NAP-KEYS action keybindings for discrete commands. The shell may bind each
 * action to a key; the injected binding then suppresses forwarding for that
 * key, calls `preventDefault()` and runs the handler locally. Built-in keys
 * stay as the fallback, so the optional domain only adds shell-owned bindings.
 * Held flight controls stay on raw key state: actions have no release edge.
 */
import { KEYS_DOMAIN, keys, type Action } from '@napplet/sdk';
import { runtimeHasDomain } from './domain-availability.ts';

export type ShellAction = Action & { run: () => void };

/** Register actions when the domain is present; returns a cleanup. */
export function registerShellActions(actions: readonly ShellAction[]): () => void {
  if (!runtimeHasDomain(KEYS_DOMAIN)) return () => {};
  const subscriptions = actions.map(({ run, ...action }) => {
    keys.registerAction(action).catch((error: unknown) => {
      console.warn(`Shell keybinding ${action.id} unavailable`, error);
    });
    return keys.onAction(action.id, run);
  });
  return () => {
    for (const subscription of subscriptions) subscription.close();
    for (const action of actions) keys.unregisterAction(action.id);
  };
}

/** True when a NAP-KEYS binding already handled this keystroke as an action. */
export const handledByShellBinding = (event: KeyboardEvent) => event.defaultPrevented;