Don't unpin shortcuts when they are unavailable

This commit is contained in:
MM20
2023-10-13 15:03:01 +02:00
parent ad5772b3db
commit d797263c0a
6 changed files with 123 additions and 6 deletions
@@ -7,6 +7,7 @@ import de.mm20.launcher2.graphics.BadgeDrawable
import de.mm20.launcher2.search.data.LauncherShortcut
import de.mm20.launcher2.search.data.LegacyShortcut
import de.mm20.launcher2.search.Searchable
import de.mm20.launcher2.search.data.UnavailableShortcut
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
@@ -50,6 +51,19 @@ class AppShortcutBadgeProvider(
val badge = Badge(icon = BadgeDrawable(context, icon))
send(badge)
}
} else if (searchable is UnavailableShortcut) {
val packageName = searchable.packageName
withContext(Dispatchers.IO) {
val icon = try {
context.packageManager.getApplicationIcon(
packageName
)
} catch (e: PackageManager.NameNotFoundException) {
return@withContext
}
val badge = Badge(icon = BadgeDrawable(context, icon))
send(badge)
}
} else {
send(null)
}