Skip to content

Commit

Permalink
refactor(webview): ensure destroy and loadUrl methods run on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
rhenwinch committed Aug 27, 2024
1 parent 48563e1 commit fd5ff19
Showing 1 changed file with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.webkit.CookieManager
import android.webkit.WebStorage
import android.webkit.WebView
import androidx.annotation.MainThread
import com.flixclusive.core.util.common.dispatcher.AppDispatchers.Companion.launchOnMain

/**
*
Expand Down Expand Up @@ -53,45 +54,51 @@ abstract class WebViewDriver(
url: String,
headers: Map<String, String>
) {
super.loadUrl(url, headers)
launchOnMain {
super.loadUrl(url, headers)
}

if (!isHeadless) {
WebViewDriverManager.register(this)
}
}

override fun loadUrl(url: String) {
super.loadUrl(url)
launchOnMain {
super.loadUrl(url)
}

if (!isHeadless) {
WebViewDriverManager.register(this)
}
}

override fun destroy() {
if (shouldClearCache) {
clearCache(true)
}
if (shouldClearCookies) {
cookieManager?.removeAllCookies(null)
cookieManager?.flush()
}
if (shouldClearHistory) {
clearHistory()
}
if (shouldClearFormData) {
clearFormData()
}
if (shouldClearWebStorage) {
webStorage?.deleteAllData()
}
if (shouldClearSslPreferences) {
clearSslPreferences()
}
launchOnMain {
if (shouldClearCache) {
clearCache(true)
}
if (shouldClearCookies) {
cookieManager?.removeAllCookies(null)
cookieManager?.flush()
}
if (shouldClearHistory) {
clearHistory()
}
if (shouldClearFormData) {
clearFormData()
}
if (shouldClearWebStorage) {
webStorage?.deleteAllData()
}
if (shouldClearSslPreferences) {
clearSslPreferences()
}

stopLoading()
onPause()
super.destroy()
stopLoading()
onPause()
super.destroy()
}

if (!isHeadless) {
WebViewDriverManager.unregister()
Expand Down

0 comments on commit fd5ff19

Please sign in to comment.