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

View File

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