Fix: Database access on Main crashes

This commit is contained in:
machiav3lli 2022-01-13 23:52:30 +01:00
parent 27a54c1b08
commit e559f19529
2 changed files with 5 additions and 5 deletions

View File

@ -22,6 +22,7 @@ import com.looker.droidify.utility.Utils.toInstalledItem
import com.looker.droidify.utility.extension.android.Android
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.net.InetSocketAddress
import java.net.Proxy
@ -69,10 +70,9 @@ class MainApplication : Application(), ImageLoaderFactory {
} catch (e: Exception) {
null
}
if (packageInfo != null) {
db.installedDao.put(packageInfo.toInstalledItem())
} else {
db.installedDao.delete(packageName)
GlobalScope.launch {
if (packageInfo != null) db.installedDao.put(packageInfo.toInstalledItem())
else db.installedDao.delete(packageName)
}
}
}

View File

@ -435,7 +435,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
* @see SyncService.displayUpdatesNotification
*/
private fun runAutoUpdate(productItems: List<ProductItem>) {
if (Preferences[Preferences.Key.InstallAfterSync]) {
if (Preferences[Preferences.Key.InstallAfterSync]) GlobalScope.launch {
// run startUpdate on every item
productItems.map { productItem ->
Pair(