Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions icon-src/feature-graphic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions icon-src/icon-background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions icon-src/icon-glyph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions icon-src/icon-monochrome.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions icon-src/icon-square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 17 additions & 4 deletions mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
"userInterfaceStyle": "light",
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.travelintime.app"
"bundleIdentifier": "com.travelintime.app",
"infoPlist": {
"ITSAppUsesNonExemptEncryption": false
}
},
"android": {
"package": "com.travelintime.app",
"adaptiveIcon": {
"backgroundColor": "#E6F4FE",
"backgroundColor": "#7a2e10",
"foregroundImage": "./assets/android-icon-foreground.png",
"backgroundImage": "./assets/android-icon-background.png",
"monochromeImage": "./assets/android-icon-monochrome.png"
},
"predictiveBackGestureEnabled": false
"predictiveBackGestureEnabled": false,
"blockedPermissions": [
"android.permission.SYSTEM_ALERT_WINDOW"
]
},
"web": {
"favicon": "./assets/favicon.png"
Expand All @@ -30,6 +36,13 @@
],
"experiments": {
"typedRoutes": true
}
},
"extra": {
"router": {},
"eas": {
"projectId": "016213f3-580c-4f9c-8f50-bdfd797e2f19"
}
},
"owner": "retsnom"
}
}
42 changes: 21 additions & 21 deletions mobile/app/reader/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ReaderScreen = () => {
const [listPanelTab, setListPanelTab] = useState<'bookmarks' | 'chapters' | 'bookinfo' | 'notes' | null>(null);
const settingsLoadedRef = useRef(false);
const hadSavedSettingsRef = useRef(false);
const chapterTextResolverRef = useRef<((text: string) => void) | null>(null);
const chapterTextResolverRef = useRef<((result: { text: string; startOffset: number }) => void) | null>(null);
const chapterTextTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const relocatedResolverRef = useRef<(() => void) | null>(null);
// 供 advanceToNextChapter 判斷「是否已經跨到新章節」/「是否已到書尾」,用 ref 而非
Expand Down Expand Up @@ -205,7 +205,7 @@ const ReaderScreen = () => {
clearTimeout(chapterTextTimeoutRef.current);
chapterTextTimeoutRef.current = null;
}
chapterTextResolverRef.current?.(msg.text);
chapterTextResolverRef.current?.({ text: msg.text, startOffset: msg.startOffset });
chapterTextResolverRef.current = null;
return;
}
Expand Down Expand Up @@ -258,14 +258,14 @@ const ReaderScreen = () => {
// 若已有一個 getChapterText 請求在飛行中,新請求直接回空字串,避免蓋掉前一個
// resolver 導致前一個呼叫永遠 resolve 不到正確結果;並用逾時保護 WebView 沒回應時
// 呼叫端不會卡死。
const requestChapterText = useCallback((): Promise<string> => {
if (chapterTextResolverRef.current) return Promise.resolve('');
const requestChapterText = useCallback((): Promise<{ text: string; startOffset: number }> => {
if (chapterTextResolverRef.current) return Promise.resolve({ text: '', startOffset: 0 });
return new Promise((resolve) => {
chapterTextResolverRef.current = resolve;
chapterTextTimeoutRef.current = setTimeout(() => {
chapterTextResolverRef.current = null;
chapterTextTimeoutRef.current = null;
resolve('');
resolve({ text: '', startOffset: 0 });
}, 5000);
webviewRef.current?.postMessage(JSON.stringify({ type: 'getChapterText' }));
});
Expand Down Expand Up @@ -312,19 +312,25 @@ const ReaderScreen = () => {
}, [waitForRelocated]);

const continueReadingRef = useRef<() => void>(() => {});
const readNextAndContinue = useCallback(async () => {
const advanced = await advanceToNextChapter();
if (!advanced) return;
const text = await requestChapterText();
if (!text.trim()) return;

const startSpeaking = useCallback((text: string, startOffset: number) => {
readingHrefRef.current = currentHrefRef.current;
webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsStart' }));
tts.speak(
text,
() => continueReadingRef.current(),
(charIndex) => webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsBoundary', charIndex }))
(charIndex) =>
webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsBoundary', charIndex: charIndex + startOffset }))
);
}, [advanceToNextChapter, requestChapterText, tts]);
}, [tts]);

const readNextAndContinue = useCallback(async () => {
const advanced = await advanceToNextChapter();
if (!advanced) return;
const { text, startOffset } = await requestChapterText();
if (!text.trim()) return;
startSpeaking(text, startOffset);
}, [advanceToNextChapter, requestChapterText, startSpeaking]);
useEffect(() => { continueReadingRef.current = readNextAndContinue; }, [readNextAndContinue]);

const handleTTSPlay = useCallback(async () => {
Expand All @@ -333,16 +339,10 @@ const ReaderScreen = () => {
webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsStart' }));
return;
}
const text = await requestChapterText();
const { text, startOffset } = await requestChapterText();
if (!text.trim()) return;
readingHrefRef.current = currentHrefRef.current;
webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsStart' }));
tts.speak(
text,
() => continueReadingRef.current(),
(charIndex) => webviewRef.current?.postMessage(JSON.stringify({ type: 'ttsBoundary', charIndex }))
);
}, [tts, requestChapterText]);
startSpeaking(text, startOffset);
}, [tts, requestChapterText, startSpeaking]);

const handleTTSPause = useCallback(() => {
tts.pause();
Expand Down
Binary file modified mobile/assets/android-icon-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mobile/assets/android-icon-foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mobile/assets/android-icon-monochrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mobile/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mobile/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mobile/assets/splash-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mobile/lib/readerHtml.generated.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mobile/lib/readerMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type OutboundMessage =
| { type: 'error'; message: string }
| { type: 'metaExtracted'; title: string; author: string; coverBase64: string | null; coverMediaType: string | null }
| { type: 'metaError'; message: string }
| { type: 'chapterText'; text: string }
| { type: 'chapterText'; text: string; startOffset: number }
| { type: 'bookLanguageDetected'; baseScript: Script }
| { type: 'tocLoaded'; toc: TocItem[] }
| { type: 'textSelected'; cfi: string; text: string }
Expand Down
Loading
Loading