package app.chanora.chanora_flutter

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity() {

    companion object {
        init {
            // Force-load the chanora_bridge cdylib at activity-class-init
            // time so JNI_OnLoad captures the JavaVM* before Flutter / FRB
            // tries to call any Rust function.
            System.loadLibrary("chanora_bridge")
        }

        /**
         * JNI entry point implemented in `chanora_bridge::android_init`.
         * Initialises `ndk_context` with our Activity so cpal-on-Oboe can
         * find Android audio services when `chanora_audio` starts the
         * capture / playback streams.
         */
        @JvmStatic
        external fun initChanoraContext(context: android.content.Context)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Pass the Application context to the Rust side so the audio
        // engine can open device handles. Must run before any
        // `chanora_audio` call from Dart.
        initChanoraContext(applicationContext)
    }
}
