This commit is contained in:
Cloudburst 2023-02-11 14:25:04 +00:00
parent ee4517093f
commit 1ae7307892
3 changed files with 15 additions and 3 deletions

View file

@ -82,6 +82,7 @@ import com.lagradost.cloudstream3.ui.setup.SetupFragmentExtensions
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
import com.lagradost.cloudstream3.utils.AppUtils.isNetworkAvailable
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
import com.lagradost.cloudstream3.utils.AppUtils.loadRepository
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
@ -720,15 +721,15 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
changeStatusBarState(isEmulatorSettings())
// Automatically enable jsdelivr if cant connect to raw.githubusercontent.com
if (!settingsManager.contains("jsdelivr_proxy_key")) {
if (!settingsManager.contains("jsdelivr_proxy_key") && isNetworkAvailable()) {
runBlocking {
if (checkGithubConnectivity()) {
setKey("jsdelivr_proxy_key", false)
} else {
setKey("jsdelivr_proxy_key", true)
val parentView = findViewById(android.R.id.content)
Snackbar.make(parentView, getString(R.string.jsdelivr_enabled), Snackbar.LENGTH_LONG)
.setAction("Revert", v -> {
Snackbar.make(parentView, R.string.jsdelivr_enabled, Snackbar.LENGTH_LONG)
.setAction(R.string.revert, v -> {
setKey("jsdelivr_proxy_key", false)
})
.setBackgroundTint(ContextCompat.getColor(this@MainActivity, R.color.primaryGrayBackground))

View file

@ -456,6 +456,16 @@ object AppUtils {
}
}
fun Context.isNetworkAvailable(): Boolean {
val manager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = manager.activeNetworkInfo
var connected = activeNetworkInfo != null && activeNetworkInfo.isConnected
if (!connected) {
connected = manager.allNetworkInfo?.any { it.isConnected } ?: false
}
return connected
}
fun splitQuery(url: URL): Map<String, String> {
val queryPairs: MutableMap<String, String> = LinkedHashMap()
val query: String = url.query

View file

@ -640,4 +640,5 @@
<string name="empty_library_no_accounts_message">Looks like your library is empty :(\nLogin to a library account or add shows to your local library</string>
<string name="empty_library_logged_in_message">Looks like this list is empty, try switching to another one</string>
<string name="safe_mode_file">Safe mode file found!\nNot loading any extensions on startup until file is removed.</string>
<string name="revert">Revert</string>
</resources>