add check updates -
This commit is contained in:
parent
c896a6b1a8
commit
dfc624431d
4 changed files with 0 additions and 83 deletions
|
|
@ -43,10 +43,3 @@ data class AnswerBotList(
|
|||
@SerializedName("total") val total: Int,
|
||||
@SerializedName("items") val items: List<AnswerBot>?
|
||||
)
|
||||
|
||||
data class ReleaseInfo(
|
||||
@SerializedName("tag_name") val tagName: String,
|
||||
@SerializedName("name") val name: String?,
|
||||
@SerializedName("body") val body: String?,
|
||||
@SerializedName("html_url") val htmlUrl: String
|
||||
)
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ interface IpService {
|
|||
suspend fun getIpInfo(): IpInfo
|
||||
}
|
||||
|
||||
interface ForgejoService {
|
||||
@GET("api/v1/repos/hhu67/sergay-app/releases/latest")
|
||||
suspend fun getLatestRelease(): ReleaseInfo
|
||||
}
|
||||
|
||||
interface ApiService {
|
||||
@FormUrlEncoded
|
||||
@POST("api/login")
|
||||
|
|
@ -121,13 +116,5 @@ interface ApiService {
|
|||
.build()
|
||||
.create(IpService::class.java)
|
||||
}
|
||||
|
||||
fun createForgejoService(): ForgejoService {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl("https://code.hhu67.pw/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
.create(ForgejoService::class.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ import kotlin.system.exitProcess
|
|||
@Composable
|
||||
fun MainAppScreen(vm: MainViewModel) {
|
||||
val ctx = LocalContext.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
|
||||
|
|
@ -180,41 +179,6 @@ fun MainAppScreen(vm: MainViewModel) {
|
|||
icon = { Icon(Icons.Default.BrightnessLow, contentDescription = null, tint = Color.Blue) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
Spacer(Modifier.weight(1f))
|
||||
HorizontalDivider()
|
||||
NavigationDrawerItem(
|
||||
label = {
|
||||
Column {
|
||||
Text("Проверить обновления")
|
||||
if (vm.updateCheckMessage.isNotEmpty()) {
|
||||
Text(vm.updateCheckMessage, style = MaterialTheme.typography.labelSmall, color = Color.Gray)
|
||||
}
|
||||
}
|
||||
},
|
||||
selected = false,
|
||||
onClick = {
|
||||
vm.checkForUpdates("1.0")
|
||||
},
|
||||
icon = {
|
||||
if (vm.isCheckingUpdates) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(24.dp), strokeWidth = 2.dp)
|
||||
} else {
|
||||
Icon(Icons.Default.Update, contentDescription = null)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
vm.updateInfo?.let { info ->
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Скачать ${info.tagName}", color = MaterialTheme.colorScheme.primary) },
|
||||
selected = false,
|
||||
onClick = {
|
||||
uriHandler.openUri(info.htmlUrl)
|
||||
},
|
||||
icon = { Icon(Icons.Default.Download, contentDescription = null, tint = MaterialTheme.colorScheme.primary) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -77,12 +77,6 @@ class MainViewModel(appContext: Context) : ViewModel() {
|
|||
var inoagentModeActive by mutableStateOf(false)
|
||||
var showInoagentDialog by mutableStateOf(false)
|
||||
|
||||
var updateInfo by mutableStateOf<ReleaseInfo?>(null)
|
||||
var isCheckingUpdates by mutableStateOf(false)
|
||||
var updateCheckMessage by mutableStateOf("")
|
||||
|
||||
private val forgejo = ApiService.createForgejoService()
|
||||
|
||||
init {
|
||||
if (isAuthenticated) {
|
||||
checkRoleAndRestore()
|
||||
|
|
@ -308,27 +302,6 @@ class MainViewModel(appContext: Context) : ViewModel() {
|
|||
inoagentModeActive = true
|
||||
}
|
||||
|
||||
fun checkForUpdates(currentVersion: String) {
|
||||
viewModelScope.launch {
|
||||
isCheckingUpdates = true
|
||||
updateCheckMessage = ""
|
||||
updateInfo = null
|
||||
try {
|
||||
val latest = forgejo.getLatestRelease()
|
||||
if (latest.tagName != currentVersion) {
|
||||
updateInfo = latest
|
||||
updateCheckMessage = "Доступно обновление: ${latest.tagName}"
|
||||
} else {
|
||||
updateCheckMessage = "У вас последняя версия"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
updateCheckMessage = "Ошибка проверки: ${e.localizedMessage}"
|
||||
} finally {
|
||||
isCheckingUpdates = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteBotPhrase(id: Int) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue