improve stability
This commit is contained in:
@@ -55,13 +55,18 @@
|
|||||||
android:icon="@mipmap/launcher_icon"
|
android:icon="@mipmap/launcher_icon"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:enableOnBackInvokedCallback="true">
|
android:enableOnBackInvokedCallback="true">
|
||||||
<activity android:name="eu.lensai.flutter_mozilla_components.activities.NotificationActivity" android:theme="@style/Theme.AppCompat.Translucent" />
|
|
||||||
|
<activity
|
||||||
|
android:name="eu.lensai.flutter_mozilla_components.activities.NotificationActivity"
|
||||||
|
android:theme="@style/Theme.AppCompat.Translucent"
|
||||||
|
android:exported="false"
|
||||||
|
android:launchMode="singleTop" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:taskAffinity=""
|
android:taskAffinity="me.movenext.bang_navigator.task"
|
||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
android:supportsPictureInPicture="true"
|
android:supportsPictureInPicture="true"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
|
|||||||
+42
-17
@@ -1,6 +1,8 @@
|
|||||||
package eu.lensai.flutter_mozilla_components
|
package eu.lensai.flutter_mozilla_components
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -17,6 +19,7 @@ import eu.lensai.flutter_mozilla_components.databinding.FragmentBrowserBinding
|
|||||||
import eu.lensai.flutter_mozilla_components.ext.getPreferenceKey
|
import eu.lensai.flutter_mozilla_components.ext.getPreferenceKey
|
||||||
import eu.lensai.flutter_mozilla_components.pip.PictureInPictureIntegration
|
import eu.lensai.flutter_mozilla_components.pip.PictureInPictureIntegration
|
||||||
import eu.lensai.flutter_mozilla_components.services.DownloadService
|
import eu.lensai.flutter_mozilla_components.services.DownloadService
|
||||||
|
import io.flutter.Log
|
||||||
import mozilla.components.browser.state.selector.selectedTab
|
import mozilla.components.browser.state.selector.selectedTab
|
||||||
import mozilla.components.concept.engine.EngineView
|
import mozilla.components.concept.engine.EngineView
|
||||||
import mozilla.components.feature.app.links.AppLinksFeature
|
import mozilla.components.feature.app.links.AppLinksFeature
|
||||||
@@ -294,28 +297,50 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun restartApp(context: Context) {
|
||||||
|
val packageManager = context.packageManager
|
||||||
|
val intent = packageManager.getLaunchIntentForPackage(context.packageName)
|
||||||
|
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
context.startActivity(intent)
|
||||||
|
|
||||||
|
if (context is Activity) {
|
||||||
|
context.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime.getRuntime().exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createAndSetupEngine() {
|
||||||
|
try {
|
||||||
|
// Set layout parameters
|
||||||
|
val layoutParams = FrameLayout.LayoutParams(
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
|
)
|
||||||
|
|
||||||
|
val engineView = createEngine(components)
|
||||||
|
val originalContext = ActivityContextWrapper.getOriginalContext(requireActivity())
|
||||||
|
val engineNativeView = engineView.asView()
|
||||||
|
engineNativeView.layoutParams = layoutParams
|
||||||
|
|
||||||
|
engineView.setActivityContext(originalContext)
|
||||||
|
|
||||||
|
binding.swipeToRefresh.addView(engineNativeView)
|
||||||
|
|
||||||
|
components.engineView = engineView
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("EngineCreation", "Failed to create engine: ${e.message}", e)
|
||||||
|
context?.let { restartApp(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
_binding = FragmentBrowserBinding.inflate(inflater, container, false)
|
_binding = FragmentBrowserBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
// Set layout parameters
|
createAndSetupEngine()
|
||||||
val layoutParams = FrameLayout.LayoutParams(
|
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
||||||
FrameLayout.LayoutParams.MATCH_PARENT
|
|
||||||
)
|
|
||||||
|
|
||||||
val originalContext = ActivityContextWrapper.getOriginalContext(requireActivity())
|
|
||||||
|
|
||||||
val engineView = createEngine(components)
|
|
||||||
components.engineView = engineView
|
|
||||||
|
|
||||||
val engineNativeView = engineView.asView()
|
|
||||||
engineNativeView.layoutParams = layoutParams
|
|
||||||
|
|
||||||
engineView.setActivityContext(originalContext)
|
|
||||||
|
|
||||||
binding.swipeToRefresh.addView(engineNativeView)
|
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -16,4 +16,9 @@ class NotificationActivity: AppCompatActivity() {
|
|||||||
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
components.notificationsDelegate.unBindActivity(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+14
-3
@@ -1,5 +1,6 @@
|
|||||||
package me.movenext.simple_intent_receiver
|
package me.movenext.simple_intent_receiver
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -14,10 +15,10 @@ class SimpleIntentReceiverPlugin: FlutterPlugin, ActivityAware, PluginRegistry.N
|
|||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
private var intentReceiver: IntentReceiver? = null
|
private var intentReceiver: IntentReceiver? = null
|
||||||
private var handledInitialIntent = false
|
private var handledInitialIntent = false
|
||||||
|
private var activity: Activity? = null
|
||||||
|
|
||||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
context = flutterPluginBinding.applicationContext
|
context = flutterPluginBinding.applicationContext
|
||||||
|
|
||||||
intentReceiver = IntentReceiver(flutterPluginBinding.binaryMessenger)
|
intentReceiver = IntentReceiver(flutterPluginBinding.binaryMessenger)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ class SimpleIntentReceiverPlugin: FlutterPlugin, ActivityAware, PluginRegistry.N
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||||
|
activity = binding.activity
|
||||||
binding.addOnNewIntentListener(this)
|
binding.addOnNewIntentListener(this)
|
||||||
|
|
||||||
// Process the initial intent if available
|
// Process the initial intent if available
|
||||||
@@ -38,22 +40,31 @@ class SimpleIntentReceiverPlugin: FlutterPlugin, ActivityAware, PluginRegistry.N
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivityForConfigChanges() {
|
override fun onDetachedFromActivityForConfigChanges() {
|
||||||
// No implementation needed
|
activity = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||||
|
activity = binding.activity
|
||||||
binding.addOnNewIntentListener(this)
|
binding.addOnNewIntentListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivity() {
|
override fun onDetachedFromActivity() {
|
||||||
// No implementation needed
|
activity = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent): Boolean {
|
override fun onNewIntent(intent: Intent): Boolean {
|
||||||
|
// Update the activity's intent to ensure proper state
|
||||||
|
activity?.setIntent(intent)
|
||||||
return handleIntent(intent)
|
return handleIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleIntent(intent: Intent): Boolean {
|
private fun handleIntent(intent: Intent): Boolean {
|
||||||
|
// Check if this intent is coming from a different task
|
||||||
|
if (intent.flags and Intent.FLAG_ACTIVITY_NEW_TASK != 0) {
|
||||||
|
// Clear any existing tasks with this activity
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
}
|
||||||
|
|
||||||
val pigeonIntent = convertToPigeonIntent(intent)
|
val pigeonIntent = convertToPigeonIntent(intent)
|
||||||
intentReceiver?.sendIntent(System.currentTimeMillis(), pigeonIntent)
|
intentReceiver?.sendIntent(System.currentTimeMillis(), pigeonIntent)
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user