Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed411fc284 | |||
| b7b0457685 |
BIN
KeyStore.jks
BIN
KeyStore.jks
Binary file not shown.
@@ -10,6 +10,9 @@ import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.app.NotificationCompat
|
||||
import libandroid.Libandroid
|
||||
|
||||
@@ -19,6 +22,7 @@ class GolangServerService : Service() {
|
||||
const val CHANNEL_ID = "GolangServerChannel"
|
||||
const val NOTIFICATION_ID = 1
|
||||
private const val TAG = "GolangServerService"
|
||||
var isRunning by mutableStateOf(false)
|
||||
}
|
||||
|
||||
private var wakeLock: PowerManager.WakeLock? = null
|
||||
@@ -29,9 +33,13 @@ class GolangServerService : Service() {
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (isRunning) {
|
||||
Log.d(TAG, "❗ Server is already running")
|
||||
return START_STICKY
|
||||
}
|
||||
isRunning = true
|
||||
Log.d(TAG, "onStartCommand called")
|
||||
|
||||
// 1. Tạo intent để mở lại MainActivity khi người dùng click vào thông báo
|
||||
val notificationIntent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
@@ -40,18 +48,15 @@ class GolangServerService : Service() {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
// 2. Tạo notification
|
||||
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle("Golang Server")
|
||||
.setContentText("Server đang chạy")
|
||||
.setContentTitle("FireflyGO Server")
|
||||
.setContentText("FireflyGO is running...")
|
||||
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build()
|
||||
|
||||
// 3. Chạy foreground
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
|
||||
// 4. Giữ CPU không sleep (tùy chọn, nhưng hữu ích)
|
||||
try {
|
||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GolangServer::WakeLock")
|
||||
@@ -61,7 +66,6 @@ class GolangServerService : Service() {
|
||||
Log.e(TAG, "❌ WakeLock failed", e)
|
||||
}
|
||||
|
||||
// 5. Chạy server trong thread riêng
|
||||
Thread {
|
||||
try {
|
||||
val appDataPath = intent?.getStringExtra("appDataPath")
|
||||
@@ -69,16 +73,23 @@ class GolangServerService : Service() {
|
||||
Libandroid.setPathDataLocal(appDataPath)
|
||||
Log.d(TAG, "✅ Set path data: $appDataPath")
|
||||
} else {
|
||||
isRunning = false
|
||||
Log.e(TAG, "❌ appDataPath not received in intent")
|
||||
stopSelf()
|
||||
return@Thread
|
||||
}
|
||||
|
||||
Libandroid.setServerRunning(true)
|
||||
isRunning = true
|
||||
Log.d(TAG, "✅ Server started")
|
||||
} catch (e: Exception) {
|
||||
isRunning = false
|
||||
Log.e(TAG, "❌ Error starting server", e)
|
||||
stopSelf()
|
||||
}
|
||||
}.start()
|
||||
|
||||
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
@@ -89,6 +100,7 @@ class GolangServerService : Service() {
|
||||
// 1. Tắt server
|
||||
try {
|
||||
val result = Libandroid.setServerRunning(false)
|
||||
isRunning = false
|
||||
Log.d(TAG, "Server shutdown result: $result")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error shutting down server", e)
|
||||
@@ -105,6 +117,7 @@ class GolangServerService : Service() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to release WakeLock", e)
|
||||
}
|
||||
isRunning = false
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
@@ -72,9 +72,8 @@ class MainActivity : ComponentActivity() {
|
||||
@Composable
|
||||
fun ServerControlScreen(appDataPath: String, modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
var isServerRunning by remember { mutableStateOf(false) }
|
||||
|
||||
val serverImage = if (isServerRunning)
|
||||
val isRunning = GolangServerService.isRunning
|
||||
val serverImage = if (isRunning)
|
||||
painterResource(id = R.drawable.server_running)
|
||||
else
|
||||
painterResource(id = R.drawable.server_stopped)
|
||||
@@ -115,8 +114,7 @@ fun ServerControlScreen(appDataPath: String, modifier: Modifier = Modifier) {
|
||||
Button(
|
||||
onClick = {
|
||||
try {
|
||||
isServerRunning = !isServerRunning
|
||||
if (isServerRunning) {
|
||||
if (!isRunning) {
|
||||
val intent = Intent(context, GolangServerService::class.java)
|
||||
intent.putExtra("appDataPath", appDataPath)
|
||||
context.startService(intent)
|
||||
@@ -128,7 +126,7 @@ fun ServerControlScreen(appDataPath: String, modifier: Modifier = Modifier) {
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (isServerRunning) Color(0xFFB71C1C) else Color(0xFF2196F3),
|
||||
containerColor = if (isRunning) Color(0xFFB71C1C) else Color(0xFF2196F3),
|
||||
contentColor = Color.White
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
@@ -137,7 +135,7 @@ fun ServerControlScreen(appDataPath: String, modifier: Modifier = Modifier) {
|
||||
.height(50.dp)
|
||||
) {
|
||||
Text(
|
||||
text = if (isServerRunning) "Stop Server" else "Start Server",
|
||||
text = if (isRunning) "Stop Server" else "Start Server",
|
||||
fontSize = 20.sp
|
||||
)
|
||||
}
|
||||
@@ -146,9 +144,9 @@ fun ServerControlScreen(appDataPath: String, modifier: Modifier = Modifier) {
|
||||
|
||||
// Server status text
|
||||
Text(
|
||||
text = if (isServerRunning) "Server is running" else "Server is stopped",
|
||||
text = if (isRunning) "Server is running" else "Server is stopped",
|
||||
fontSize = 24.sp,
|
||||
color = if (isServerRunning) Color(0xFF4CAF50) else Color.Gray
|
||||
color = if (isRunning) Color(0xFF4CAF50) else Color.Gray
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">FireflyGo-3.4.5X</string>
|
||||
<string name="app_name">FireflyGo-3.5.5X</string>
|
||||
</resources>
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ab23bd9a708e04ce0817aa7e3d05e81e3bd64e8846d0df54af9647b550d30859
|
||||
size 72329407
|
||||
oid sha256:26eaf2a6981aed15c5c7f6edc465505406f05567739054e71f2d3af60f111ef2
|
||||
size 73415308
|
||||
|
||||
Reference in New Issue
Block a user