package net.celltron.node
import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.TextView
/**
* Minimal launcher: starts the foreground node service and polls its last log
* line so you can watch first-run extraction + sidecar boot on-device. The real
* GUI (WebView over pgh) replaces this in a later step.
*/
class MainActivity : Activity() {
private lateinit var tv: TextView
private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
tv = TextView(this).apply {
textSize = 14f
setPadding(48, 96, 48, 48)
}
setContentView(tv)
val i = Intent(this, PghNodeService::class.java)
if (Build.VERSION.SDK_INT >= 26) startForegroundService(i) else startService(i)
poll()
}
private fun poll() {
tv.text = "celltron node\n\n" +
"Runtime host: proot + glibc rootfs (extracted on first launch)\n" +
"Service: pgh-sidecar on @pgh-node\n\n" +
"Last log:\n${PghNodeService.lastLogSnapshot}"
handler.postDelayed({ poll() }, 1000)
}
override fun onDestroy() {
handler.removeCallbacksAndMessages(null)
super.onDestroy()
}
}