Skip to content

Commit

Permalink
Progress Timber migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Slion committed Sep 21, 2023
1 parent 1105cd9 commit 9ab7ef3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
18 changes: 7 additions & 11 deletions app/src/main/java/acr/browser/lightning/browser/TabsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package acr.browser.lightning.browser
import acr.browser.lightning.R
import acr.browser.lightning.browser.sessions.Session
import acr.browser.lightning.extensions.snackbar
import acr.browser.lightning.log.Logger
import acr.browser.lightning.search.SearchEngineProvider
import acr.browser.lightning.settings.NewTabPosition
import acr.browser.lightning.settings.preferences.UserPreferences
Expand Down Expand Up @@ -39,8 +38,7 @@ class TabsManager @Inject constructor(
private val historyPageInitializer: HistoryPageInitializer,
private val downloadPageInitializer: DownloadPageInitializer,
private val noOpPageInitializer: NoOpInitializer,
private val userPreferences: UserPreferences,
private val logger: Logger,
private val userPreferences: UserPreferences
): fulguris.Component() {

private val tabList = arrayListOf<LightningView>()
Expand Down Expand Up @@ -442,7 +440,7 @@ class TabsManager @Inject constructor(
restorePreviousTabs()
} catch (ex: Throwable) {
// TODO: report this using firebase or local crash logs
logger.log(TAG, ex.toString())
Timber.e(ex,"restorePreviousTabs failed")
activity.snackbar(R.string.error_recovery_session)
createRecoverySession()
}
Expand Down Expand Up @@ -568,7 +566,7 @@ class TabsManager @Inject constructor(
isIncognito: Boolean,
newTabPosition: NewTabPosition
): LightningView {
logger.log(TAG, "New tab")
Timber.i("New tab")
val tab = LightningView(
activity,
tabInitializer,
Expand All @@ -577,8 +575,7 @@ class TabsManager @Inject constructor(
incognitoPageInitializer,
bookmarkPageInitializer,
downloadPageInitializer,
historyPageInitializer,
logger
historyPageInitializer
)

// Add our new tab at the specified position
Expand Down Expand Up @@ -620,7 +617,7 @@ class TabsManager @Inject constructor(
* @return returns true if the current tab was deleted, false otherwise.
*/
fun deleteTab(position: Int): Boolean {
logger.log(TAG, "Delete tab: $position")
Timber.i("Delete tab: $position")
val currentTab = currentTab
val current = positionOf(currentTab)

Expand Down Expand Up @@ -829,7 +826,7 @@ class TabsManager @Inject constructor(
*/
private fun recoverSessions() {
// TODO: report this in firebase or local logs
logger.log(TAG, "recoverSessions")
Timber.i("recoverSessions")
//
iSessions.clear() // Defensive, should already be empty if we get there
// Search for session files
Expand Down Expand Up @@ -885,7 +882,7 @@ class TabsManager @Inject constructor(
* @return The selected tab we just switched to.
*/
fun switchToTab(aPosition: Int): LightningView {
logger.log(TAG, "switch to tab: $aPosition")
Timber.i("switch to tab: $aPosition")
return tabList[aPosition].also {
currentTab = it
// Put that tab at the top of our recent tab list
Expand All @@ -907,7 +904,6 @@ class TabsManager @Inject constructor(

companion object {

private const val TAG = "TabsManager"
private const val TAB_KEY_PREFIX = "TAB_"
// Preserve this file name for compatibility
private const val FILENAME_SESSION_DEFAULT = "SAVED_TABS.parcel"
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/acr/browser/lightning/view/LightningView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class LightningView(
private val incognitoPageInitializer: IncognitoPageInitializer,
private val bookmarkPageInitializer: BookmarkPageInitializer,
private val downloadPageInitializer: DownloadPageInitializer,
private val historyPageInitializer: HistoryPageInitializer,
private val logger: Logger
private val historyPageInitializer: HistoryPageInitializer
): WebView.FindListener,
SharedPreferences.OnSharedPreferenceChangeListener {

Expand Down Expand Up @@ -566,7 +565,7 @@ class LightningView(
} catch (e: Exception) {
// This shouldn't be necessary, but there are a number
// of KitKat devices that crash trying to set this
logger.log(TAG, "Problem setting LayoutAlgorithm to TEXT_AUTOSIZING")
Timber.e(e,"Problem setting LayoutAlgorithm to TEXT_AUTOSIZING")
}
} else {
settings.layoutAlgorithm = LayoutAlgorithm.NORMAL
Expand Down Expand Up @@ -760,15 +759,15 @@ class LightningView(
*/
fun onPause() {
webView?.onPause()
logger.log(TAG, "WebView onPause: ${webView?.id}")
Timber.d("WebView onPause: ${webView?.id}")
}

/**
* Resume the current WebView instance.
*/
fun onResume() {
webView?.onResume()
logger.log(TAG, "WebView onResume: ${webView?.id}")
Timber.d("WebView onResume: ${webView?.id}")
}

/**
Expand Down Expand Up @@ -874,7 +873,7 @@ class LightningView(
*/
fun pauseTimers() {
webView?.pauseTimers()
logger.log(TAG, "Pausing JS timers")
Timber.d("Pausing JS timers")
}

/**
Expand All @@ -884,7 +883,7 @@ class LightningView(
*/
fun resumeTimers() {
webView?.resumeTimers()
logger.log(TAG, "Resuming JS timers")
Timber.d("Resuming JS timers")
}

/**
Expand Down Expand Up @@ -1352,8 +1351,6 @@ class LightningView(
public const val KHtmlMetaThemeColorInvalid: Int = Color.TRANSPARENT
public const val KFetchMetaThemeColorTries: Int = 6

private const val TAG = "LightningView"

const val HEADER_REQUESTED_WITH = "X-Requested-With"
const val HEADER_WAP_PROFILE = "X-Wap-Profile"
private const val HEADER_DNT = "DNT"
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/java/acr/browser/lightning/view/LightningWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import acr.browser.lightning.html.homepage.HomePageFactory
import acr.browser.lightning.js.InvertPage
import acr.browser.lightning.js.SetMetaViewport
import acr.browser.lightning.js.TextReflow
import acr.browser.lightning.log.Logger
import acr.browser.lightning.settings.NoYesAsk
import acr.browser.lightning.settings.preferences.DomainPreferences
import acr.browser.lightning.settings.preferences.UserPreferences
Expand Down Expand Up @@ -74,7 +73,6 @@ class LightningWebClient(
val userPreferences: UserPreferences = hiltEntryPoint.userPreferences
val preferences: SharedPreferences = hiltEntryPoint.userSharedPreferences()
val sslWarningPreferences: SslWarningPreferences = hiltEntryPoint.sslWarningPreferences
val logger: Logger = hiltEntryPoint.logger
val textReflowJs: TextReflow = hiltEntryPoint.textReflowJs
val invertPageJs: InvertPage = hiltEntryPoint.invertPageJs
val setMetaViewport: SetMetaViewport = hiltEntryPoint.setMetaViewport
Expand Down Expand Up @@ -139,8 +137,8 @@ class LightningWebClient(
// See: https://stackoverflow.com/a/60621350/3969362
// See: https://stackoverflow.com/a/39642318/3969362
// Just pass on user defined viewport width in percentage of the actual viewport to the JavaScript
logger.log(TAG, "JavaScript Desktop Mode Hack")
aView.settings.useWideViewPort = true;
Timber.i("JavaScript Desktop Mode Hack")
aView.settings.useWideViewPort = true
aView.evaluateJavascript(setMetaViewport.provideJs().replaceFirst("\$width\$","${aView.context.configPrefs.desktopWidth}"), null)
}
}
Expand Down Expand Up @@ -329,7 +327,7 @@ class LightningWebClient(
val user = name.text.toString()
val pass = password.text.toString()
handler.proceed(user.trim(), pass.trim())
logger.log(TAG, "Attempting HTTP Authentication")
Timber.i("Attempting HTTP Authentication")
}
setNegativeButton(R.string.action_cancel) { _, _ ->
handler.cancel()
Expand Down Expand Up @@ -643,7 +641,7 @@ class LightningWebClient(
try {
activity.startActivity(intent)
} catch (e: ActivityNotFoundException) {
logger.log(TAG, "ActivityNotFoundException")
Timber.e(e, "ActivityNotFoundException")
}

return true
Expand Down Expand Up @@ -699,9 +697,4 @@ class LightningWebClient(
return errorCodeMessageCodes
}

companion object {

private const val TAG = "LightningWebClient"

}
}

0 comments on commit 9ab7ef3

Please sign in to comment.