Install the "icons" WebExtension to automatically load icons for every visited website.
parent
c334c77bbe
commit
291df48c4e
|
@ -140,7 +140,7 @@ class TabViewHolder(
|
|||
checkbox.setOnCheckedChangeListener(checkboxListener)
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = view.favicon_image.context.components.utils.icons
|
||||
val bitmap = view.favicon_image.context.components.core.icons
|
||||
.loadIcon(IconRequest(tab.url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
view.favicon_image.setImageBitmap(bitmap)
|
||||
|
|
|
@ -9,10 +9,11 @@ import android.content.res.Configuration
|
|||
import android.os.Bundle
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import mozilla.components.browser.engine.gecko.GeckoEngine
|
||||
import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.browser.session.storage.SessionStorage
|
||||
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
|
||||
|
@ -25,6 +26,7 @@ import mozilla.components.concept.fetch.Client
|
|||
import mozilla.components.feature.session.HistoryDelegate
|
||||
import mozilla.components.lib.crash.handler.CrashHandlerService
|
||||
import org.mozilla.fenix.AppRequestInterceptor
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.test.Mockable
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
import org.mozilla.geckoview.GeckoRuntime
|
||||
|
@ -97,37 +99,34 @@ class Core(private val context: Context) {
|
|||
*/
|
||||
val sessionManager by lazy {
|
||||
SessionManager(engine).also { sessionManager ->
|
||||
// Restore a previous, still active bundle.
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
val snapshot = async(Dispatchers.IO) {
|
||||
sessionStorage.restore()
|
||||
}
|
||||
// Install the "icons" WebExtension to automatically load icons for every visited website.
|
||||
icons.install(engine, sessionManager)
|
||||
|
||||
// There's an active bundle with a snapshot: Feed it into the SessionManager.
|
||||
snapshot.await()?.let {
|
||||
try {
|
||||
val selected = sessionManager.selectedSession
|
||||
sessionManager.restore(it)
|
||||
selected?.let {
|
||||
sessionManager.select(selected)
|
||||
}
|
||||
} catch (_: IllegalArgumentException) {
|
||||
return@let
|
||||
}
|
||||
// Restore the previous state.
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
withContext(Dispatchers.IO) {
|
||||
sessionStorage.restore()
|
||||
}?.let { snapshot ->
|
||||
sessionManager.restore(snapshot, updateSelection = (sessionManager.selectedSession == null))
|
||||
}
|
||||
|
||||
// Now that we have restored our previous state (if there's one) let's setup auto saving the state while
|
||||
// the app is used.
|
||||
sessionStorage.apply {
|
||||
autoSave(sessionManager)
|
||||
.periodicallyInForeground(interval = 30, unit = TimeUnit.SECONDS)
|
||||
.whenGoingToBackground()
|
||||
.whenSessionsChange()
|
||||
}
|
||||
sessionStorage.autoSave(sessionManager)
|
||||
.periodicallyInForeground(interval = 30, unit = TimeUnit.SECONDS)
|
||||
.whenGoingToBackground()
|
||||
.whenSessionsChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Icons component for loading, caching and processing website icons.
|
||||
*/
|
||||
val icons by lazy {
|
||||
BrowserIcons(context, context.components.core.client)
|
||||
}
|
||||
|
||||
/**
|
||||
* The storage component to persist browsing history (with the exception of
|
||||
* private sessions).
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
package org.mozilla.fenix.components
|
||||
|
||||
import android.content.Context
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.feature.intent.IntentProcessor
|
||||
import mozilla.components.feature.search.SearchUseCases
|
||||
import mozilla.components.feature.session.SessionUseCases
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.test.Mockable
|
||||
|
||||
/**
|
||||
|
@ -34,8 +32,4 @@ class Utilities(
|
|||
val privateIntentProcessor by lazy {
|
||||
IntentProcessor(sessionUseCases, sessionManager, searchUseCases, context, isPrivate = true)
|
||||
}
|
||||
|
||||
val icons by lazy {
|
||||
BrowserIcons(context, context.components.core.client)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class ExceptionsListItemViewHolder(
|
|||
|
||||
private fun updateFavIcon(url: String) {
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = favicon.context.components.utils.icons
|
||||
val bitmap = favicon.context.components.core.icons
|
||||
.loadIcon(IconRequest(url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
favicon.setImageBitmap(bitmap)
|
||||
|
|
|
@ -78,7 +78,7 @@ class TabInCollectionViewHolder(
|
|||
collection_tab_hostname.text = tab.url.urlToTrimmedHost()
|
||||
collection_tab_title.text = tab.title
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = collection_tab_icon.context.components.utils.icons
|
||||
val bitmap = collection_tab_icon.context.components.core.icons
|
||||
.loadIcon(IconRequest(tab.url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
collection_tab_icon.setImageBitmap(bitmap)
|
||||
|
|
|
@ -92,7 +92,7 @@ class TabViewHolder(
|
|||
hostname.text = tab.hostname
|
||||
tab_title.text = tab.title
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = favicon_image.context.components.utils.icons
|
||||
val bitmap = favicon_image.context.components.core.icons
|
||||
.loadIcon(IconRequest(tab.url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
favicon_image.setImageBitmap(bitmap)
|
||||
|
|
|
@ -17,7 +17,6 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.appservices.places.BookmarkRoot
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.icons.IconRequest
|
||||
import mozilla.components.browser.menu.BrowserMenu
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
|
@ -196,7 +195,7 @@ class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkA
|
|||
|
||||
if (!selected && item.url?.startsWith("http") == true) {
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = BrowserIcons(bookmark_favicon.context, bookmark_layout.context.components.core.client)
|
||||
val bitmap = bookmark_layout.context.components.core.icons
|
||||
.loadIcon(IconRequest(item.url!!)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
bookmark_favicon.setImageBitmap(bitmap)
|
||||
|
|
|
@ -125,7 +125,7 @@ class HistoryListItemViewHolder(
|
|||
|
||||
private fun updateFavIcon(url: String) {
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = favicon.context.components.utils.icons
|
||||
val bitmap = favicon.context.components.core.icons
|
||||
.loadIcon(IconRequest(url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
favicon.setImageBitmap(bitmap)
|
||||
|
|
|
@ -109,21 +109,21 @@ class AwesomeBarUIView(
|
|||
SessionSuggestionProvider(
|
||||
components.core.sessionManager,
|
||||
components.useCases.tabsUseCases.selectTab,
|
||||
components.utils.icons
|
||||
components.core.icons
|
||||
)
|
||||
|
||||
historyStorageProvider =
|
||||
HistoryStorageSuggestionProvider(
|
||||
components.core.historyStorage,
|
||||
loadUrlUseCase,
|
||||
components.utils.icons
|
||||
components.core.icons
|
||||
)
|
||||
|
||||
bookmarksStorageSuggestionProvider =
|
||||
BookmarksStorageSuggestionProvider(
|
||||
components.core.bookmarksStorage,
|
||||
loadUrlUseCase,
|
||||
components.utils.icons
|
||||
components.core.icons
|
||||
)
|
||||
|
||||
if (Settings.getInstance(container.context).showSearchSuggestions()) {
|
||||
|
|
|
@ -28,7 +28,6 @@ import kotlinx.coroutines.Dispatchers.IO
|
|||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
import mozilla.components.browser.icons.IconRequest
|
||||
import mozilla.components.feature.sitepermissions.SitePermissions
|
||||
import org.jetbrains.anko.alert
|
||||
|
@ -168,10 +167,9 @@ class ExceptionsAdapter(private val clickListener: View.OnClickListener) :
|
|||
override fun onBindViewHolder(holder: SitePermissionsViewHolder, position: Int) {
|
||||
val sitePermissions = requireNotNull(getItem(position))
|
||||
val context = holder.textView.context
|
||||
val client = context.components.core.client
|
||||
|
||||
launch(IO) {
|
||||
val bitmap = BrowserIcons(context, client)
|
||||
val bitmap = context.components.core.icons
|
||||
.loadIcon(IconRequest(sitePermissions.origin)).await().bitmap
|
||||
launch(Main) {
|
||||
val drawable = BitmapDrawable(context.resources, bitmap)
|
||||
|
|
Loading…
Reference in New Issue