Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope EventListener.Factory to TreehouseApp #1778

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public fun TreehouseAppFactory(
context: Context,
httpClient: OkHttpClient,
manifestVerifier: ManifestVerifier,
eventListenerFactory: EventListener.Factory = EventListener.NONE,
embeddedDir: Path? = null,
embeddedFileSystem: FileSystem? = null,
cacheName: String = "zipline",
Expand All @@ -37,7 +36,6 @@ public fun TreehouseAppFactory(
): TreehouseApp.Factory = TreehouseApp.Factory(
platform = AndroidTreehousePlatform(context),
dispatchers = AndroidTreehouseDispatchers(),
eventListenerFactory = eventListenerFactory,
httpClient = httpClient.asZiplineHttpClient(),
frameClockFactory = AndroidChoreographerFrameClock.Factory(),
manifestVerifier = manifestVerifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TreehouseApp<A : AppService> private constructor(
private val factory: Factory,
private val appScope: CoroutineScope,
public val spec: Spec<A>,
private val eventListenerFactory: EventListener.Factory,
) {
public val dispatchers: TreehouseDispatchers = factory.dispatchers

Expand Down Expand Up @@ -139,7 +140,7 @@ public class TreehouseApp<A : AppService> private constructor(

// Adapt [EventListener.Factory] to a [ZiplineEventListener.Factory]
val ziplineEventListenerFactory = ZiplineEventListener.Factory { _, manifestUrl ->
val eventListener = factory.eventListenerFactory.create(this@TreehouseApp, manifestUrl)
val eventListener = eventListenerFactory.create(this@TreehouseApp, manifestUrl)
RealEventPublisher(eventListener).ziplineEventListener
}
loader = loader.withEventListenerFactory(ziplineEventListenerFactory)
Expand Down Expand Up @@ -194,7 +195,6 @@ public class TreehouseApp<A : AppService> private constructor(
public class Factory internal constructor(
private val platform: TreehousePlatform,
public val dispatchers: TreehouseDispatchers,
internal val eventListenerFactory: EventListener.Factory,
internal val httpClient: ZiplineHttpClient,
internal val frameClockFactory: FrameClock.Factory,
internal val manifestVerifier: ManifestVerifier,
Expand All @@ -213,7 +213,8 @@ public class TreehouseApp<A : AppService> private constructor(
public fun <A : AppService> create(
appScope: CoroutineScope,
spec: Spec<A>,
): TreehouseApp<A> = TreehouseApp(this, appScope, spec)
eventListenerFactory: EventListener.Factory = EventListener.NONE,
): TreehouseApp<A> = TreehouseApp(this, appScope, spec, eventListenerFactory)

override fun close() {
cache.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import okio.Path
public fun TreehouseAppFactory(
httpClient: ZiplineHttpClient,
manifestVerifier: ManifestVerifier,
eventListenerFactory: EventListener.Factory = EventListener.NONE,
embeddedDir: Path? = null,
embeddedFileSystem: FileSystem? = null,
cacheName: String = "zipline",
Expand All @@ -34,7 +33,6 @@ public fun TreehouseAppFactory(
): TreehouseApp.Factory = TreehouseApp.Factory(
platform = IosTreehousePlatform(),
dispatchers = IosTreehouseDispatchers(),
eventListenerFactory = eventListenerFactory,
httpClient = httpClient,
frameClockFactory = IosDisplayLinkClock,
manifestVerifier = manifestVerifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class EmojiSearchActivity : ComponentActivity() {
context = applicationContext,
httpClient = httpClient,
manifestVerifier = ManifestVerifier.Companion.NO_SIGNATURE_CHECKS,
eventListenerFactory = { app, manifestUrl -> appEventListener },
embeddedDir = "/".toPath(),
embeddedFileSystem = applicationContext.assets.asFileSystem(),
)
Expand All @@ -143,6 +142,7 @@ class EmojiSearchActivity : ComponentActivity() {
manifestUrl = manifestUrlFlow,
hostApi = RealHostApi(this@EmojiSearchActivity, httpClient),
),
eventListenerFactory = { app, manifestUrl -> appEventListener },
)

treehouseApp.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class EmojiSearchActivity : ComponentActivity() {
context = applicationContext,
httpClient = httpClient,
manifestVerifier = ManifestVerifier.NO_SIGNATURE_CHECKS,
eventListenerFactory = { app, manifestUrl -> appEventListener },
embeddedDir = "/".toPath(),
embeddedFileSystem = applicationContext.assets.asFileSystem(),
stateStore = FileStateStore(
Expand All @@ -164,6 +163,7 @@ class EmojiSearchActivity : ComponentActivity() {
manifestUrl = manifestUrlFlow,
hostApi = RealHostApi(this@EmojiSearchActivity, httpClient),
),
eventListenerFactory = { app, manifestUrl -> appEventListener },
)

treehouseApp.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class EmojiSearchLauncher(
val treehouseAppFactory = TreehouseAppFactory(
httpClient = ziplineHttpClient,
manifestVerifier = ManifestVerifier.Companion.NO_SIGNATURE_CHECKS,
eventListenerFactory = { app, manifestUrl -> eventListener },
)

val manifestUrlFlow = flowOf(manifestUrl)
Expand All @@ -75,6 +74,7 @@ class EmojiSearchLauncher(
manifestUrl = manifestUrlFlow,
hostApi = hostApi,
),
eventListenerFactory = { app, manifestUrl -> eventListener },
)

treehouseApp.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class TestAppLauncher(
val treehouseAppFactory = TreehouseAppFactory(
httpClient = ziplineHttpClient,
manifestVerifier = NO_SIGNATURE_CHECKS,
eventListenerFactory = { app, manifestUrl -> eventListener },
)

val manifestUrlFlow = flowOf(manifestUrl)
Expand All @@ -68,6 +67,7 @@ class TestAppLauncher(
manifestUrl = manifestUrlFlow,
hostApi = hostApi,
),
eventListenerFactory = { app, manifestUrl -> eventListener },
)

treehouseApp.start()
Expand Down