mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-30 04:46:17 -08:00
feat(dictionary): add Hachidori backend support (#266)
This commit is contained in:
1 parent
e690ffba07
commit
cbaa4626e1
143 files changed
+5564
-305
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import type { ModalStateReader, RendererContext } from '../context';
|
||||
import { syncOverlayMouseIgnoreState } from '../overlay-mouse-ignore.js';
|
||||
import {
|
||||
YOMITAN_POPUP_HIDDEN_EVENT,
|
||||
YOMITAN_POPUP_MOUSE_ENTER_EVENT,
|
||||
YOMITAN_POPUP_MOUSE_LEAVE_EVENT,
|
||||
YOMITAN_POPUP_SHOWN_EVENT,
|
||||
registerDictionaryPopupVisibilityListener,
|
||||
registerYomitanLookupListener,
|
||||
PRIMARY_SUB_VISIBLE_ON_YOMITAN_POPUP_CLASS,
|
||||
isHachidoriPopupOpen,
|
||||
isYomitanPopupVisible,
|
||||
isYomitanPopupIframe,
|
||||
} from '../yomitan-popup.js';
|
||||
@@ -257,8 +258,20 @@ export function createMouseHandlers(
|
||||
options.sendMpvCommand(['set_property', 'pause', 'no']);
|
||||
}
|
||||
|
||||
// Hachidori also claims attention for a left press anywhere on the overlay
|
||||
// that may become a selection, so once its events identify the reader only
|
||||
// an open popup pane should pause playback.
|
||||
function canPauseForYomitanPopup(): boolean {
|
||||
return (
|
||||
yomitanPopupVisible &&
|
||||
options.getYomitanPopupAutoPauseEnabled() &&
|
||||
(!ctx.state.hachidoriReaderSeen ||
|
||||
(typeof document !== 'undefined' && isHachidoriPopupOpen(document)))
|
||||
);
|
||||
}
|
||||
|
||||
async function maybePauseForYomitanPopup(): Promise<void> {
|
||||
if (!yomitanPopupVisible || !options.getYomitanPopupAutoPauseEnabled()) {
|
||||
if (!canPauseForYomitanPopup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -278,11 +291,7 @@ export function createMouseHandlers(
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
requestId !== popupPauseRequestId ||
|
||||
!yomitanPopupVisible ||
|
||||
!options.getYomitanPopupAutoPauseEnabled()
|
||||
) {
|
||||
if (requestId !== popupPauseRequestId || !canPauseForYomitanPopup()) {
|
||||
return;
|
||||
}
|
||||
if (paused !== false) return;
|
||||
@@ -470,7 +479,8 @@ export function createMouseHandlers(
|
||||
function setupYomitanObserver(): void {
|
||||
reconcilePopupInteraction({ allowPause: true });
|
||||
|
||||
window.addEventListener(YOMITAN_POPUP_SHOWN_EVENT, () => {
|
||||
registerDictionaryPopupVisibilityListener('shown', (reader) => {
|
||||
if (reader === 'hachidori') ctx.state.hachidoriReaderSeen = true;
|
||||
reconcilePopupInteraction({
|
||||
assumeVisible: true,
|
||||
allowPause: true,
|
||||
@@ -478,10 +488,16 @@ export function createMouseHandlers(
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener(YOMITAN_POPUP_HIDDEN_EVENT, () => {
|
||||
registerDictionaryPopupVisibilityListener('hidden', () => {
|
||||
disablePopupInteractionIfIdle();
|
||||
});
|
||||
|
||||
// A Hachidori selection opens its popup while the drag's attention claim is
|
||||
// still held, so no second shown event arrives; its lookup marks the open.
|
||||
registerYomitanLookupListener(window, () => {
|
||||
reconcilePopupInteraction({ allowPause: true });
|
||||
});
|
||||
|
||||
window.addEventListener(YOMITAN_POPUP_MOUSE_ENTER_EVENT, () => {
|
||||
ctx.state.isOverYomitanPopup = true;
|
||||
reconcilePopupInteraction({ assumeVisible: true, reclaimFocus: true });
|
||||
|
||||
Reference in new issue
Block a user