mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-10 15:13:32 -07:00
feat(aniskip): move intro detection from mpv plugin to app runtime (#117)
This commit is contained in:
@@ -56,6 +56,7 @@ const HOT_RELOAD_ROOTS = ['subtitleStyle', 'keybindings', 'shortcuts', 'subtitle
|
||||
|
||||
const HOT_RELOAD_EXACT_OR_PREFIX_PATHS = [
|
||||
'secondarySub.defaultMode',
|
||||
'mpv.aniskipEnabled',
|
||||
'mpv.aniskipButtonKey',
|
||||
'ankiConnect.ai.enabled',
|
||||
'stats.toggleKey',
|
||||
|
||||
@@ -350,3 +350,21 @@ test('visibility and boolean parsers handle text values', () => {
|
||||
assert.equal(asBoolean('yes', false), true);
|
||||
assert.equal(asBoolean('0', true), false);
|
||||
});
|
||||
|
||||
test('dispatchMpvProtocolMessage emits client-message string args', async () => {
|
||||
const received: Array<{ args: string[] }> = [];
|
||||
const { deps } = createDeps({
|
||||
emitClientMessage: (payload) => {
|
||||
received.push(payload);
|
||||
},
|
||||
});
|
||||
|
||||
await dispatchMpvProtocolMessage(
|
||||
{ event: 'client-message', args: ['subminer-skip-intro', 42, 'extra'] },
|
||||
deps,
|
||||
);
|
||||
await dispatchMpvProtocolMessage({ event: 'client-message', args: [] }, deps);
|
||||
await dispatchMpvProtocolMessage({ event: 'client-message' }, deps);
|
||||
|
||||
assert.deepEqual(received, [{ args: ['subminer-skip-intro', 'extra'] }]);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ export type MpvMessage = {
|
||||
event?: string;
|
||||
name?: string;
|
||||
data?: unknown;
|
||||
args?: unknown;
|
||||
request_id?: number;
|
||||
error?: string;
|
||||
};
|
||||
@@ -94,6 +95,7 @@ export interface MpvProtocolHandleMessageDeps {
|
||||
restorePreviousSecondarySubVisibility: () => void;
|
||||
shouldQuitOnMpvShutdown: () => boolean;
|
||||
requestAppQuit: () => void;
|
||||
emitClientMessage?: (payload: { args: string[] }) => void;
|
||||
}
|
||||
|
||||
type SubtitleTrackCandidate = {
|
||||
@@ -376,6 +378,13 @@ export async function dispatchMpvProtocolMessage(
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (msg.event === 'client-message') {
|
||||
const args = Array.isArray(msg.args)
|
||||
? msg.args.filter((arg): arg is string => typeof arg === 'string')
|
||||
: [];
|
||||
if (args.length > 0) {
|
||||
deps.emitClientMessage?.({ args });
|
||||
}
|
||||
} else if (msg.event === 'shutdown') {
|
||||
deps.restorePreviousSecondarySubVisibility();
|
||||
if (deps.shouldQuitOnMpvShutdown()) {
|
||||
|
||||
@@ -129,6 +129,7 @@ export interface MpvIpcClientEventMap {
|
||||
'media-title-change': { title: string | null };
|
||||
'subtitle-metrics-change': { patch: Partial<MpvSubtitleRenderMetrics> };
|
||||
'secondary-subtitle-visibility': { visible: boolean };
|
||||
'client-message': { args: string[] };
|
||||
}
|
||||
|
||||
type MpvIpcClientEventName = keyof MpvIpcClientEventMap;
|
||||
@@ -491,6 +492,9 @@ export class MpvIpcClient implements MpvClient {
|
||||
},
|
||||
shouldQuitOnMpvShutdown: () => this.deps.shouldQuitOnMpvShutdown?.() ?? false,
|
||||
requestAppQuit: () => this.deps.requestAppQuit?.(),
|
||||
emitClientMessage: (payload) => {
|
||||
this.emit('client-message', payload);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user