Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a0d48d7 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

App Lounge: Handle PWA installations better

parent 9aac1a34
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.navigation.ui.setupWithNavController
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.databinding.ActivityMainBinding
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
import foundation.e.apps.utils.enums.User

@AndroidEntryPoint
@@ -133,6 +134,7 @@ class MainActivity : AppCompatActivity() {
                }
            }
            list.forEach { app ->
                if (app.type == Type.NATIVE) {
                    if (app.status == Status.INSTALLING && !viewModel.installInProgress) {
                        if (app.downloadIdMap.all { it.value }) {
                            viewModel.installInProgress = true
@@ -145,3 +147,4 @@ class MainActivity : AppCompatActivity() {
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ class FusedManagerImpl @Inject constructor(

    private fun flushOldDownload(packageName: String) {
        val parentPathFile = File("$cacheDir/$packageName")
        if (parentPathFile.exists()) parentPathFile.delete()
        if (parentPathFile.exists()) parentPathFile.deleteRecursively()
    }

    private suspend fun downloadNativeApp(fusedDownload: FusedDownload) {
+19 −4
Original line number Diff line number Diff line
@@ -12,13 +12,16 @@ import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.manager.database.DatabaseRepository
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.utils.enums.Status
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PWAManagerModule @Inject constructor(
    @ApplicationContext private val context: Context
    @ApplicationContext private val context: Context,
    private val databaseRepository: DatabaseRepository
    ) {

    companion object {
@@ -34,7 +37,11 @@ class PWAManagerModule @Inject constructor(
        private const val VIEW_PWA = "foundation.e.blisslauncher.VIEW_PWA"
    }

    fun installPWAApp(fusedDownload: FusedDownload) {
    suspend fun installPWAApp(fusedDownload: FusedDownload) {
        // Update status
        fusedDownload.status = Status.DOWNLOADING
        databaseRepository.updateDownload(fusedDownload)

        // Get bitmap and byteArray for icon
        val iconByteArray = Base64.decode(fusedDownload.iconByteArray, Base64.DEFAULT)
        val iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.size)
@@ -53,7 +60,11 @@ class PWAManagerModule @Inject constructor(
        }
    }

    private fun publishShortcut(fusedDownload: FusedDownload, bitmap: Bitmap, databaseID: Long) {
    private suspend fun publishShortcut(fusedDownload: FusedDownload, bitmap: Bitmap, databaseID: Long) {
        // Update status
        fusedDownload.status = Status.INSTALLING
        databaseRepository.updateDownload(fusedDownload)

        val intent = Intent().apply {
            action = VIEW_PWA
            data = Uri.parse(fusedDownload.downloadURLList[0])
@@ -69,5 +80,9 @@ class PWAManagerModule @Inject constructor(
            .setIntent(intent)
            .build()
        ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null)

        // Update status
        fusedDownload.status = Status.INSTALLED
        databaseRepository.updateDownload(fusedDownload)
    }
}