mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 18:22:42 -08:00
feat(core): add Electron runtime, services, and app composition
This commit is contained in:
37
src/main/runtime/mpv-client-runtime-service.ts
Normal file
37
src/main/runtime/mpv-client-runtime-service.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { Config } from '../../types';
|
||||
|
||||
export type MpvClientRuntimeServiceOptions = {
|
||||
getResolvedConfig: () => Config;
|
||||
autoStartOverlay: boolean;
|
||||
setOverlayVisible: (visible: boolean) => void;
|
||||
shouldBindVisibleOverlayToMpvSubVisibility: () => boolean;
|
||||
isVisibleOverlayVisible: () => boolean;
|
||||
getReconnectTimer: () => ReturnType<typeof setTimeout> | null;
|
||||
setReconnectTimer: (timer: ReturnType<typeof setTimeout> | null) => void;
|
||||
};
|
||||
|
||||
type MpvClientLike = {
|
||||
connect: () => void;
|
||||
};
|
||||
|
||||
type MpvClientCtor<
|
||||
TClient extends MpvClientLike,
|
||||
TOptions extends MpvClientRuntimeServiceOptions,
|
||||
> = new (socketPath: string, options: TOptions) => TClient;
|
||||
|
||||
export function createMpvClientRuntimeServiceFactory<
|
||||
TClient extends MpvClientLike,
|
||||
TOptions extends MpvClientRuntimeServiceOptions,
|
||||
>(deps: {
|
||||
createClient: MpvClientCtor<TClient, TOptions>;
|
||||
socketPath: string;
|
||||
options: TOptions;
|
||||
bindEventHandlers: (client: TClient) => void;
|
||||
}) {
|
||||
return (): TClient => {
|
||||
const mpvClient = new deps.createClient(deps.socketPath, deps.options);
|
||||
deps.bindEventHandlers(mpvClient);
|
||||
mpvClient.connect();
|
||||
return mpvClient;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user