package com.nitrochucker import android.content.Intent import android.util.Log import com.chuckerteam.chucker.api.Chucker import com.margelo.nitro.NitroModules import com.margelo.nitro.nitrochucker.HybridNitroChuckerSpec class HybridNitroChucker : HybridNitroChuckerSpec() { init { // Defense-in-depth. Primary registration is ChuckerStartupInitializer, which // runs at process creation (before any request fires). This is a pure Nitro // module (autolinked via nitro.json) with no ReactPackage, so registering here // too guarantees the interceptor is installed the first time JS touches the // hybrid even if App Startup were disabled. register() is idempotent. ChuckerCapture.register(NitroModules.applicationContext) } override val isSupported: Boolean get() = true override fun show() { val ctx = NitroModules.applicationContext ?: return val activity = ctx.currentActivity val intent = Chucker.getLaunchIntent(ctx) if (activity != null) { activity.startActivity(intent) } else { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ctx.startActivity(intent) } } override fun setEnabled(enabled: Boolean) { ChuckerCapture.enabled.set(enabled) } override fun dismiss() { // Chucker runs in its own task; we cannot force-finish it. Best-effort: // clear its notification so the inspector stops surfacing itself. NitroModules.applicationContext?.let { Chucker.dismissNotifications(it) } } override fun clearLogs() { // Chucker 4.x exposes no public "clear all transactions" API; clearing is a // UI action / governed by the retention period. Documented best-effort no-op. Log.i("NitroChucker", "clearLogs(): no public Chucker API to clear data; no-op") } override fun setMaxLogCount(maxCount: Double) { // Deliberate no-op. This cap exists for iOS, where Wormholy holds every transaction // (bodies included) in an unbounded in-memory array. Chucker persists transactions to // a database instead of RAM and truncates bodies at 250 KB by default, so retention // here is bounded by disk and the retention period rather than a count. Log.i( "NitroChucker", "setMaxLogCount($maxCount): no-op on Android — Chucker persists to a database " + "and caps bodies at 250 KB, so there is no count cap to apply", ) } override fun setIgnoredHosts(hosts: Array) { ChuckerCapture.setIgnoredHosts(hosts.toList()) } }