add check updates -

This commit is contained in:
hhu67 2026-08-20 23:18:16 +03:00
parent c896a6b1a8
commit dfc624431d
4 changed files with 0 additions and 83 deletions

View file

@ -43,10 +43,3 @@ data class AnswerBotList(
@SerializedName("total") val total: Int, @SerializedName("total") val total: Int,
@SerializedName("items") val items: List<AnswerBot>? @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
)

View file

@ -18,11 +18,6 @@ interface IpService {
suspend fun getIpInfo(): IpInfo suspend fun getIpInfo(): IpInfo
} }
interface ForgejoService {
@GET("api/v1/repos/hhu67/sergay-app/releases/latest")
suspend fun getLatestRelease(): ReleaseInfo
}
interface ApiService { interface ApiService {
@FormUrlEncoded @FormUrlEncoded
@POST("api/login") @POST("api/login")
@ -121,13 +116,5 @@ interface ApiService {
.build() .build()
.create(IpService::class.java) .create(IpService::class.java)
} }
fun createForgejoService(): ForgejoService {
return Retrofit.Builder()
.baseUrl("https://code.hhu67.pw/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ForgejoService::class.java)
}
} }
} }

View file

@ -42,7 +42,6 @@ import kotlin.system.exitProcess
@Composable @Composable
fun MainAppScreen(vm: MainViewModel) { fun MainAppScreen(vm: MainViewModel) {
val ctx = LocalContext.current val ctx = LocalContext.current
val uriHandler = LocalUriHandler.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
@ -180,41 +179,6 @@ fun MainAppScreen(vm: MainViewModel) {
icon = { Icon(Icons.Default.BrightnessLow, contentDescription = null, tint = Color.Blue) }, icon = { Icon(Icons.Default.BrightnessLow, contentDescription = null, tint = Color.Blue) },
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) 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)
)
}
} }
} }
) { ) {

View file

@ -77,12 +77,6 @@ class MainViewModel(appContext: Context) : ViewModel() {
var inoagentModeActive by mutableStateOf(false) var inoagentModeActive by mutableStateOf(false)
var showInoagentDialog 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 { init {
if (isAuthenticated) { if (isAuthenticated) {
checkRoleAndRestore() checkRoleAndRestore()
@ -308,27 +302,6 @@ class MainViewModel(appContext: Context) : ViewModel() {
inoagentModeActive = true 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) { fun deleteBotPhrase(id: Int) {
viewModelScope.launch { viewModelScope.launch {
try { try {