mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 756d7cbea0 | |||
| 8a3d781bb3 |
@@ -76,7 +76,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
@@ -12,7 +12,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
@@ -191,7 +191,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
+8
-6
@@ -38,13 +38,13 @@ class GitHubUpdateRepository(
|
||||
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||
}
|
||||
release.map { release ->
|
||||
val apkAsset =
|
||||
val standaloneApkAsset =
|
||||
release.assets.find { asset ->
|
||||
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
||||
asset.name.endsWith(".apk")
|
||||
asset.name.endsWith(".apk")
|
||||
}
|
||||
val newVersion =
|
||||
apkAsset
|
||||
standaloneApkAsset
|
||||
?.name
|
||||
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
||||
?.removeSuffix(".apk") ?: return@map null
|
||||
@@ -53,7 +53,9 @@ class GitHubUpdateRepository(
|
||||
if (isNightly && newVersion != currentVersion)
|
||||
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||
GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||
GitHubReleaseMapper.toAppUpdate(release.copy(
|
||||
assets = listOf(standaloneApkAsset)
|
||||
), newVersion)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -63,7 +65,7 @@ class GitHubUpdateRepository(
|
||||
override suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
onProgress: suspend (Float) -> Unit,
|
||||
): Result<File> =
|
||||
withContext(ioDispatcher) {
|
||||
try {
|
||||
@@ -101,4 +103,4 @@ class GitHubUpdateRepository(
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,6 +9,6 @@ interface UpdateRepository {
|
||||
suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
onProgress: suspend (Float) -> Unit,
|
||||
): Result<File>
|
||||
}
|
||||
|
||||
+8
-2
@@ -4,21 +4,25 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import jakarta.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@HiltViewModel
|
||||
class SupportViewModel
|
||||
@Inject
|
||||
constructor(private val updateRepository: UpdateRepository, private val fileUtils: FileUtils) :
|
||||
constructor(private val updateRepository: UpdateRepository, private val fileUtils: FileUtils,
|
||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher) :
|
||||
ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(SupportUiState())
|
||||
@@ -62,7 +66,9 @@ constructor(private val updateRepository: UpdateRepository, private val fileUtil
|
||||
_uiState.update { it.copy(isLoading = true) }
|
||||
updateRepository
|
||||
.downloadApk(appUpdate.apkUrl, appUpdate.apkFileName) { progress ->
|
||||
_uiState.update { it.copy(downloadProgress = progress) }
|
||||
withContext(mainDispatcher) {
|
||||
_uiState.update { it.copy(downloadProgress = progress) }
|
||||
}
|
||||
}
|
||||
.onSuccess { apk ->
|
||||
_uiState.update { it.copy(isLoading = false) }
|
||||
|
||||
Reference in New Issue
Block a user