Skip to content

Commit

Permalink
fix package cache
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed May 15, 2023
1 parent 11ecdba commit 00b6254
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class AboutFragment : ToolbarFragment(R.layout.layout_about) {
.setOnClickAction { }
.build())
.apply {
PackageCache.awaitLoadSync()
for ((_, pkg) in PackageCache.installedPluginPackages) {
try {
val pluginId = pkg.providers[0].loadString(Plugins.METADATA_KEY_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import moe.matsuri.nya.neko.Plugins
import java.util.concurrent.atomic.AtomicBoolean

object PackageCache {

Expand All @@ -39,9 +40,11 @@ object PackageCache {
lateinit var packageMap: Map<String, Int>
val uidMap = HashMap<Int, HashSet<String>>()
val loaded = Mutex(true)
var registerd = AtomicBoolean(false)

// called from init (suspend)
fun register() {
if (registerd.getAndSet(true)) return
reload()
app.listenForPackageChanges(false) {
reload()
Expand Down Expand Up @@ -96,6 +99,10 @@ object PackageCache {
if (::packageMap.isInitialized) {
return
}
if (!registerd.get()) {
register()
return
}
runBlocking {
loaded.withLock {
// just await
Expand Down

0 comments on commit 00b6254

Please sign in to comment.