Fix app update install notification disappearing

This commit is contained in:
arkon 2022-06-26 19:11:34 -04:00
parent 7b294478e4
commit 4ca0fc7a4d
3 changed files with 22 additions and 22 deletions

View File

@ -79,6 +79,7 @@ object Notifications {
private const val GROUP_APK_UPDATES = "group_apk_updates"
const val CHANNEL_APP_UPDATE = "app_apk_update_channel"
const val ID_APP_UPDATER = 1
const val ID_APP_UPDATE_PROMPT = 2
const val CHANNEL_EXTENSIONS_UPDATE = "ext_apk_update_channel"
const val ID_UPDATES_TO_EXTS = -401
const val ID_EXTENSION_INSTALLER = -402

View File

@ -61,22 +61,6 @@ internal class AppUpdateNotifier(private val context: Context) {
notificationBuilder.show()
}
/**
* Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based
* updates.
*
* We can prompt them to migrate to the GitHub version though.
*/
fun promptFdroidUpdate() {
with(notificationBuilder) {
setContentTitle(context.getString(R.string.update_check_notification_update_available))
setContentText(context.getString(R.string.update_check_fdroid_migration_info))
setSmallIcon(R.drawable.ic_tachi)
setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/faq/#how-do-i-migrate-from-the-f-droid-version"))
}
notificationBuilder.show()
}
/**
* Call when apk download starts.
*
@ -118,7 +102,7 @@ internal class AppUpdateNotifier(private val context: Context) {
*
* @param uri path location of apk.
*/
fun onDownloadFinished(uri: Uri) {
fun promptInstall(uri: Uri) {
val installIntent = NotificationHandler.installApkPendingActivity(context, uri)
with(notificationBuilder) {
setContentText(context.getString(R.string.update_check_notification_download_complete))
@ -137,10 +121,26 @@ internal class AppUpdateNotifier(private val context: Context) {
addAction(
R.drawable.ic_close_24dp,
context.getString(R.string.action_cancel),
NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATER),
NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATE_PROMPT),
)
}
notificationBuilder.show()
notificationBuilder.show(Notifications.ID_APP_UPDATE_PROMPT)
}
/**
* Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based
* updates.
*
* We can prompt them to migrate to the GitHub version though.
*/
fun promptFdroidUpdate() {
with(notificationBuilder) {
setContentTitle(context.getString(R.string.update_check_notification_update_available))
setContentText(context.getString(R.string.update_check_fdroid_migration_info))
setSmallIcon(R.drawable.ic_tachi)
setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/faq/#how-do-i-migrate-from-the-f-droid-version"))
}
notificationBuilder.show(Notifications.ID_APP_UPDATE_PROMPT)
}
/**

View File

@ -42,7 +42,6 @@ class AppUpdateService : Service() {
private lateinit var notifier: AppUpdateNotifier
private var runningJob: Job? = null
private var runningCall: Call? = null
override fun onCreate() {
@ -133,7 +132,7 @@ class AppUpdateService : Service() {
response.close()
throw Exception("Unsuccessful response")
}
notifier.onDownloadFinished(apkFile.getUriCompat(this))
notifier.promptInstall(apkFile.getUriCompat(this))
} catch (error: Exception) {
logcat(LogPriority.ERROR, error)
if (error is CancellationException ||
@ -195,7 +194,7 @@ class AppUpdateService : Service() {
val intent = Intent(context, AppUpdateService::class.java).apply {
putExtra(EXTRA_DOWNLOAD_URL, url)
}
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
}
}