Files
SubMiner/src/main/runtime/app-lifecycle-actions.ts
T
sudacode ca40cd6267 fix(anime): clarify bridge failures and update guidance
- Show actionable bridge errors and preserve episodes when details fail
- Check external bridges for updates without offering unsafe in-app installs
- Complete cleanup and ignore callbacks from closed Tsukihime sessions
2026-09-16 23:25:21 -07:00

114 lines
4.0 KiB
TypeScript

export function createOnWillQuitCleanupHandler(deps: {
destroyTray: () => void;
stopConfigHotReload: () => void;
restorePreviousSecondarySubVisibility: () => void;
restoreMpvSubVisibility: () => void;
unregisterAllGlobalShortcuts: () => void;
stopSubtitleWebsocket: () => void;
stopTexthookerService: () => void;
stopSyncAutoScheduler: () => void | Promise<void>;
clearWindowsVisibleOverlayForegroundPollLoop: () => void;
clearLinuxMpvFullscreenOverlayRefreshTimeouts: () => void;
destroyMainOverlayWindow: () => void;
destroyModalOverlayWindow: () => void;
destroyYomitanParserWindow: () => void;
clearYomitanParserState: () => void;
stopWindowTracker: () => void;
flushMpvLog: () => void;
destroyMpvSocket: () => void;
clearReconnectTimer: () => void;
destroySubtitleTimingTracker: () => void;
destroyImmersionTracker: () => void | Promise<void>;
destroyAnkiIntegration: () => void;
destroyAnilistSetupWindow: () => void;
clearAnilistSetupWindow: () => void;
destroyJellyfinSetupWindow: () => void;
clearJellyfinSetupWindow: () => void;
destroyFirstRunSetupWindow: () => void;
clearFirstRunSetupWindow: () => void;
destroyYomitanSettingsWindow: () => void;
clearYomitanSettingsWindow: () => void;
stopJellyfinRemoteSession: () => void;
cleanupInternalSubtitleTrackCache: () => void;
cleanupYoutubeSubtitleTempDirs: () => void;
cleanupYoutubeMediaCache: () => void;
cleanupRemoteMediaWindows: () => void;
cleanupJellyfinSubtitleCache: () => void;
stopDiscordPresenceService: () => void;
}) {
return async (): Promise<void> => {
const cleanupErrors: unknown[] = [];
deps.destroyTray();
deps.stopConfigHotReload();
deps.restorePreviousSecondarySubVisibility();
deps.restoreMpvSubVisibility();
deps.unregisterAllGlobalShortcuts();
deps.stopSubtitleWebsocket();
deps.stopTexthookerService();
const stopSyncAutoScheduler = Promise.resolve(deps.stopSyncAutoScheduler()).catch(
(error: unknown) => {
cleanupErrors.push(error);
},
);
deps.clearWindowsVisibleOverlayForegroundPollLoop();
deps.clearLinuxMpvFullscreenOverlayRefreshTimeouts();
deps.destroyMainOverlayWindow();
deps.destroyModalOverlayWindow();
deps.destroyYomitanParserWindow();
deps.clearYomitanParserState();
deps.stopWindowTracker();
deps.flushMpvLog();
deps.destroyMpvSocket();
deps.clearReconnectTimer();
deps.destroySubtitleTimingTracker();
await deps.destroyImmersionTracker();
deps.destroyAnkiIntegration();
deps.destroyAnilistSetupWindow();
deps.clearAnilistSetupWindow();
deps.destroyJellyfinSetupWindow();
deps.clearJellyfinSetupWindow();
deps.destroyFirstRunSetupWindow();
deps.clearFirstRunSetupWindow();
deps.destroyYomitanSettingsWindow();
deps.clearYomitanSettingsWindow();
const runCleanup = (cleanup: () => void): void => {
try {
cleanup();
} catch (error) {
cleanupErrors.push(error);
}
};
try {
runCleanup(deps.stopJellyfinRemoteSession);
runCleanup(deps.cleanupJellyfinSubtitleCache);
runCleanup(deps.cleanupInternalSubtitleTrackCache);
} finally {
runCleanup(deps.cleanupYoutubeSubtitleTempDirs);
runCleanup(deps.cleanupYoutubeMediaCache);
runCleanup(deps.cleanupRemoteMediaWindows);
runCleanup(deps.stopDiscordPresenceService);
await stopSyncAutoScheduler;
}
if (cleanupErrors.length > 0) throw cleanupErrors[0];
};
}
export function createShouldRestoreWindowsOnActivateHandler(deps: {
isOverlayRuntimeInitialized: () => boolean;
getAllWindowCount: () => number;
}) {
return (): boolean => deps.isOverlayRuntimeInitialized() && deps.getAllWindowCount() === 0;
}
export function createRestoreWindowsOnActivateHandler(deps: {
createMainWindow: () => void;
updateVisibleOverlayVisibility: () => void;
syncOverlayMpvSubtitleSuppression: () => void;
}) {
return (): void => {
deps.createMainWindow();
deps.updateVisibleOverlayVisibility();
deps.syncOverlayMpvSubtitleSuppression();
};
}