From c5202c04e2157103352203a0f9181a4ba33002d3 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 7 Aug 2022 14:08:16 -0400 Subject: [PATCH] Fixing problematic initialization sequence that mutated the tabs list from multiple places --- .../acr/browser/lightning/browser/BrowserContract.kt | 2 +- .../acr/browser/lightning/browser/BrowserPresenter.kt | 11 +++++------ .../browser/lightning/browser/tab/TabsRepository.kt | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserContract.kt b/app/src/main/java/acr/browser/lightning/browser/BrowserContract.kt index 150ab2afe..716a9e6e1 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserContract.kt +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserContract.kt @@ -200,7 +200,7 @@ interface BrowserContract { /** * Initialize all tabs that were previously frozen when the browser was last open. */ - fun initializeTabs(): Maybe> + fun initializeTabs(): Maybe> /** * Notifies the model that all tabs need to be frozen before the browser shuts down. diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.kt b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.kt index a415ee1b3..b04a29fd1 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.kt +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.kt @@ -56,6 +56,8 @@ import acr.browser.lightning.utils.isHistoryUrl import acr.browser.lightning.utils.isSpecialUrl import acr.browser.lightning.utils.smartUrlFilter import acr.browser.lightning.utils.value +import io.reactivex.Flowable +import io.reactivex.Observable import javax.inject.Inject import kotlin.system.exitProcess @@ -151,13 +153,10 @@ class BrowserPresenter @Inject constructor( compositeDisposable += model.initializeTabs() .observeOn(mainScheduler) - .concatWith( - Maybe.fromCallable { initialUrl } - .flatMapSingleElement { model.createTab(UrlInitializer(it)) } - .map(::listOf) - ) + .concatWith(Maybe.fromCallable { initialUrl }.map { listOf(UrlInitializer(it)) }) + .flatMap { Flowable.fromIterable(it) } + .flatMapSingle(model::createTab) .toList() - .map(MutableList>::flatten) .filter(List::isNotEmpty) .switchIfEmpty(model.createTab(homePageInitializer).map(::listOf)) .subscribe { list -> diff --git a/app/src/main/java/acr/browser/lightning/browser/tab/TabsRepository.kt b/app/src/main/java/acr/browser/lightning/browser/tab/TabsRepository.kt index 1458be6fe..7f446d52d 100644 --- a/app/src/main/java/acr/browser/lightning/browser/tab/TabsRepository.kt +++ b/app/src/main/java/acr/browser/lightning/browser/tab/TabsRepository.kt @@ -81,14 +81,13 @@ class TabsRepository @Inject constructor( override fun tabsListChanges(): Observable> = tabsListObservable.hide() - override fun initializeTabs(): Maybe> = + override fun initializeTabs(): Maybe> = Single.fromCallable(bundleStore::retrieve) .flatMapObservable { Observable.fromIterable(it) } .subscribeOn(diskScheduler) .observeOn(mainScheduler) - .flatMapSingle(::createTab) .toList() - .filter(MutableList::isNotEmpty) + .filter(List::isNotEmpty) override fun freeze() { if (userPreferences.restoreLostTabsEnabled) {