fix: various fixes on text selector in TTS mode and normal image height (#1390)

This commit is contained in:
Huang Xin
2025-06-13 23:28:21 +08:00
committed by GitHub
parent 20955ec294
commit 467e80cd4b
8 changed files with 228 additions and 50 deletions
@@ -108,8 +108,8 @@ const FooterBar: React.FC<FooterBarProps> = ({
};
const handleSpeakText = async () => {
if (!view || !progress) return;
if (eventDispatcher.dispatchSync('tts-is-speaking')) {
if (!view || !progress || !viewState) return;
if (viewState.ttsEnabled) {
eventDispatcher.dispatch('tts-stop', { bookKey });
} else {
eventDispatcher.dispatch('tts-speak', { bookKey });
@@ -32,10 +32,11 @@ const TOCView: React.FC<{
bookKey: string;
toc: TOCItem[];
}> = ({ bookKey, toc }) => {
const { getView, getProgress, getViewSettings } = useReaderStore();
const { getView, getProgress, getViewState, getViewSettings } = useReaderStore();
const { sideBarBookKey, isSideBarVisible } = useSidebarStore();
const viewSettings = getViewSettings(bookKey)!;
const progress = getProgress(bookKey);
const viewState = getViewState(bookKey);
const [expandedItems, setExpandedItems] = useState<Set<string>>(new Set());
const [containerHeight, setContainerHeight] = useState(400);
@@ -150,7 +151,7 @@ const TOCView: React.FC<{
);
useEffect(() => {
if (!progress || eventDispatcher.dispatchSync('tts-is-speaking')) return;
if (!progress || viewState?.ttsEnabled) return;
if (sideBarBookKey !== bookKey) return;
if (!isSideBarVisible) return;
@@ -158,7 +159,7 @@ const TOCView: React.FC<{
if (currentHref) {
expandParents(toc, currentHref);
}
}, [toc, progress, sideBarBookKey, isSideBarVisible, bookKey, expandParents]);
}, [toc, progress, viewState, sideBarBookKey, isSideBarVisible, bookKey, expandParents]);
useEffect(() => {
if (flatItems.length > 0) {
@@ -99,11 +99,9 @@ const TTSControl = () => {
useEffect(() => {
eventDispatcher.on('tts-speak', handleTTSSpeak);
eventDispatcher.on('tts-stop', handleTTSStop);
eventDispatcher.onSync('tts-is-speaking', handleQueryIsSpeaking);
return () => {
eventDispatcher.off('tts-speak', handleTTSSpeak);
eventDispatcher.off('tts-stop', handleTTSStop);
eventDispatcher.offSync('tts-is-speaking', handleQueryIsSpeaking);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -238,10 +236,6 @@ const TTSControl = () => {
}
};
const handleQueryIsSpeaking = () => {
return !!ttsControllerRef.current;
};
const handleTogglePlay = async () => {
const ttsController = ttsControllerRef.current;
if (!ttsController) return;