Skip to content

Commit

Permalink
Fixing problematic initialization sequence that mutated the tabs list…
Browse files Browse the repository at this point in the history
… from multiple places
  • Loading branch information
Anthony Restaino committed Aug 7, 2022
1 parent 58c4417 commit c5202c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ interface BrowserContract {
/**
* Initialize all tabs that were previously frozen when the browser was last open.
*/
fun initializeTabs(): Maybe<List<TabModel>>
fun initializeTabs(): Maybe<List<TabInitializer>>

/**
* Notifies the model that all tabs need to be frozen before the browser shuts down.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<List<TabModel>>::flatten)
.filter(List<TabModel>::isNotEmpty)
.switchIfEmpty(model.createTab(homePageInitializer).map(::listOf))
.subscribe { list ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ class TabsRepository @Inject constructor(

override fun tabsListChanges(): Observable<List<TabModel>> = tabsListObservable.hide()

override fun initializeTabs(): Maybe<List<TabModel>> =
override fun initializeTabs(): Maybe<List<TabInitializer>> =
Single.fromCallable(bundleStore::retrieve)
.flatMapObservable { Observable.fromIterable(it) }
.subscribeOn(diskScheduler)
.observeOn(mainScheduler)
.flatMapSingle(::createTab)
.toList()
.filter(MutableList<TabModel>::isNotEmpty)
.filter(List<TabInitializer>::isNotEmpty)

override fun freeze() {
if (userPreferences.restoreLostTabsEnabled) {
Expand Down

0 comments on commit c5202c0

Please sign in to comment.