Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1989,9 +1989,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa

handleAppIntent(intent)

ioSafe {
runAutoUpdate() // TODO remove this when we update the updater autosearch
}
//ioSafe {
// runAutoUpdate()
//}

FcastManager().init(this, false)

Expand Down
72 changes: 44 additions & 28 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivityScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
Expand All @@ -22,28 +24,33 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.viewmodel.compose.viewModel
import com.lagradost.cloudstream3.mvvm.getStackTracePretty
import com.lagradost.cloudstream3.ui.settings.APK_CONTENT_TYPE
import com.lagradost.cloudstream3.ui.settings.APK_PRERELEASE
import com.lagradost.cloudstream3.ui.settings.APK_REPOSITORY
import com.lagradost.cloudstream3.ui.settings.APK_USERNAME
import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.ui.settings.ApkUpdater
import com.lagradost.cloudstream3.ui.settings.GithubAction
import com.lagradost.cloudstream3.ui.settings.GithubAction.AutoSearchForUpdate
import com.lagradost.cloudstream3.ui.settings.GithubAction.Dismiss
import com.lagradost.cloudstream3.ui.settings.GithubAction.SearchForUpdate
import com.lagradost.cloudstream3.ui.settings.GithubAction.SkipUpdate
import com.lagradost.cloudstream3.ui.settings.GithubAction.Update
import com.lagradost.cloudstream3.ui.settings.GithubState
import com.lagradost.cloudstream3.ui.settings.GithubUpdateDialogState
import com.lagradost.cloudstream3.ui.settings.GithubViewModel
import com.lagradost.cloudstream3.ui.settings.GithubReleases
import com.lagradost.cloudstream3.ui.settings.GithubReleases.APK_CONTENT_TYPE
import com.lagradost.cloudstream3.ui.settings.GithubReleases.APK_PRERELEASE
import com.lagradost.cloudstream3.ui.settings.GithubReleases.APK_REPOSITORY
import com.lagradost.cloudstream3.ui.settings.GithubReleases.APK_USERNAME
import com.lagradost.cloudstream3.utils.GitInfo.currentCommitHash
import com.lagradost.cloudstream3.utils.parseMarkdown
import com.lagradost.cloudstream4.compose.BlackButton
import com.lagradost.cloudstream4.compose.Screen
import com.lagradost.cloudstream4.compose.WhiteButton
import com.lagradost.cloudstream4.rememberAppSettings
import com.lagradost.cloudstream4.viewmodels.GithubAction
import com.lagradost.cloudstream4.viewmodels.GithubAction.AutoSearchForUpdate
import com.lagradost.cloudstream4.viewmodels.GithubAction.Dismiss
import com.lagradost.cloudstream4.viewmodels.GithubAction.SearchForUpdate
import com.lagradost.cloudstream4.viewmodels.GithubAction.SkipUpdate
import com.lagradost.cloudstream4.viewmodels.GithubAction.Update
import com.lagradost.cloudstream4.viewmodels.GithubState
import com.lagradost.cloudstream4.viewmodels.GithubUpdateDialogState
import com.lagradost.cloudstream4.viewmodels.GithubViewModel
import com.mihon.material.padding

object MainActivityScreen : Screen {
private var hasSearchedForUpdate: Boolean = false

@Composable
fun githubViewModel(): GithubViewModel? {
// By having the ComponentActivity as the owner we can have a singleton viewmodel
Expand All @@ -60,10 +67,15 @@ object MainActivityScreen : Screen {
isDebug = BuildConfig.DEBUG,
buildSha = activity.currentCommitHash(),
settings = settings,
updater = ApkUpdater
)/*.apply {
onAction(AutoSearchForUpdate) // Remove this for now
}*/
updater = ApkUpdater,
repository = GithubReleases,
).apply {
/** Only search once per session when not in safe mode */
if (!hasSearchedForUpdate && !PluginManager.isSafeMode()) {
hasSearchedForUpdate = true
onAction(AutoSearchForUpdate)
}
}
}
}

