refactor: split main runtime flows into focused modules

This commit is contained in:
2026-02-19 16:57:06 -08:00
parent 162be118e1
commit d5d71816ac
31 changed files with 3270 additions and 672 deletions

View File

@@ -9,6 +9,28 @@
## Current Work (newest first)
- [2026-02-20T00:47:26Z] progress: extracted CLI runtime prechecks + initial arg orchestration into `src/main/runtime/cli-command-prechecks.ts` and `src/main/runtime/initial-args-handler.ts`; rewired `handleCliCommand` texthooker-only transition and `handleInitialArgs`.
- [2026-02-20T00:47:26Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/cli-command-prechecks.test.js dist/main/runtime/initial-args-handler.test.js dist/main/runtime/anilist-setup-window.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (50/50).
- [2026-02-20T00:45:18Z] progress: extracted setup-window lifecycle/focus bookkeeping helpers into runtime modules (`createMaybeFocusExistingAnilistSetupWindowHandler`, `createHandleAnilistSetupWindowClosedHandler`, `createHandleAnilistSetupWindowOpenedHandler`, `createMaybeFocusExistingJellyfinSetupWindowHandler`, `createHandleJellyfinSetupWindowClosedHandler`, `createHandleJellyfinSetupWindowOpenedHandler`); rewired `openAnilistSetupWindow` + `openJellyfinSetupWindow`.
- [2026-02-20T00:45:18Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/anilist-setup-window.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (43/43).
- [2026-02-20T00:41:54Z] progress: extracted AniList setup fallback load-event callbacks into `src/main/runtime/anilist-setup-window.ts` (`createAnilistSetupDidFailLoadHandler`, `createAnilistSetupDidFinishLoadHandler`); rewired `did-fail-load` and `did-finish-load` hooks in `openAnilistSetupWindow`.
- [2026-02-20T00:41:54Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/anilist-setup-window.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (37/37).
- [2026-02-20T00:40:53Z] progress: extracted AniList setup URL event handlers from `openAnilistSetupWindow` into `src/main/runtime/anilist-setup-window.ts` (`createAnilistSetupWindowOpenHandler`, `createAnilistSetupWillNavigateHandler`, `createAnilistSetupWillRedirectHandler`, `createAnilistSetupDidNavigateHandler`); rewired `main.ts` callbacks.
- [2026-02-20T00:40:53Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/anilist-setup-window.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (34/34).
- [2026-02-20T00:35:26Z] progress: extracted Jellyfin setup window navigation interception into `createHandleJellyfinSetupNavigationHandler` in `src/main/runtime/jellyfin-setup-window.ts`; rewired `openJellyfinSetupWindow` `will-navigate` branch in `src/main.ts`.
- [2026-02-20T00:35:26Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (26/26).
- [2026-02-20T00:34:12Z] progress: extracted Jellyfin remote lifecycle orchestration from `src/main.ts` into `src/main/runtime/jellyfin-remote-session-lifecycle.ts` (`createStartJellyfinRemoteSessionHandler`, `createStopJellyfinRemoteSessionHandler`); rewired start/stop call sites and callbacks; `src/main.ts` now 2731 LOC.
- [2026-02-20T00:34:12Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/jellyfin-remote-session-lifecycle.test.js dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (20/20).
- [2026-02-20T00:32:07Z] progress: extracted remaining `runJellyfinCommand` action branches into `src/main/runtime/jellyfin-cli-play.ts` and `src/main/runtime/jellyfin-cli-remote-announce.ts`; rewired main command router; `src/main.ts` now 2773 LOC.
- [2026-02-20T00:32:07Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/jellyfin-cli-auth.test.js dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-play.test.js dist/main/runtime/jellyfin-cli-remote-announce.test.js` pass (16/16).
- [2026-02-20T00:29:07Z] progress: extracted Jellyfin CLI listing branches (`--jellyfin-libraries`, `--jellyfin-items`, `--jellyfin-subtitles`) from `runJellyfinCommand` into `src/main/runtime/jellyfin-cli-list.ts`; rewired through `createHandleJellyfinListCommands`; `src/main.ts` now 2820 LOC.
- [2026-02-20T00:29:07Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/jellyfin-cli-list.test.js dist/main/runtime/jellyfin-cli-auth.test.js` pass (9/9).
- [2026-02-20T00:19:13Z] progress: extracted AniList post-watch + queue orchestration into `src/main/runtime/anilist-post-watch.ts`, subtitle position state wrappers into `src/main/runtime/subtitle-position.ts`, and app protocol URL event wiring into `src/main/runtime/protocol-url-handlers.ts`; rewired `main.ts`; `src/main.ts` now 2853 LOC.
- [2026-02-20T00:19:13Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/protocol-url-handlers.test.js dist/main/runtime/subtitle-position.test.js dist/main/runtime/anilist-post-watch.test.js dist/main/runtime/anilist-media-guess.test.js dist/main/runtime/anilist-token-refresh.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/anilist-setup-protocol.test.js dist/main/runtime/jellyfin-remote-connection.test.js dist/main/runtime/jellyfin-remote-playback.test.js dist/main/runtime/jellyfin-remote-commands.test.js dist/main/runtime/config-hot-reload-handlers.test.js dist/core/services/app-ready.test.js dist/core/services/startup-bootstrap.test.js` pass (52/52).
- [2026-02-20T00:12:40Z] progress: extracted AniList token/media resolution helpers from `src/main.ts` into `src/main/runtime/anilist-token-refresh.ts` and `src/main/runtime/anilist-media-guess.ts`; rewired `refreshAnilistClientSecretState`, `maybeProbeAnilistDuration`, and `ensureAnilistMediaGuess`; `src/main.ts` now 2892 LOC.
- [2026-02-20T00:12:40Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/anilist-media-guess.test.js dist/main/runtime/anilist-token-refresh.test.js dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/anilist-setup-protocol.test.js dist/main/runtime/jellyfin-remote-connection.test.js dist/main/runtime/jellyfin-remote-playback.test.js dist/main/runtime/jellyfin-remote-commands.test.js dist/main/runtime/config-hot-reload-handlers.test.js dist/core/services/app-ready.test.js dist/core/services/startup-bootstrap.test.js` pass (45/45).
- [2026-02-20T00:08:57Z] progress: extracted Jellyfin setup window form/submission logic from `src/main.ts` into `src/main/runtime/jellyfin-setup-window.ts` (`buildJellyfinSetupFormHtml`, `parseJellyfinSetupSubmissionUrl`, `createHandleJellyfinSetupSubmissionHandler`); kept window lifecycle in main.
- [2026-02-20T00:08:57Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/jellyfin-setup-window.test.js dist/main/runtime/anilist-setup-protocol.test.js dist/main/runtime/jellyfin-remote-connection.test.js dist/main/runtime/jellyfin-remote-playback.test.js dist/main/runtime/jellyfin-remote-commands.test.js dist/main/runtime/config-hot-reload-handlers.test.js dist/core/services/app-ready.test.js dist/core/services/startup-bootstrap.test.js` pass (39/39).
- [2026-02-20T00:00:55Z] progress: extracted AniList setup/protocol handlers (`notifyAnilistSetup`, `consumeAnilistSetupTokenFromUrl`, `handleAnilistSetupProtocolUrl`, `registerSubminerProtocolClient`) from `src/main.ts` into `src/main/runtime/anilist-setup-protocol.ts`; rewired protocol registration and callback wiring; `src/main.ts` now 2988 LOC.
- [2026-02-20T00:00:55Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `node --test dist/main/runtime/anilist-setup-protocol.test.js dist/main/runtime/jellyfin-remote-connection.test.js dist/main/runtime/jellyfin-remote-playback.test.js dist/main/runtime/jellyfin-remote-commands.test.js dist/main/runtime/config-hot-reload-handlers.test.js dist/core/services/app-ready.test.js dist/core/services/startup-bootstrap.test.js` pass (35/35).
- [2026-02-19T23:58:32Z] progress: extracted Jellyfin MPV connection/bootstrap handlers (`waitForMpvConnected`, `launchMpvIdleForJellyfinPlayback`, `ensureMpvConnectedForJellyfinPlayback`) from `src/main.ts` into `src/main/runtime/jellyfin-remote-connection.ts`; rewired call sites; `src/main.ts` now 2996 LOC.
@@ -38,6 +60,36 @@
- `src/main/runtime/jellyfin-remote-connection.test.ts`
- `src/main/runtime/anilist-setup-protocol.ts`
- `src/main/runtime/anilist-setup-protocol.test.ts`
- `src/main/runtime/jellyfin-setup-window.ts`
- `src/main/runtime/jellyfin-setup-window.test.ts`
- `src/main/runtime/initial-args-handler.ts`
- `src/main/runtime/initial-args-handler.test.ts`
- `src/main/runtime/cli-command-prechecks.ts`
- `src/main/runtime/cli-command-prechecks.test.ts`
- `src/main/runtime/anilist-token-refresh.ts`
- `src/main/runtime/anilist-token-refresh.test.ts`
- `src/main/runtime/anilist-media-guess.ts`
- `src/main/runtime/anilist-media-guess.test.ts`
- `src/main/runtime/anilist-post-watch.ts`
- `src/main/runtime/anilist-post-watch.test.ts`
- `src/main/runtime/subtitle-position.ts`
- `src/main/runtime/subtitle-position.test.ts`
- `src/main/runtime/protocol-url-handlers.ts`
- `src/main/runtime/protocol-url-handlers.test.ts`
- `src/main/runtime/jellyfin-cli-auth.ts`
- `src/main/runtime/jellyfin-cli-auth.test.ts`
- `src/main/runtime/jellyfin-cli-list.ts`
- `src/main/runtime/jellyfin-cli-list.test.ts`
- `src/main/runtime/jellyfin-cli-play.ts`
- `src/main/runtime/jellyfin-cli-play.test.ts`
- `src/main/runtime/jellyfin-cli-remote-announce.ts`
- `src/main/runtime/jellyfin-cli-remote-announce.test.ts`
- `src/main/runtime/jellyfin-remote-session-lifecycle.ts`
- `src/main/runtime/jellyfin-remote-session-lifecycle.test.ts`
- `src/main/runtime/anilist-setup-window.ts`
- `src/main/runtime/anilist-setup-window.test.ts`
- `src/main/runtime/jellyfin-setup-window.ts`
- `src/main/runtime/jellyfin-setup-window.test.ts`
## Open Questions / Blockers
@@ -45,5 +97,4 @@
## Next Step
- identify next extractable `src/main.ts` domain slice, add seam test, extract to `src/main/runtime/*`, run build + targeted tests.
- extract next `src/main.ts` slice likely Jellyfin setup UI branch (`openJellyfinSetupWindow` form handling + config patch helpers) into `src/main/runtime/jellyfin-setup-window.ts` with seam tests.
- extract next `src/main.ts` CLI command context composition slice into helper factory + tests.