diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index face4fae..e6345f81 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings import com.lagradost.cloudstream3.APIHolder.initAll import com.lagradost.cloudstream3.APIHolder.updateHasTrailers +import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.CommonActivity.loadThemes import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent @@ -596,7 +597,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { apis = allProviders.distinctBy { it } if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){ - this@MainActivity.restorePromptGithub() + context?.restorePromptGithub() } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index f03804cc..cda57f62 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.syncproviders.providers import androidx.fragment.app.FragmentActivity import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey @@ -111,8 +112,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ userAvatar = it.owner.userAvatar, gistUrl = it.gistUrl )) - runOnMainThread { - FragmentActivity().restorePromptGithub() + ioSafe { + context?.restorePromptGithub() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index a7770fef..04e32ad5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -335,18 +335,18 @@ object BackupUtils { Toast.LENGTH_LONG ) } - - fun FragmentActivity.restorePromptGithub() = - ioSafe { - val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() - val jsondata = app.get(gistUrl).text - val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw?: throw IllegalAccessException() - val data = parseJson(dataraw) - this@restorePromptGithub.restore( - data, - restoreSettings = true, - restoreDataStore = true - ) - } + suspend fun Context.restorePromptGithub() { + val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(gistUrl).text + val dataraw = + parseJson(jsondata ?: "").files.values.first().dataRaw + ?: throw IllegalAccessException() + val data = parseJson(dataraw) + restore( + data, + restoreSettings = true, + restoreDataStore = true + ) + } }