mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Show different update notification for F-Droid installations
This commit is contained in:
		| @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper | ||||
| import eu.kanade.tachiyomi.network.await | ||||
| import eu.kanade.tachiyomi.network.parseAs | ||||
| import eu.kanade.tachiyomi.util.lang.withIOContext | ||||
| import eu.kanade.tachiyomi.util.system.getInstallerPackageName | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| import java.util.Date | ||||
| import java.util.concurrent.TimeUnit | ||||
| @@ -33,14 +34,19 @@ class AppUpdateChecker { | ||||
|  | ||||
|                     // Check if latest version is different from current version | ||||
|                     if (isNewVersion(it.version)) { | ||||
|                         AppUpdateResult.NewUpdate(it) | ||||
|                         if (context.getInstallerPackageName() == "org.fdroid.fdroid") { | ||||
|                             AppUpdateResult.NewUpdateFdroidInstallation | ||||
|                         } else { | ||||
|                             AppUpdateResult.NewUpdate(it) | ||||
|                         } | ||||
|                     } else { | ||||
|                         AppUpdateResult.NoNewUpdate | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|             if (result is AppUpdateResult.NewUpdate) { | ||||
|                 AppUpdateNotifier(context).promptUpdate(result.release) | ||||
|             when (result) { | ||||
|                 is AppUpdateResult.NewUpdate -> AppUpdateNotifier(context).promptUpdate(result.release) | ||||
|                 is AppUpdateResult.NewUpdateFdroidInstallation -> AppUpdateNotifier(context).promptFdroidUpdate() | ||||
|             } | ||||
|  | ||||
|             result | ||||
|   | ||||
| @@ -58,6 +58,22 @@ 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/guides/troubleshooting/#unable-to-install-the-app-or-extensions")) | ||||
|         } | ||||
|         notificationBuilder.show() | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Call when apk download starts. | ||||
|      * | ||||
|   | ||||
| @@ -2,5 +2,6 @@ package eu.kanade.tachiyomi.data.updater | ||||
|  | ||||
| sealed class AppUpdateResult { | ||||
|     class NewUpdate(val release: GithubRelease) : AppUpdateResult() | ||||
|     object NewUpdateFdroidInstallation : AppUpdateResult() | ||||
|     object NoNewUpdate : AppUpdateResult() | ||||
| } | ||||
|   | ||||
| @@ -382,6 +382,19 @@ fun Context.isPackageInstalled(packageName: String): Boolean { | ||||
|     } | ||||
| } | ||||
|  | ||||
| fun Context.getInstallerPackageName(): String? { | ||||
|     return try { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||||
|             packageManager.getInstallSourceInfo(packageName).installingPackageName | ||||
|         } else { | ||||
|             @Suppress("DEPRECATION") | ||||
|             packageManager.getInstallerPackageName(packageName) | ||||
|         } | ||||
|     } catch (e: Exception) { | ||||
|         null | ||||
|     } | ||||
| } | ||||
|  | ||||
| fun Context.getApplicationIcon(pkgName: String): Drawable? { | ||||
|     return try { | ||||
|         packageManager.getApplicationIcon(pkgName) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user