intermediate
This commit is contained in:
+11
-13
@@ -115,21 +115,19 @@ class GeckoTabsApiImpl : GeckoTabsApi {
|
||||
|
||||
private suspend fun handleIconChange(tab: SessionState) {
|
||||
try {
|
||||
val iconBytes: ByteArray?
|
||||
if (tab.content.icon != null) {
|
||||
val iconBytes = tab.content.icon?.toWebPBytes()
|
||||
withContext(Dispatchers.Main) {
|
||||
components.flutterEvents.onIconChange(
|
||||
System.currentTimeMillis(),
|
||||
tab.id,
|
||||
iconBytes
|
||||
) { }
|
||||
}
|
||||
iconBytes = tab.content.icon?.toWebPBytes()
|
||||
} else {
|
||||
val result = components.core.icons.loadIcon(IconRequest(url = tab.content.url)).await()
|
||||
val iconBytes = result.bitmap.toWebPBytes()
|
||||
withContext(Dispatchers.Main) {
|
||||
components.flutterEvents.onIconChange(System.currentTimeMillis(), tab.id, iconBytes) { }
|
||||
}
|
||||
iconBytes = null
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
components.flutterEvents.onIconChange(
|
||||
System.currentTimeMillis(),
|
||||
tab.id,
|
||||
iconBytes
|
||||
) { }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.error("$TAG: Failed to handle icon change for tab ${tab.id}", e)
|
||||
|
||||
+11
@@ -70,6 +70,17 @@ class FlutterEventMiddleware(private val flutterEvents: GeckoStateEvents) : Midd
|
||||
) { _ -> }
|
||||
}
|
||||
}
|
||||
is ContentAction.UpdateIconAction -> {
|
||||
val bytes = action.icon.toWebPBytes()
|
||||
|
||||
runOnUiThread {
|
||||
flutterEvents.onIconUpdate(
|
||||
System.currentTimeMillis(),
|
||||
action.pageUrl,
|
||||
bytes
|
||||
) { _ -> }
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
//logger.debug("Event fired: " + action.javaClass.name)
|
||||
}
|
||||
|
||||
+18
-1
@@ -1,4 +1,4 @@
|
||||
// Autogenerated from Pigeon (v22.7.0), do not edit directly.
|
||||
// Autogenerated from Pigeon (v22.7.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
|
||||
|
||||
@@ -2430,6 +2430,23 @@ class GeckoStateEvents(private val binaryMessenger: BinaryMessenger, private val
|
||||
}
|
||||
}
|
||||
}
|
||||
fun onIconUpdate(timestampArg: Long, urlArg: String, bytesArg: ByteArray, callback: (Result<Unit>) -> Unit)
|
||||
{
|
||||
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||
val channelName = "dev.flutter.pigeon.flutter_mozilla_components.GeckoStateEvents.onIconUpdate$separatedMessageChannelSuffix"
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||
channel.send(listOf(timestampArg, urlArg, bytesArg)) {
|
||||
if (it is List<*>) {
|
||||
if (it.size > 1) {
|
||||
callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
|
||||
} else {
|
||||
callback(Result.success(Unit))
|
||||
}
|
||||
} else {
|
||||
callback(Result.failure(createConnectionError(channelName)))
|
||||
}
|
||||
}
|
||||
}
|
||||
fun onTabAdded(timestampArg: Long, tabIdArg: String, callback: (Result<Unit>) -> Unit)
|
||||
{
|
||||
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||
|
||||
Reference in New Issue
Block a user