Skip to content

Commit

Permalink
Fix reader bugs (LNReader#1212)
Browse files Browse the repository at this point in the history
* fix: tts algorithm

* update: turn off tts by default

* update default padding

* change tts transition to 500ms

* update reader body padding

* cleanup

* fix: throw Exception
  • Loading branch information
nyagami committed Aug 15, 2024
1 parent 1131446 commit 86c82c1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
5 changes: 2 additions & 3 deletions android/app/src/main/assets/css/index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
html {
scroll-behavior: smooth;
overflow-x: hidden;
padding-top: var(--StatusBar-currentHeight);
word-wrap: break-word;
}

Expand All @@ -19,6 +18,7 @@ body {
margin-left: 0;
margin-right: 0;
padding-bottom: 40px;
padding-top: var(--StatusBar-currentHeight);

font-size: var(--readerSettings-textSize);
background-color: var(--readerSettings-theme);
Expand All @@ -30,7 +30,6 @@ body {

body.page-reader {
overflow: hidden;
padding: 0;
}

#LNReader-chapter {
Expand Down Expand Up @@ -344,7 +343,7 @@ td {
align-items: center;
padding: 4px;
border-radius: 100%;
transition: 1s;
transition: .5s;
}

#TTS-Controller.active{
Expand Down
45 changes: 21 additions & 24 deletions android/app/src/main/assets/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ window.reader = new (function () {

//layout props
this.paddingTop = parseInt(
getComputedStyle(document.querySelector('html')).getPropertyValue(
getComputedStyle(document.querySelector('body')).getPropertyValue(
'padding-top',
),
10,
Expand Down Expand Up @@ -162,15 +162,13 @@ window.tts = new (function () {

// if can find a readable node, else stop tts
this.findNextTextNode = () => {
if (!this.started) {
this.started = true;
if (this.readable()) {
return true;
}
} else if (this.currentElement.isSameNode(reader.chapterElement)) {
if (this.currentElement.isSameNode(reader.chapterElement) && this.started) {
return false;
} else {
this.started = true;
}
// node is read -> next node or parent node

// is read, have to go next or go back
if (this.currentElement.isSameNode(this.prevElement)) {
this.prevElement = this.currentElement;
if (this.currentElement.nextElementSibling) {
Expand All @@ -179,28 +177,27 @@ window.tts = new (function () {
this.currentElement = this.currentElement.parentElement;
}
return this.findNextTextNode();
}

if (this.readable()) {
return true;
}
if (this.prevElement?.parentElement.isSameNode(this.currentElement)) {
// is backtracking
this.prevElement = this.currentElement;
if (this.currentElement.nextElementSibling) {
} else {
// can read? read it
if (this.readable()) {
return true;
}
if (
!this.prevElement?.parentElement?.isSameNode(this.currentElement) &&
this.currentElement.firstElementChild
) {
// go deep
this.prevElement = this.currentElement;
this.currentElement = this.currentElement.firstElementChild;
} else if (this.currentElement.nextElementSibling) {
this.prevElement = this.currentElement;
this.currentElement = this.currentElement.nextElementSibling;
} else {
this.prevElement = this.currentElement;
this.currentElement = this.currentElement.parentElement;
}
return this.findNextTextNode();
}
if (this.currentElement.firstElementChild) {
// go deeper
this.prevElement = this.currentElement;
this.currentElement = this.currentElement.firstElementChild;
return this.findNextTextNode();
}
return false;
};

this.next = () => {
Expand Down
3 changes: 1 addition & 2 deletions android/app/src/main/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ const TTSController = () => {
return div(
{
id: 'TTS-Controller',
class: () =>
`${reader.generalSettings.val.TTSEnable === false ? 'hidden' : ''}`,
class: () => `${reader.generalSettings.val.TTSEnable ? '' : 'hidden'}`,
ontouchstart: () => {
if (!controllerElement) {
controllerElement = document.getElementById('TTS-Controller');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class EpubUtil(context: ReactApplicationContext) : ReactContextBaseJavaModule(co
if (tocFile.exists()) {
val tocParser = initParse(tocFile)
var label = ""
while(tocParser.next() != XmlPullParser.END_DOCUMENT){
if(tocParser.name == "navMap") break;
while (tocParser.next() != XmlPullParser.END_DOCUMENT) {
if (tocParser.name == "navMap") break
}
while (tocParser.next() != XmlPullParser.END_DOCUMENT) {
val tag = tocParser.name
if(tag == "navMap") break;
if (tag == "navMap") break
if (tag != null) {
if (tag == "text") {
label = readText(tocParser)
Expand All @@ -143,7 +143,7 @@ class EpubUtil(context: ReactApplicationContext) : ReactContextBaseJavaModule(co
}
}
} else {
throw Error("Table of content doesn't exist!")
throw Exception("Table of content (toc.ncx) does not exist!")
}
var cover: String? = null
while (parser.next() != XmlPullParser.END_DOCUMENT) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/persisted/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ export const initialChapterGeneralSettings: ChapterGeneralSettings = {
removeExtraParagraphSpacing: false,
bionicReading: false,
tapToScroll: false,
TTSEnable: true,
TTSEnable: false,
};

export const initialChapterReaderSettings: ChapterReaderSettings = {
theme: '#292832',
textColor: '#CCCCCC',
textSize: 16,
textAlign: 'left',
padding: 4,
padding: 16,
fontFamily: '',
lineHeight: 1.5,
customCSS: '',
Expand Down

0 comments on commit 86c82c1

Please sign in to comment.