@@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.utils
33import android.app.Activity
44import android.content.Context
55import android.content.Intent
6+ import android.content.pm.PackageManager.NameNotFoundException
67import android.net.Uri
78import android.text.TextUtils
89import android.util.Log
@@ -37,6 +38,7 @@ object InAppUpdater {
3738 private const val GITHUB_USER_NAME = " recloudstream"
3839 private const val GITHUB_REPO = " cloudstream"
3940
41+ private const val PRERELEASE_PACKAGE_NAME = " com.lagradost.cloudstream3.prerelease"
4042 private const val LOG_TAG = " InAppUpdater"
4143
4244 private data class GithubAsset (
@@ -73,17 +75,14 @@ object InAppUpdater {
7375 @JsonProperty(" updateNodeId" ) val updateNodeId : String? ,
7476 )
7577
76- private suspend fun Activity.getAppUpdate (): Update {
78+ private suspend fun Activity.getAppUpdate (installPrerelease : Boolean ): Update {
7779 return try {
78- val settingsManager = PreferenceManager .getDefaultSharedPreferences(this )
79- if (
80- settingsManager.getBoolean(
81- getString(R .string.prerelease_update_key),
82- resources.getBoolean(R .bool.is_prerelease)
83- )
84- ) {
85- getPreReleaseUpdate()
86- } else getReleaseUpdate()
80+ when {
81+ // No updates on debug version
82+ BuildConfig .DEBUG -> Update (false , null , null , null , null )
83+ BuildConfig .FLAVOR == " prerelease" || installPrerelease -> getPreReleaseUpdate()
84+ else -> getReleaseUpdate()
85+ }
8786 } catch (e: Exception ) {
8887 Log .e(LOG_TAG , Log .getStackTraceString(e))
8988 Update (false , null , null , null , null )
@@ -226,17 +225,42 @@ object InAppUpdater {
226225 }
227226 }
228227
228+ fun Activity.installPreReleaseIfNeeded () {
229+ ioSafe {
230+ val isInstalled = try {
231+ packageManager.getPackageInfo(PRERELEASE_PACKAGE_NAME , 0 )
232+ true
233+ } catch (_: NameNotFoundException ) {
234+ false
235+ }
236+
237+ if (isInstalled) {
238+ runOnUiThread {
239+ showToast(R .string.prerelease_already_installed)
240+ }
241+ } else if (runAutoUpdate(false , true ) == false ) {
242+ runOnUiThread {
243+ showToast(R .string.prerelease_install_failed)
244+ }
245+ }
246+ }
247+ }
248+
229249 /* *
230250 * @param checkAutoUpdate if the update check was launched automatically
251+ * @param installPrerelease if we want to install the pre-release version
231252 */
232- suspend fun Activity.runAutoUpdate (checkAutoUpdate : Boolean = true): Boolean {
253+ suspend fun Activity.runAutoUpdate (
254+ checkAutoUpdate : Boolean = true,
255+ installPrerelease : Boolean = false
256+ ): Boolean {
233257 val settingsManager = PreferenceManager .getDefaultSharedPreferences(this )
234258 if (! checkAutoUpdate || settingsManager.getBoolean(
235259 getString(R .string.auto_update_key),
236260 true
237261 )
238262 ) {
239- val update = getAppUpdate()
263+ val update = getAppUpdate(installPrerelease )
240264 if (update.shouldUpdate && update.updateURL != null ) {
241265 // Check if update should be skipped
242266 val updateNodeId = settingsManager.getString(
0 commit comments