feat: add mark-as-watched keybinding and Yomitan lookup tracking

Add configurable keybinding to mark the current video as watched with
IPC plumbing between renderer and main process. Add event listener
infrastructure for tracking Yomitan dictionary lookups per session.
This commit is contained in:
2026-03-17 19:52:43 -07:00
parent 75f2c212c7
commit a5a6426fe1
12 changed files with 222 additions and 3 deletions

View File

@@ -192,6 +192,25 @@ export function createKeyboardHandlers(
);
}
function isMarkWatchedKey(e: KeyboardEvent): boolean {
return (
e.code === ctx.state.markWatchedKey &&
!e.ctrlKey &&
!e.altKey &&
!e.metaKey &&
!e.shiftKey &&
!e.repeat
);
}
async function handleMarkWatched(): Promise<void> {
const marked = await window.electronAPI.markActiveVideoWatched();
if (marked) {
window.electronAPI.sendMpvCommand(['show-text', 'Marked as watched', '1500']);
window.electronAPI.sendMpvCommand(['playlist-next', 'force']);
}
}
function getSubtitleWordNodes(): HTMLElement[] {
return Array.from(
ctx.dom.subtitleRoot.querySelectorAll<HTMLElement>('.word[data-token-index]'),
@@ -704,12 +723,14 @@ export function createKeyboardHandlers(
}
async function setupMpvInputForwarding(): Promise<void> {
const [keybindings, statsToggleKey] = await Promise.all([
const [keybindings, statsToggleKey, markWatchedKey] = await Promise.all([
window.electronAPI.getKeybindings(),
window.electronAPI.getStatsToggleKey(),
window.electronAPI.getMarkWatchedKey(),
]);
updateKeybindings(keybindings);
ctx.state.statsToggleKey = statsToggleKey;
ctx.state.markWatchedKey = markWatchedKey;
syncKeyboardTokenSelection();
const subtitleMutationObserver = new MutationObserver(() => {
@@ -811,6 +832,12 @@ export function createKeyboardHandlers(
return;
}
if (isMarkWatchedKey(e)) {
e.preventDefault();
void handleMarkWatched();
return;
}
if (
(ctx.state.yomitanPopupVisible || isYomitanPopupVisible(document)) &&
!isControllerModalShortcut(e)