Plugin update appToast, Refs

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

View file

@ -568,14 +568,23 @@ class StateApp {
StateAnnouncement.instance.deleteAnnouncement("plugin-update") StateAnnouncement.instance.deleteAnnouncement("plugin-update")
scopeOrNull?.launch(Dispatchers.IO) { scopeOrNull?.launch(Dispatchers.IO) {
val updateAvailableCount = StatePlatform.instance.checkForUpdates() val updateAvailable = StatePlatform.instance.checkForUpdates()
withContext(Dispatchers.Main) { 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( StateAnnouncement.instance.registerAnnouncement(
"plugin-update", "plugin-update",
"Plugin updates available", "Plugin updates available",
"There are $updateAvailableCount plugin updates available.", "There are ${updateAvailable.size} plugin updates available.",
AnnouncementType.SESSION_RECURRING AnnouncementType.SESSION_RECURRING
) )
} }

View file

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