Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Exit" not terminating service when app is not in focus #157

Merged
merged 4 commits into from
Feb 19, 2025
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
1 change: 0 additions & 1 deletion app/src/main/java/com/OxGames/Pluvia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class MainActivity : ComponentActivity() {
}

private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = {
SteamService.stop()
finishAndRemoveTask()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NotificationHelper(private val context: Context) {
val stopIntent = Intent(context, SteamService::class.java).apply {
action = ACTION_EXIT
}
val stopPendingIntent = PendingIntent.getService(
val stopPendingIntent = PendingIntent.getForegroundService(
context,
0,
stopIntent,
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ class SteamService : Service(), IChallengeUrlChanged {
private val dbScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())

private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = {
SteamService.stop()
}

companion object {
const val MAX_SIMULTANEOUS_PICS_REQUESTS = 50
const val PICS_CHANGE_CHECK_DELAY = 60000L
Expand Down Expand Up @@ -1096,6 +1100,8 @@ class SteamService : Service(), IChallengeUrlChanged {
super.onCreate()
instance = this

PluviaApp.events.on<AndroidEvent.EndProcess, Unit>(onEndProcess)

notificationHelper = NotificationHelper(applicationContext)

// To view log messages in android logcat properly
Expand All @@ -1117,6 +1123,7 @@ class SteamService : Service(), IChallengeUrlChanged {
// Notification intents
when (intent?.action) {
NotificationHelper.ACTION_EXIT -> {
Timber.d("Exiting app via notification intent")
PluviaApp.events.emit(AndroidEvent.EndProcess)
return START_NOT_STICKY
}
Expand Down Expand Up @@ -1291,6 +1298,7 @@ class SteamService : Service(), IChallengeUrlChanged {
isStopping = false
retryAttempt = 0

PluviaApp.events.off<AndroidEvent.EndProcess, Unit>(onEndProcess)
PluviaApp.events.clearAllListenersOf<SteamEvent<Any>>()
}

Expand Down