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() { ...@@ -120,7 +120,9 @@ class NodeService : Service() {
try { try {
when (intent?.action) { when (intent?.action) {
"START" -> { "START" -> {
// Call startForeground immediately first
startForeground(NOTIFICATION_ID, createNotification()) startForeground(NOTIFICATION_ID, createNotification())
// Get settings from Intent extras // Get settings from Intent extras
var protocol = intent.getStringExtra("gateway_protocol") ?: "WS" var protocol = intent.getStringExtra("gateway_protocol") ?: "WS"
var ip = intent.getStringExtra("gateway_ip") ?: "" var ip = intent.getStringExtra("gateway_ip") ?: ""
...@@ -140,11 +142,14 @@ class NodeService : Service() { ...@@ -140,11 +142,14 @@ class NodeService : Service() {
// END TEMPORARY CONFIG // END TEMPORARY CONFIG
val fullUrl = if (protocol == "WSS") "wss://$ip:$port" else "ws://$ip:$port" val fullUrl = if (protocol == "WSS") "wss://$ip:$port" else "ws://$ip:$port"
System.out.println("=== NodeService STARTED with URL: $fullUrl ===")
Log.d(TAG, "Starting with URL: $fullUrl, token present: ${token.isNotBlank()}")
// Debug: Write to file // Delay startup briefly to let startForeground settle
try { 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()}")
// Debug: Write to file
try {
val debugFile = java.io.File(cacheDir, "nodeservice_debug.txt") val debugFile = java.io.File(cacheDir, "nodeservice_debug.txt")
debugFile.appendText("START action: url=$fullUrl tokenLen=${token.length} nodeId=$nodeId\n") debugFile.appendText("START action: url=$fullUrl tokenLen=${token.length} nodeId=$nodeId\n")
} catch (e: Exception) {} } catch (e: Exception) {}
...@@ -155,6 +160,7 @@ class NodeService : Service() { ...@@ -155,6 +160,7 @@ class NodeService : Service() {
} catch (e: Exception) {} } catch (e: Exception) {}
scope.launch { startNode(fullUrl, token, nodeId) } scope.launch { startNode(fullUrl, token, nodeId) }
}, 500) // 500ms delay to let startForeground settle
} }
"STOP" -> { "STOP" -> {
scope.launch { stopNode() } 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