add missing methods

This commit is contained in:
Minecon724 2024-08-08 11:44:21 +02:00
parent ed1a870e1b
commit 439b8aa4f0
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -113,4 +113,36 @@ class DashboardViewModel(
) )
} }
fun toggleInstance(instance: RentedInstance) {
val deferred =
if (instance.status == "running") {
vastApi.startInstance(instance.rentalId)
} else {
vastApi.stopInstance(instance.rentalId)
}
viewModelScope.launch {
try {
deferred.await()
refresh()
} catch (e: Exception) {
_refreshError.value = e.message
}
}
}
fun deleteInstance(instance: RentedInstance) {
val deferred = vastApi.deleteInstance(instance.rentalId)
viewModelScope.launch {
try {
deferred.await()
refresh()
} catch (e: Exception) {
_refreshError.value = e.message
}
}
} // TODO once again these methods share some code and more probably will so why not move the shared stuff
// OR not refresh but refresh only instances or even better don't refresh instances but delete or edit that one
} }