refactor: extract app shutdown orchestration service

This commit is contained in:
2026-02-10 00:06:10 -08:00
parent 2878a1f3d1
commit 8b286f15e8
4 changed files with 107 additions and 25 deletions

View File

@@ -0,0 +1,32 @@
import test from "node:test";
import assert from "node:assert/strict";
import { runAppShutdownRuntimeService } from "./app-shutdown-runtime-service";
test("runAppShutdownRuntimeService runs teardown steps in order", () => {
const calls: string[] = [];
runAppShutdownRuntimeService({
unregisterAllGlobalShortcuts: () => calls.push("unregisterAllGlobalShortcuts"),
stopSubtitleWebsocket: () => calls.push("stopSubtitleWebsocket"),
stopTexthookerService: () => calls.push("stopTexthookerService"),
destroyYomitanParserWindow: () => calls.push("destroyYomitanParserWindow"),
clearYomitanParserPromises: () => calls.push("clearYomitanParserPromises"),
stopWindowTracker: () => calls.push("stopWindowTracker"),
destroyMpvSocket: () => calls.push("destroyMpvSocket"),
clearReconnectTimer: () => calls.push("clearReconnectTimer"),
destroySubtitleTimingTracker: () => calls.push("destroySubtitleTimingTracker"),
destroyAnkiIntegration: () => calls.push("destroyAnkiIntegration"),
});
assert.deepEqual(calls, [
"unregisterAllGlobalShortcuts",
"stopSubtitleWebsocket",
"stopTexthookerService",
"destroyYomitanParserWindow",
"clearYomitanParserPromises",
"stopWindowTracker",
"destroyMpvSocket",
"clearReconnectTimer",
"destroySubtitleTimingTracker",
"destroyAnkiIntegration",
]);
});

View File

@@ -0,0 +1,27 @@
export interface AppShutdownRuntimeDeps {
unregisterAllGlobalShortcuts: () => void;
stopSubtitleWebsocket: () => void;
stopTexthookerService: () => void;
destroyYomitanParserWindow: () => void;
clearYomitanParserPromises: () => void;
stopWindowTracker: () => void;
destroyMpvSocket: () => void;
clearReconnectTimer: () => void;
destroySubtitleTimingTracker: () => void;
destroyAnkiIntegration: () => void;
}
export function runAppShutdownRuntimeService(
deps: AppShutdownRuntimeDeps,
): void {
deps.unregisterAllGlobalShortcuts();
deps.stopSubtitleWebsocket();
deps.stopTexthookerService();
deps.destroyYomitanParserWindow();
deps.clearYomitanParserPromises();
deps.stopWindowTracker();
deps.destroyMpvSocket();
deps.clearReconnectTimer();
deps.destroySubtitleTimingTracker();
deps.destroyAnkiIntegration();
}