Expand All @@ -81,20 +93,18 @@ object MainActivityScreen : Screen {

@Composable
fun GithubState(updaterState: GithubState, onAction: (GithubAction) -> Unit) {
if (updaterState.dialog == null) {
return
}
val dialog = updaterState.dialog ?: return

val title: String
val body: @Composable () -> Unit
val confirmButton: @Composable () -> Unit
val dismissButton: @Composable () -> Unit
val cancelable: Boolean

when (val state = updaterState.dialog.state) {
when (val state = dialog.state) {
is GithubUpdateDialogState.Error -> {
// Only show error if it is initialized by the user
if (!updaterState.dialog.isFromUser) return
if (!dialog.isFromUser) return

cancelable = true
title = stringResource(R.string.download_failed)
Expand All @@ -113,7 +123,7 @@ object MainActivityScreen : Screen {

GithubUpdateDialogState.Loading -> {
// Only show loading if it is initialized by the user
if (!updaterState.dialog.isFromUser) return
if (!dialog.isFromUser) return

cancelable = true
title = stringResource(R.string.loading)
Expand All @@ -134,7 +144,7 @@ object MainActivityScreen : Screen {

GithubUpdateDialogState.NoUpdateFound -> {
// Only show error if it is initialized by the user
if (!updaterState.dialog.isFromUser) return
if (!dialog.isFromUser) return

cancelable = true
title = stringResource(R.string.no_update_found)
Expand All @@ -154,7 +164,12 @@ object MainActivityScreen : Screen {
(state.oldSha ?: BuildConfig.VERSION_NAME),
(state.newSha ?: state.file.displayName)
)
body = { Text(text = state.file.changeLog) }
body = {
Text(
text = parseMarkdown(state.file.changeLog),
modifier = Modifier.verticalScroll(rememberScrollState())
)
}
confirmButton = {
WhiteButton(text = stringResource(R.string.update), onClick = {
onAction(Update(state.file))
Expand All @@ -175,9 +190,10 @@ object MainActivityScreen : Screen {
cancelable = false
title = stringResource(R.string.update_notification_downloading)
body = {
if (state.total != null) {
val total = state.total
if (total != null) {
val progress =
(state.progress.toFloat() / state.total.toFloat()).coerceIn(0.0f, 1.0f)
(state.progress.toFloat() / total.toFloat()).coerceIn(0.0f, 1.0f)
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
color = MaterialTheme.colorScheme.onBackground,
Expand All @@ -192,7 +208,7 @@ object MainActivityScreen : Screen {
} / ${
formatFileSize(
LocalContext.current,
state.total
total
)
})"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.safe
import com.lagradost.cloudstream3.receivers.PackageInstallerStatusReceiver
import com.lagradost.cloudstream4.AppSettings
import com.lagradost.cloudstream4.viewmodels.AppUpdater
import com.lagradost.cloudstream4.viewmodels.DigestPair
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.lagradost.cloudstream3.ui.settings

import androidx.compose.runtime.Immutable
import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream4.viewmodels.GithubFile
import com.lagradost.cloudstream4.viewmodels.GithubRepository
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.jvm.Throws
import java.io.FileNotFoundException

object GithubReleases {
object GithubReleases : GithubRepository {
@Serializable
private data class GithubAsset(
@JsonProperty("name") @SerialName("name") val name: String,
Expand Down Expand Up @@ -41,27 +42,15 @@ object GithubReleases {
@JsonProperty("object") @SerialName("object") val githubObject: GithubObject,
)

/** GitHub file update package */
@Immutable
data class GithubFile(
/** File digest, sha:xxx */
val digest: String?,
/** File url for download */
val downloadUrl: String,
/** Filename without the extension */
val displayName: String,
/** Changelog, aka the commit message */
val changeLog: String,
/** Name of the tag, aka unique release name like vX.X.X or pre-release */
val tagName: String,
/** Unique node id */
val nodeId: String,
)
const val APK_USERNAME = "recloudstream"
const val APK_REPOSITORY = "cloudstream"
const val APK_PRERELEASE = "pre-release"
const val APK_CONTENT_TYPE = "application/vnd.android.package-archive"

private val defaultHeaders = mapOf("Accept" to "application/vnd.github.v3+json")

@Throws
suspend fun getShaFromTag(
override suspend fun getSha(
userName: String,
repository: String,
tag: String,
Expand All @@ -73,13 +62,13 @@ object GithubReleases {
}

@Throws
suspend fun getLatestReleaseFile(
override suspend fun getRelease(
userName: String,
repository: String,
prerelease: Boolean,
prereleaseTag: String,
contentType: String,
): GithubFile? {
): GithubFile {
val latestReleaseUrl = if (prerelease) {
// Find the release object
// https://docs.github.com/en/rest/releases/releases?apiVersion=2026-03-10#get-a-release-by-tag-name
Expand All @@ -102,7 +91,7 @@ object GithubReleases {
}

if (foundAsset == null) {
return null
throw FileNotFoundException()
}

return GithubFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.lagradost.cloudstream3.utils.InAppUpdater.installPreReleaseIfNeeded
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream4.AppSettings
import com.lagradost.cloudstream4.rememberAppSettings
import com.lagradost.cloudstream4.viewmodels.GithubAction
import com.lagradost.safefile.SafeFile
import com.mihon.presentation.settings.Preference
import com.mihon.presentation.settings.SearchableSettings
Expand Down
Loading
Loading