Plugin update appToast, Refs

This commit is contained in:
Kelvin 2024-01-03 19:47:38 +01:00
parent 0dc33e1f2b
commit 0f60d4737e
2 changed files with 16 additions and 7 deletions

View file

@ -568,14 +568,23 @@ class StateApp {
StateAnnouncement.instance.deleteAnnouncement("plugin-update")
scopeOrNull?.launch(Dispatchers.IO) {
val updateAvailableCount = StatePlatform.instance.checkForUpdates()
val updateAvailable = StatePlatform.instance.checkForUpdates()
withContext(Dispatchers.Main) {
if (updateAvailableCount > 0) {
if (updateAvailable.isNotEmpty()) {
UIDialogs.appToast(
ToastView.Toast(updateAvailable
.map { " - " + it.name }
.joinToString("\n"),
true,
null,
"Plugin updates available"
));
StateAnnouncement.instance.registerAnnouncement(
"plugin-update",
"Plugin updates available",
"There are $updateAvailableCount plugin updates available.",
"There are ${updateAvailable.size} plugin updates available.",
AnnouncementType.SESSION_RECURRING
)
}

View file

@ -941,8 +941,8 @@ class StatePlatform {
}
}
suspend fun checkForUpdates(): Int = withContext(Dispatchers.IO) {
var updateAvailableCount = 0
suspend fun checkForUpdates(): List<SourcePluginConfig> = withContext(Dispatchers.IO) {
var configs = mutableListOf<SourcePluginConfig>()
val updatesAvailableFor = hashSetOf<String>()
for (availableClient in getAvailableClients()) {
if (availableClient !is JSClient) {
@ -950,13 +950,13 @@ class StatePlatform {
}
if (checkForUpdates(availableClient.config)) {
updateAvailableCount++
configs.add(availableClient.config);
updatesAvailableFor.add(availableClient.config.id)
}
}
_updatesAvailableMap = updatesAvailableFor
return@withContext updateAvailableCount
return@withContext configs;
}
fun clearUpdateAvailable(c: SourcePluginConfig) {