mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): extract app-ready runtime dependencies helper
This commit is contained in:
81
src/main.ts
81
src/main.ts
@@ -158,6 +158,7 @@ import {
|
||||
} from "./core/services";
|
||||
import { runOverlayShortcutLocalFallback } from "./core/services/overlay-shortcut-handler";
|
||||
import { runAppReadyRuntimeService } from "./core/services/startup-service";
|
||||
import type { AppReadyRuntimeDeps } from "./core/services/startup-service";
|
||||
import {
|
||||
applyRuntimeOptionResultRuntimeService,
|
||||
cycleRuntimeOptionFromIpcRuntimeService,
|
||||
@@ -640,7 +641,48 @@ function createAppLifecycleRuntimeDeps(): AppLifecycleDepsRuntimeOptions {
|
||||
printHelp: () => printHelp(DEFAULT_TEXTHOOKER_PORT),
|
||||
logNoRunningInstance: () => appLogger.logNoRunningInstance(),
|
||||
onReady: async () => {
|
||||
await runAppReadyRuntimeService({
|
||||
await runAppReadyRuntimeService(createAppReadyRuntimeDeps());
|
||||
},
|
||||
onWillQuitCleanup: () => {
|
||||
restorePreviousSecondarySubVisibility();
|
||||
globalShortcut.unregisterAll();
|
||||
subtitleWsService.stop();
|
||||
texthookerService.stop();
|
||||
if (appState.yomitanParserWindow && !appState.yomitanParserWindow.isDestroyed()) {
|
||||
appState.yomitanParserWindow.destroy();
|
||||
}
|
||||
appState.yomitanParserWindow = null;
|
||||
appState.yomitanParserReadyPromise = null;
|
||||
appState.yomitanParserInitPromise = null;
|
||||
if (appState.windowTracker) {
|
||||
appState.windowTracker.stop();
|
||||
}
|
||||
if (appState.mpvClient && appState.mpvClient.socket) {
|
||||
appState.mpvClient.socket.destroy();
|
||||
}
|
||||
if (appState.reconnectTimer) {
|
||||
clearTimeout(appState.reconnectTimer);
|
||||
}
|
||||
if (appState.subtitleTimingTracker) {
|
||||
appState.subtitleTimingTracker.destroy();
|
||||
}
|
||||
if (appState.ankiIntegration) {
|
||||
appState.ankiIntegration.destroy();
|
||||
}
|
||||
},
|
||||
shouldRestoreWindowsOnActivate: () =>
|
||||
appState.overlayRuntimeInitialized && BrowserWindow.getAllWindows().length === 0,
|
||||
restoreWindowsOnActivate: () => {
|
||||
createMainWindow();
|
||||
createInvisibleWindow();
|
||||
updateVisibleOverlayVisibility();
|
||||
updateInvisibleOverlayVisibility();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createAppReadyRuntimeDeps(): AppReadyRuntimeDeps {
|
||||
return {
|
||||
loadSubtitlePosition: () => loadSubtitlePosition(),
|
||||
resolveKeybindings: () => {
|
||||
appState.keybindings = resolveKeybindings(getResolvedConfig(), DEFAULT_KEYBINDINGS);
|
||||
@@ -698,43 +740,6 @@ function createAppLifecycleRuntimeDeps(): AppLifecycleDepsRuntimeOptions {
|
||||
shouldAutoInitializeOverlayRuntimeFromConfig(),
|
||||
initializeOverlayRuntime: () => initializeOverlayRuntime(),
|
||||
handleInitialArgs: () => handleInitialArgs(),
|
||||
});
|
||||
},
|
||||
onWillQuitCleanup: () => {
|
||||
restorePreviousSecondarySubVisibility();
|
||||
globalShortcut.unregisterAll();
|
||||
subtitleWsService.stop();
|
||||
texthookerService.stop();
|
||||
if (appState.yomitanParserWindow && !appState.yomitanParserWindow.isDestroyed()) {
|
||||
appState.yomitanParserWindow.destroy();
|
||||
}
|
||||
appState.yomitanParserWindow = null;
|
||||
appState.yomitanParserReadyPromise = null;
|
||||
appState.yomitanParserInitPromise = null;
|
||||
if (appState.windowTracker) {
|
||||
appState.windowTracker.stop();
|
||||
}
|
||||
if (appState.mpvClient && appState.mpvClient.socket) {
|
||||
appState.mpvClient.socket.destroy();
|
||||
}
|
||||
if (appState.reconnectTimer) {
|
||||
clearTimeout(appState.reconnectTimer);
|
||||
}
|
||||
if (appState.subtitleTimingTracker) {
|
||||
appState.subtitleTimingTracker.destroy();
|
||||
}
|
||||
if (appState.ankiIntegration) {
|
||||
appState.ankiIntegration.destroy();
|
||||
}
|
||||
},
|
||||
shouldRestoreWindowsOnActivate: () =>
|
||||
appState.overlayRuntimeInitialized && BrowserWindow.getAllWindows().length === 0,
|
||||
restoreWindowsOnActivate: () => {
|
||||
createMainWindow();
|
||||
createInvisibleWindow();
|
||||
updateVisibleOverlayVisibility();
|
||||
updateInvisibleOverlayVisibility();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user