You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Dismiss notification on error
This commit is contained in:
@@ -46,9 +46,6 @@ abstract class NotificationService : Service() {
|
||||
) : Int {
|
||||
val currentNotification = remove(id)?.run(editBody)
|
||||
|
||||
updateForeground()
|
||||
|
||||
cancel(id)
|
||||
var newId = -1
|
||||
currentNotification?.let {
|
||||
newId = nextInt(Int.MAX_VALUE)
|
||||
@@ -56,7 +53,6 @@ abstract class NotificationService : Service() {
|
||||
}
|
||||
|
||||
if (!hasNotifications) {
|
||||
stopForeground(true)
|
||||
stopSelf()
|
||||
}
|
||||
return newId
|
||||
@@ -72,12 +68,16 @@ abstract class NotificationService : Service() {
|
||||
manager.cancel(id)
|
||||
}
|
||||
|
||||
private fun remove(id: Int) = notifications.remove(id)
|
||||
.also { updateForeground() }
|
||||
protected fun remove(id: Int) = notifications.remove(id).also {
|
||||
cancel(id)
|
||||
updateForeground()
|
||||
}
|
||||
|
||||
private fun updateForeground() {
|
||||
if (notifications.isNotEmpty())
|
||||
if (hasNotifications)
|
||||
startForeground(notifications.keys.first(), notifications.values.first().build())
|
||||
else
|
||||
stopForeground(true)
|
||||
}
|
||||
|
||||
// --
|
||||
|
||||
@@ -49,6 +49,7 @@ abstract class RemoteFileService : NotificationService() {
|
||||
.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) }
|
||||
|
||||
Reference in New Issue
Block a user