Commit eeee42e0 authored by Lisa (AI Assistant)'s avatar Lisa (AI Assistant)

Fix: Delay startup to prevent ForegroundService crash

parent 41abc2b5
......@@ -120,7 +120,9 @@ class NodeService : Service() {
try {
when (intent?.action) {
"START" -> {
// Call startForeground immediately first
startForeground(NOTIFICATION_ID, createNotification())
// Get settings from Intent extras
var protocol = intent.getStringExtra("gateway_protocol") ?: "WS"
var ip = intent.getStringExtra("gateway_ip") ?: ""
......@@ -140,6 +142,9 @@ class NodeService : Service() {
// END TEMPORARY CONFIG
val fullUrl = if (protocol == "WSS") "wss://$ip:$port" else "ws://$ip:$port"
// Delay startup briefly to let startForeground settle
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
System.out.println("=== NodeService STARTED with URL: $fullUrl ===")
Log.d(TAG, "Starting with URL: $fullUrl, token present: ${token.isNotBlank()}")
......@@ -155,6 +160,7 @@ class NodeService : Service() {
} catch (e: Exception) {}
scope.launch { startNode(fullUrl, token, nodeId) }
}, 500) // 500ms delay to let startForeground settle
}
"STOP" -> {
scope.launch { stopNode() }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment