mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
feat(overlay): discover unclaimed mpv key bindings (#246)
This commit is contained in:
1 parent
e6dc9dfec5
commit
7c1eac03dc
21 files changed
+674
-5
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type { Keybinding } from '../../types';
|
||||
import { parseSessionBindingKey } from '../../core/services/session-bindings';
|
||||
import { parseMpvInputBindingKeys } from '../../shared/mpv-input-bindings';
|
||||
import type { MpvInputBindingsSnapshot } from '../../types/session-bindings';
|
||||
|
||||
export async function readMpvInputBindings(deps: {
|
||||
getMpvClient: () => {
|
||||
connected: boolean;
|
||||
requestProperty: (name: string) => Promise<unknown>;
|
||||
} | null;
|
||||
getConfiguredKeybindings: () => Keybinding[];
|
||||
platform: 'darwin' | 'win32' | 'linux';
|
||||
}): Promise<MpvInputBindingsSnapshot> {
|
||||
const blockedKeys = deps.getConfiguredKeybindings().flatMap((binding) => {
|
||||
const { key } = parseSessionBindingKey(binding.key, deps.platform);
|
||||
return key ? [key] : [];
|
||||
});
|
||||
const client = deps.getMpvClient();
|
||||
if (!client?.connected) return { keys: [], blockedKeys };
|
||||
try {
|
||||
const value = await client.requestProperty('input-bindings');
|
||||
return {
|
||||
keys:
|
||||
client === deps.getMpvClient() && client.connected ? parseMpvInputBindingKeys(value) : [],
|
||||
blockedKeys,
|
||||
};
|
||||
} catch {
|
||||
// Older mpv versions and disconnected sessions retain SubMiner's controls.
|
||||
return { keys: [], blockedKeys };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user