mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-20 12:11:28 -07:00
feat(core): add Electron runtime, services, and app composition
This commit is contained in:
50
src/main/runtime/startup-warmups.ts
Normal file
50
src/main/runtime/startup-warmups.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export function createLaunchBackgroundWarmupTaskHandler(deps: {
|
||||
now: () => number;
|
||||
logDebug: (message: string) => void;
|
||||
logWarn: (message: string) => void;
|
||||
}) {
|
||||
return (label: string, task: () => Promise<void>): void => {
|
||||
const startedAtMs = deps.now();
|
||||
void task()
|
||||
.then(() => {
|
||||
deps.logDebug(`[startup-warmup] ${label} completed in ${deps.now() - startedAtMs}ms`);
|
||||
})
|
||||
.catch((error) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
deps.logWarn(`[startup-warmup] ${label} failed: ${message}`);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function createStartBackgroundWarmupsHandler(deps: {
|
||||
getStarted: () => boolean;
|
||||
setStarted: (started: boolean) => void;
|
||||
isTexthookerOnlyMode: () => boolean;
|
||||
launchTask: (label: string, task: () => Promise<void>) => void;
|
||||
createMecabTokenizerAndCheck: () => Promise<void>;
|
||||
ensureYomitanExtensionLoaded: () => Promise<void>;
|
||||
prewarmSubtitleDictionaries: () => Promise<void>;
|
||||
shouldAutoConnectJellyfinRemote: () => boolean;
|
||||
startJellyfinRemoteSession: () => Promise<void>;
|
||||
}) {
|
||||
return (): void => {
|
||||
if (deps.getStarted()) return;
|
||||
if (deps.isTexthookerOnlyMode()) return;
|
||||
|
||||
deps.setStarted(true);
|
||||
deps.launchTask('mecab', async () => {
|
||||
await deps.createMecabTokenizerAndCheck();
|
||||
});
|
||||
deps.launchTask('yomitan-extension', async () => {
|
||||
await deps.ensureYomitanExtensionLoaded();
|
||||
});
|
||||
deps.launchTask('subtitle-dictionaries', async () => {
|
||||
await deps.prewarmSubtitleDictionaries();
|
||||
});
|
||||
if (deps.shouldAutoConnectJellyfinRemote()) {
|
||||
deps.launchTask('jellyfin-remote-session', async () => {
|
||||
await deps.startJellyfinRemoteSession();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user