Skip to content

Commit

Permalink
fix: Webview User-Agent Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaIsrar12 committed Jul 15, 2024
1 parent a329826 commit e4726d2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class HeadersInterceptor(
}.build()
)
}
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ val appModule = module {
DownloadWorkerController(get(), get(), get())
}

single { AppData(versionName = BuildConfig.VERSION_NAME) }
single {
AppData(
versionName = BuildConfig.VERSION_NAME,
applicationId = BuildConfig.APPLICATION_ID,
)
}
factory { (activity: AppCompatActivity) -> AppReviewManager(activity, get(), get()) }

single { TranscriptManager(get()) }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ val screenModule = module {
get(),
)
}
viewModel { HtmlUnitViewModel(get(), get(), get(), get()) }
viewModel { HtmlUnitViewModel(get(), get(), get(), get(), get(), get()) }

viewModel { ProgramViewModel(get(), get(), get(), get(), get(), get(), get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package org.openedx.core.presentation.global

data class AppData(
val versionName: String,
val applicationId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -131,6 +130,7 @@ class HtmlUnitFragment : Fragment() {
url = blockUrl,
cookieManager = viewModel.cookieManager,
apiHostURL = viewModel.apiHostURL,
userAgent = viewModel.appUserAgent,
isLoading = isLoading,
injectJSList = injectJSList,
onCompletionSet = {
Expand Down Expand Up @@ -195,6 +195,7 @@ private fun HTMLContentView(
url: String,
cookieManager: AppCookieManager,
apiHostURL: String,
userAgent: String,
isLoading: Boolean,
injectJSList: List<String>,
onCompletionSet: () -> Unit,
Expand Down Expand Up @@ -290,7 +291,7 @@ private fun HTMLContentView(
setSupportZoom(true)
loadsImagesAutomatically = true
domStorageEnabled = true

userAgentString = "$userAgentString $userAgent"
}
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import org.openedx.core.BaseViewModel
import org.openedx.core.R
import org.openedx.core.config.Config
import org.openedx.core.extension.readAsText
import org.openedx.core.presentation.global.AppData
import org.openedx.core.system.AppCookieManager
import org.openedx.core.system.ResourceManager
import org.openedx.core.system.connection.NetworkConnection
import org.openedx.core.system.notifier.CourseCompletionSet
import org.openedx.core.system.notifier.CourseNotifier

class HtmlUnitViewModel(
private val config: Config,
private val appData: AppData,
private val resourceManager: ResourceManager,
private val edxCookieManager: AppCookieManager,
private val networkConnection: NetworkConnection,
private val notifier: CourseNotifier
Expand All @@ -27,6 +32,13 @@ class HtmlUnitViewModel(
val isCourseUnitProgressEnabled get() = config.getCourseUIConfig().isCourseUnitProgressEnabled
val apiHostURL get() = config.getApiHostURL()
val cookieManager get() = edxCookieManager
val appUserAgent: String
get() {
val appName = resourceManager.getString(R.string.app_name)
val applicationId = appData.applicationId
val versionName = appData.versionName
return "http.agent $appName/$applicationId/$versionName"
}

fun setWebPageLoaded(assets: AssetManager) {
if (_injectJSList.value.isNotEmpty()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ fun AppVersionItemUpgradeRequired(

private val mockAppData = AppData(
versionName = "1.0.0",
applicationId = "org.example.com"
)

private val mockConfiguration = Configuration(
Expand Down

0 comments on commit e4726d2

Please sign in to comment.