Skip to content

Commit

Permalink
Improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Apr 5, 2024
1 parent 3baf2b6 commit 5b80cf9
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,21 @@ internal class SR2Controller private constructor(
val future =
connection.openURL(resolvedURL.toString())
.handle { _, exception ->
this.debug("Failed to completely open URL: ", exception)
if (exception != null) {
this.debug("Failed to completely open URL: ", exception)
}
}.thenCompose {
connection.executeJS { js -> js.setScrollMode(this.configuration.scrollingMode) }
}.handle { _, exception ->
this.debug("Failed to set scroll mode: ", exception)
if (exception != null) {
this.debug("Failed to set scroll mode: ", exception)
}
}.thenCompose {
this.executeLocatorSet(connection, this.currentNavigationIntent)
}.handle { _, exception ->
this.debug("Failed to scroll to navigation intent: ", exception)
if (exception != null) {
this.debug("Failed to scroll to navigation intent: ", exception)
}
}

/*
Expand All @@ -677,6 +683,10 @@ internal class SR2Controller private constructor(
else ->
future.thenCompose {
connection.executeJS { js -> js.scrollToId(fragment) }
}.handle { _, exception ->
if (exception != null) {
this.debug("Failed to scroll to fragment ID: ", exception)
}
}
}
} catch (e: Exception) {
Expand Down Expand Up @@ -775,22 +785,26 @@ internal class SR2Controller private constructor(
private val webView: WebView,
) : SR2JavascriptAPIReceiverType {

private val logger =
LoggerFactory.getLogger(JavascriptAPIReceiver::class.java)

@android.webkit.JavascriptInterface
override fun onReadingPositionChanged(
chapterProgress: Double,
currentPage: Int,
pageCount: Int,
) {
val controller = this@SR2Controller
controller.debug(
"onReadingPositionChanged: {} {} {}",
chapterProgress,
currentPage,
pageCount,
)

/*
* If the controller is indicating that the user explicitly performed some kind of
* navigation action, then this reading position update should be used to update the
* navigation intent. Typically, this _only_ applies for page turns.
*/

val controller = this@SR2Controller
if (controller.updateNavigationIntentOnNextChapterProgressUpdate.compareAndSet(true, false)) {
controller.debug("Navigation: Updating intent from reading position change.")
controller.setCurrentNavigationIntent(
Expand Down Expand Up @@ -867,7 +881,7 @@ internal class SR2Controller private constructor(

@android.webkit.JavascriptInterface
override fun onRightTapped() {
this.logger.debug("onRightTapped")
this@SR2Controller.debug("onRightTapped")

return when (this@SR2Controller.publication.metadata.presentation.layout) {
FIXED ->
Expand All @@ -880,7 +894,7 @@ internal class SR2Controller private constructor(

@android.webkit.JavascriptInterface
override fun onLeftSwiped() {
this.logger.debug("onLeftSwiped")
this@SR2Controller.debug("onLeftSwiped")

return when (this@SR2Controller.publication.metadata.presentation.layout) {
FIXED ->
Expand All @@ -893,7 +907,7 @@ internal class SR2Controller private constructor(

@android.webkit.JavascriptInterface
override fun onRightSwiped() {
this.logger.debug("onRightSwiped")
this@SR2Controller.debug("onRightSwiped")

return when (this@SR2Controller.publication.metadata.presentation.layout) {
FIXED ->
Expand Down

0 comments on commit 5b80cf9

Please sign in to comment.