web: run each installed site in its own task (#598)
- Commit
52f8c4d1a97746e2d9cf0cc23e3acc772cdc3009- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-24 02:10 UTC (3 months ago)
- Parents
22dc6e1
Diff
web/src/main/AndroidManifest.xml
diff --git a/web/src/main/AndroidManifest.xml b/web/src/main/AndroidManifest.xmlindex ab505028d6..fbb653b962 100644--- a/web/src/main/AndroidManifest.xml+++ b/web/src/main/AndroidManifest.xml@@ -50,11 +50,20 @@ </intent-filter> </activity> + <!--+ Empty taskAffinity keeps installed sites out of the browser's task, and+ documentLaunchMode gives each one a task of its own keyed off the intent's data URI -+ the site's start URL - so relaunching a site returns to its existing task instead of+ stacking a duplicate. Both have to be declared here rather than as intent flags,+ because shortcuts already pinned to the home screen carry the old flags forever.+ documentLaunchMode is ignored unless launchMode is the default "standard".+ --> <activity android:name=".platform.PwaActivity" android:exported="true" android:theme="@style/Theme.Web"- android:launchMode="singleTop"+ android:taskAffinity=""+ android:documentLaunchMode="intoExisting" android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"> </activity>
web/src/main/java/com/vayunmathur/web/platform/PwaActivity.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/PwaActivity.kt b/web/src/main/java/com/vayunmathur/web/platform/PwaActivity.ktindex 15330d731e..cc0fc3db4f 100644--- a/web/src/main/java/com/vayunmathur/web/platform/PwaActivity.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/PwaActivity.kt@@ -2,9 +2,11 @@ package com.vayunmathur.web.platform import android.Manifest import android.annotation.SuppressLint+import android.app.ActivityManager import android.content.Intent import android.content.pm.PackageManager import android.net.Uri+import android.os.Build import android.os.Bundle import android.view.ViewGroup import android.webkit.CookieManager@@ -103,6 +105,25 @@ class PwaActivity : ComponentActivity() { val url = urlFromExtra ?: extractHttpUrl(urlFromData ?: "") ?: return initialUrlState.value = url titleState.value = intent.getStringExtra(EXTRA_TITLE)+ labelRecentsEntry(url, titleState.value)+ }++ /**+ * Name this task after the site it is showing. Every installed site is the same activity,+ * so without this Recents lists them all as "Web" and they can't be told apart.+ */+ private fun labelRecentsEntry(url: String, title: String?) {+ val label = title?.takeIf { it.isNotBlank() }+ ?: runCatching { BrowserUtils.hostFromUrl(url) }.getOrNull()?.takeIf { it.isNotBlank() }+ ?: return+ setTaskDescription(+ if (Build.VERSION.SDK_INT >= 33) {+ ActivityManager.TaskDescription.Builder().setLabel(label).build()+ } else {+ @Suppress("DEPRECATION")+ ActivityManager.TaskDescription(label)+ }+ ) } private fun extractHttpUrl(text: String): String? {
web/src/main/java/com/vayunmathur/web/platform/PwaHelper.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/PwaHelper.kt b/web/src/main/java/com/vayunmathur/web/platform/PwaHelper.ktindex 2a00940d52..8afc818c9f 100644--- a/web/src/main/java/com/vayunmathur/web/platform/PwaHelper.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/PwaHelper.kt@@ -120,7 +120,7 @@ object PwaHelper { data = Uri.parse(url) putExtra(com.vayunmathur.web.platform.PwaActivity.EXTRA_URL, url) putExtra(com.vayunmathur.web.platform.PwaActivity.EXTRA_TITLE, title)- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NEW_DOCUMENT) } }