diff --git a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/EventListener.kt b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/EventListener.kt index 85da1c1e4b..9910a2aaa2 100644 --- a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/EventListener.kt +++ b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/EventListener.kt @@ -40,6 +40,15 @@ public open class EventListener { */ public open fun codeLoadStart(): Any? = null + /** + * Invoked when a Zipline is created, after [codeLoadStart] and before any application code is + * loaded. + */ + public open fun ziplineCreated( + zipline: Zipline, + ) { + } + /** * Invoked when code is successfully downloaded and initialized. * @@ -64,6 +73,17 @@ public open class EventListener { ) { } + /** + * Invoked when a code load is skipped because the cached code isn't up-to-date. + * + * @param startValue the value returned by [codeLoadStart] for the start of this call. This + * is null unless [codeLoadStart] is overridden to return something else. + */ + public open fun codeLoadSkippedNotFresh( + startValue: Any?, + ) { + } + /** * Invoked when a code load fails. * @@ -190,6 +210,15 @@ public open class EventListener { ) { } + /** + * Invoked when the loader has successfully fetched a manifest, verified it (if necessary), and + * will proceed to download and load each of its modules. + */ + public open fun manifestReady( + manifest: ZiplineManifest, + ) { + } + /** * Invoked when a module load starts. This is the process of loading code into QuickJS. * diff --git a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/RealEventPublisher.kt b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/RealEventPublisher.kt index 1d02138e6e..d8a3f15eca 100644 --- a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/RealEventPublisher.kt +++ b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/RealEventPublisher.kt @@ -43,6 +43,12 @@ internal class RealEventPublisher( return listener.codeLoadStart() } + override fun ziplineCreated( + zipline: Zipline, + ) { + listener.ziplineCreated(zipline) + } + override fun applicationLoadSuccess( applicationName: String, manifestUrl: String?, @@ -61,6 +67,14 @@ internal class RealEventPublisher( listener.codeLoadSkipped(startValue) } + override fun applicationLoadSkippedNotFresh( + applicationName: String, + manifestUrl: String?, + startValue: Any?, + ) { + listener.codeLoadSkippedNotFresh(startValue) + } + override fun applicationLoadFailed( applicationName: String, manifestUrl: String?, @@ -115,6 +129,14 @@ internal class RealEventPublisher( listener.manifestVerified(manifest, verifiedKey) } + override fun manifestReady( + applicationName: String, + manifestUrl: String?, + manifest: ZiplineManifest, + ) { + listener.manifestReady(manifest) + } + override fun moduleLoadStart(zipline: Zipline, moduleId: String): Any? { return listener.moduleLoadStart(moduleId) }