mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: split main runtime handlers into focused modules
This commit is contained in:
98
src/main/runtime/app-lifecycle-main-cleanup.ts
Normal file
98
src/main/runtime/app-lifecycle-main-cleanup.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
// Narrow structural types used by cleanup assembly.
|
||||
type Destroyable = {
|
||||
destroy: () => void;
|
||||
};
|
||||
|
||||
type DestroyableWindow = Destroyable & {
|
||||
isDestroyed: () => boolean;
|
||||
};
|
||||
|
||||
type Stoppable = {
|
||||
stop: () => void;
|
||||
};
|
||||
|
||||
type SocketLike = {
|
||||
destroy: () => void;
|
||||
};
|
||||
|
||||
type TimerLike = ReturnType<typeof setTimeout>;
|
||||
|
||||
export function createBuildOnWillQuitCleanupDepsHandler(deps: {
|
||||
destroyTray: () => void;
|
||||
stopConfigHotReload: () => void;
|
||||
restorePreviousSecondarySubVisibility: () => void;
|
||||
unregisterAllGlobalShortcuts: () => void;
|
||||
stopSubtitleWebsocket: () => void;
|
||||
stopTexthookerService: () => void;
|
||||
|
||||
getYomitanParserWindow: () => DestroyableWindow | null;
|
||||
clearYomitanParserState: () => void;
|
||||
|
||||
getWindowTracker: () => Stoppable | null;
|
||||
getMpvSocket: () => SocketLike | null;
|
||||
getReconnectTimer: () => TimerLike | null;
|
||||
clearReconnectTimerRef: () => void;
|
||||
|
||||
getSubtitleTimingTracker: () => Destroyable | null;
|
||||
getImmersionTracker: () => Destroyable | null;
|
||||
clearImmersionTracker: () => void;
|
||||
getAnkiIntegration: () => Destroyable | null;
|
||||
|
||||
getAnilistSetupWindow: () => Destroyable | null;
|
||||
clearAnilistSetupWindow: () => void;
|
||||
getJellyfinSetupWindow: () => Destroyable | null;
|
||||
clearJellyfinSetupWindow: () => void;
|
||||
|
||||
stopJellyfinRemoteSession: () => void;
|
||||
}) {
|
||||
return () => ({
|
||||
destroyTray: () => deps.destroyTray(),
|
||||
stopConfigHotReload: () => deps.stopConfigHotReload(),
|
||||
restorePreviousSecondarySubVisibility: () => deps.restorePreviousSecondarySubVisibility(),
|
||||
unregisterAllGlobalShortcuts: () => deps.unregisterAllGlobalShortcuts(),
|
||||
stopSubtitleWebsocket: () => deps.stopSubtitleWebsocket(),
|
||||
stopTexthookerService: () => deps.stopTexthookerService(),
|
||||
destroyYomitanParserWindow: () => {
|
||||
const window = deps.getYomitanParserWindow();
|
||||
if (!window) return;
|
||||
if (window.isDestroyed()) return;
|
||||
window.destroy();
|
||||
},
|
||||
clearYomitanParserState: () => deps.clearYomitanParserState(),
|
||||
stopWindowTracker: () => {
|
||||
const tracker = deps.getWindowTracker();
|
||||
tracker?.stop();
|
||||
},
|
||||
destroyMpvSocket: () => {
|
||||
const socket = deps.getMpvSocket();
|
||||
socket?.destroy();
|
||||
},
|
||||
clearReconnectTimer: () => {
|
||||
const timer = deps.getReconnectTimer();
|
||||
if (!timer) return;
|
||||
clearTimeout(timer);
|
||||
deps.clearReconnectTimerRef();
|
||||
},
|
||||
destroySubtitleTimingTracker: () => {
|
||||
deps.getSubtitleTimingTracker()?.destroy();
|
||||
},
|
||||
destroyImmersionTracker: () => {
|
||||
const tracker = deps.getImmersionTracker();
|
||||
if (!tracker) return;
|
||||
tracker.destroy();
|
||||
deps.clearImmersionTracker();
|
||||
},
|
||||
destroyAnkiIntegration: () => {
|
||||
deps.getAnkiIntegration()?.destroy();
|
||||
},
|
||||
destroyAnilistSetupWindow: () => {
|
||||
deps.getAnilistSetupWindow()?.destroy();
|
||||
},
|
||||
clearAnilistSetupWindow: () => deps.clearAnilistSetupWindow(),
|
||||
destroyJellyfinSetupWindow: () => {
|
||||
deps.getJellyfinSetupWindow()?.destroy();
|
||||
},
|
||||
clearJellyfinSetupWindow: () => deps.clearJellyfinSetupWindow(),
|
||||
stopJellyfinRemoteSession: () => deps.stopJellyfinRemoteSession(),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user