You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Only launch FlashActivity if app is foreground
This commit is contained in:
@@ -40,7 +40,7 @@ abstract class NotificationService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun finishWork(
|
||||
protected fun finishNotify(
|
||||
id: Int,
|
||||
editBody: (NotificationCompat.Builder) -> NotificationCompat.Builder? = { null }
|
||||
) : Int {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk.model.download
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.skoumal.teanity.extensions.subscribeK
|
||||
@@ -7,6 +8,7 @@ import com.topjohnwu.magisk.Config
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||
import com.topjohnwu.magisk.extensions.firstMap
|
||||
import com.topjohnwu.magisk.extensions.get
|
||||
import com.topjohnwu.magisk.extensions.writeTo
|
||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk
|
||||
@@ -15,7 +17,6 @@ import com.topjohnwu.magisk.utils.ProgInputStream
|
||||
import com.topjohnwu.magisk.view.Notifications
|
||||
import com.topjohnwu.superuser.ShellUtils
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import okhttp3.ResponseBody
|
||||
import org.koin.android.ext.android.inject
|
||||
import timber.log.Timber
|
||||
@@ -47,12 +48,15 @@ abstract class RemoteFileService : NotificationService() {
|
||||
private fun start(subject: DownloadSubject) = search(subject)
|
||||
.onErrorResumeNext(download(subject))
|
||||
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnError { remove(subject.hashCode()) }
|
||||
.doOnSuccess {
|
||||
val id = finish(it, subject)
|
||||
runCatching { onFinished(it, subject, id) }.onFailure { Timber.e(it) }
|
||||
}.subscribeK()
|
||||
.subscribeK(onError = {
|
||||
Timber.e(it)
|
||||
remove(subject.hashCode())
|
||||
}) {
|
||||
val newId = finishNotify(it, subject)
|
||||
get<Activity?>()?.run {
|
||||
onFinished(it, subject, newId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun search(subject: DownloadSubject) = Single.fromCallable {
|
||||
if (!Config.isDownloadCacheEnabled) {
|
||||
@@ -98,7 +102,7 @@ abstract class RemoteFileService : NotificationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun finish(file: File, subject: DownloadSubject) = finishWork(subject.hashCode()) {
|
||||
private fun finishNotify(file: File, subject: DownloadSubject) = finishNotify(subject.hashCode()) {
|
||||
it.addActions(file, subject)
|
||||
.setContentText(getString(R.string.download_complete))
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
|
||||
Reference in New Issue
Block a user