Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class GameService : DaggerService() {

override fun onCreate() {
super.onCreate()
displayNotification()
serviceScope.launch {
awaitTermination()
withContext(Dispatchers.Main) {
Expand All @@ -40,11 +39,15 @@ class GameService : DaggerService() {
flags: Int,
startId: Int,
): Int {
displayNotification(intent)
return START_NOT_STICKY
}

private fun displayNotification() {
val notification = NotificationsManager(applicationContext).gameRunningNotification()
private fun displayNotification(intent: Intent) {
val gameIntent =
intent.getParcelableExtra<Intent>(EXTRA_GAME_ACTIVITY_INTENT)
?: return
val notification = NotificationsManager(applicationContext).gameRunningNotification(gameIntent)
ServiceCompat.startForeground(
this,
NotificationsManager.GAME_RUNNING_NOTIFICATION_ID,
Expand All @@ -64,15 +67,24 @@ class GameService : DaggerService() {
}

companion object {
private const val EXTRA_GAME_ACTIVITY_INTENT = "EXTRA_GAME_ACTIVITY_INTENT"

private data class GameProcessTask(
val task: suspend () -> Unit = {},
val terminate: Boolean = false,
)

private val tasks = Channel<GameProcessTask>(capacity = Channel.BUFFERED)

fun startService(context: Context) {
context.startService(Intent(context, GameService::class.java))
fun startService(
context: Context,
gameActivityIntent: Intent,
) {
context.startService(
Intent(context, GameService::class.java).apply {
putExtra(EXTRA_GAME_ACTIVITY_INTENT, gameActivityIntent)
},
)
}

fun schedule(task: suspend () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.swordfish.lemuroid.R
import com.swordfish.lemuroid.app.mobile.feature.game.GameActivity
import com.swordfish.lemuroid.app.tv.game.TVGameActivity
import com.swordfish.lemuroid.app.shared.library.CoreUpdateBroadcastReceiver
import com.swordfish.lemuroid.app.shared.library.LibraryIndexBroadcastReceiver

class NotificationsManager(private val applicationContext: Context) {
fun gameRunningNotification(): Notification {
fun gameRunningNotification(gameIntent: Intent): Notification {
createDefaultNotificationChannel()

val intent =
Intent(
applicationContext,
if (isTelevision()) TVGameActivity::class.java else GameActivity::class.java,
)
Intent(gameIntent).apply {
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
}
val contentIntent =
PendingIntent.getActivity(
applicationContext,
Expand Down Expand Up @@ -143,11 +139,6 @@ class NotificationsManager(private val applicationContext: Context) {
}
}

private fun isTelevision(): Boolean {
val uiMode = applicationContext.resources.configuration.uiMode
return (uiMode and Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION
}

companion object {
const val DEFAULT_CHANNEL_ID = "DEFAULT_CHANNEL_ID"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class BaseGameActivity : ImmersiveActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setUpExceptionsHandler()
GameService.startService(applicationContext)
GameService.startService(applicationContext, intent)
game = intent.getSerializableExtra(EXTRA_GAME) as Game
systemCoreConfig = intent.getSerializableExtra(EXTRA_SYSTEM_CORE_CONFIG) as SystemCoreConfig
system = GameSystem.findById(game.systemId)
Expand Down
Loading