From 91363ceb716915ad46a52551201d57e059cec34d Mon Sep 17 00:00:00 2001 From: Julien Papasian Date: Tue, 5 Nov 2024 14:22:58 +0100 Subject: [PATCH] Add FOSS flavor --- .github/workflows/build_push.yml | 35 +++++++++++---- app/build.gradle.kts | 11 ++++- .../mihon/core/firebase/FirebaseConfig.kt | 11 +++++ .../more/onboarding/PermissionStep.kt | 43 ++++++++++--------- .../settings/screen/SettingsSecurityScreen.kt | 5 ++- .../more/settings/screen/about/AboutScreen.kt | 3 +- app/src/main/java/eu/kanade/tachiyomi/App.kt | 19 ++++---- .../data/updater/AppUpdateNotifier.kt | 3 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 3 +- .../tachiyomi/util/system/BuildConfig.kt | 3 ++ .../tachiyomi/domain/release/model/Release.kt | 10 ++++- 11 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 app/src/foss/java/mihon/core/firebase/FirebaseConfig.kt diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml index 86b7d2d9e8..860f9ee0cf 100644 --- a/.github/workflows/build_push.yml +++ b/.github/workflows/build_push.yml @@ -51,6 +51,9 @@ jobs: path: app/build/outputs/mapping/standardRelease # Sign APK and create release for tags + - name: Build FOSS flavor + if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' + run: ./gradlew assembleFossRelease - name: Get tag name if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' @@ -58,7 +61,7 @@ jobs: set -x echo "VERSION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - name: Sign APK + - name: Sign APK (standard) if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # v1 with: @@ -68,6 +71,16 @@ jobs: keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} keyPassword: ${{ secrets.KEY_PASSWORD }} + - name: Sign APK (FOSS) + if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' + uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # v1 + with: + releaseDirectory: app/build/outputs/apk/foss/release + signingKeyBase64: ${{ secrets.SIGNING_KEY }} + alias: ${{ secrets.ALIAS }} + keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} + keyPassword: ${{ secrets.KEY_PASSWORD }} + - name: Clean up build artifacts if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' run: | @@ -93,6 +106,10 @@ jobs: sha=`sha256sum mihon-x86_64-${{ env.VERSION_TAG }}.apk | awk '{ print $1 }'` echo "APK_X86_64_SHA=$sha" >> $GITHUB_ENV + mv app/build/outputs/apk/foss/release/app-foss-universal-release-unsigned-signed.apk mihon-${{ env.VERSION_TAG }}.apk + sha=`sha256sum mihon-foss-${{ env.VERSION_TAG }}.apk | awk '{ print $1 }'` + echo "APK_FOSS_UNIVERSAL_SHA=$sha" >> $GITHUB_ENV + - name: Create Release if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mihonapp/mihon' uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8 @@ -104,13 +121,14 @@ jobs: ### Checksums - | Variant | SHA-256 | - | ------- | ------- | - | Universal | ${{ env.APK_UNIVERSAL_SHA }} - | arm64-v8a | ${{ env.APK_ARM64_V8A_SHA }} - | armeabi-v7a | ${{ env.APK_ARMEABI_V7A_SHA }} - | x86 | ${{ env.APK_X86_SHA }} | - | x86_64 | ${{ env.APK_X86_64_SHA }} | + | Flavor | Variant | SHA-256 | + | ------ | ------- | ------- | + | Standard | Universal | ${{ env.APK_UNIVERSAL_SHA }} + | Standard | arm64-v8a | ${{ env.APK_ARM64_V8A_SHA }} + | Standard | armeabi-v7a | ${{ env.APK_ARMEABI_V7A_SHA }} + | Standard | x86 | ${{ env.APK_X86_SHA }} | + | Standard | x86_64 | ${{ env.APK_X86_64_SHA }} | + | FOSS | Universal | ${{ env.APK_FOSS_UNIVERSAL_SHA }} | ## If you are unsure which version to choose then go with mihon-${{ env.VERSION_TAG }}.apk files: | @@ -119,6 +137,7 @@ jobs: mihon-armeabi-v7a-${{ env.VERSION_TAG }}.apk mihon-x86-${{ env.VERSION_TAG }}.apk mihon-x86_64-${{ env.VERSION_TAG }}.apk + mihon-foss-${{ env.VERSION_TAG }}.apk draft: true prerelease: false env: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 20814d2cb7..e9c56dbb7c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -99,6 +99,10 @@ android { buildConfigField("boolean", "INCLUDE_UPDATER", "true") dimension = "default" } + create("foss") { + buildConfigField("boolean", "INCLUDE_UPDATER", "true") + dimension = "default" + } create("dev") { // Include pseudolocales: https://developer.android.com/guide/topics/resources/pseudolocales resourceConfigurations.addAll(listOf("en", "en_XA", "ar_XB", "xxhdpi")) @@ -291,9 +295,12 @@ androidComponents { ) } } + // Only excluding in standard and foss flavors because this breaks + // Layout Inspector's Compose tree onVariants(selector().withFlavor("default" to "standard")) { - // Only excluding in standard flavor because this breaks - // Layout Inspector's Compose tree + it.packaging.resources.excludes.add("META-INF/*.version") + } + onVariants(selector().withFlavor("default" to "foss")) { it.packaging.resources.excludes.add("META-INF/*.version") } } diff --git a/app/src/foss/java/mihon/core/firebase/FirebaseConfig.kt b/app/src/foss/java/mihon/core/firebase/FirebaseConfig.kt new file mode 100644 index 0000000000..820543bd0d --- /dev/null +++ b/app/src/foss/java/mihon/core/firebase/FirebaseConfig.kt @@ -0,0 +1,11 @@ +package mihon.core.firebase + +import android.content.Context + +object FirebaseConfig { + fun init(context: Context) = Unit + + fun setAnalyticsEnabled(enabled: Boolean) = Unit + + fun setCrashlyticsEnabled(enabled: Boolean) = Unit +} diff --git a/app/src/main/java/eu/kanade/presentation/more/onboarding/PermissionStep.kt b/app/src/main/java/eu/kanade/presentation/more/onboarding/PermissionStep.kt index 6ad493b7eb..2e30e243ba 100644 --- a/app/src/main/java/eu/kanade/presentation/more/onboarding/PermissionStep.kt +++ b/app/src/main/java/eu/kanade/presentation/more/onboarding/PermissionStep.kt @@ -37,6 +37,7 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.compose.LocalLifecycleOwner import eu.kanade.presentation.util.rememberRequestPackageInstallsPermissionState import eu.kanade.tachiyomi.core.security.PrivacyPreferences +import eu.kanade.tachiyomi.util.system.isFossFlavor import eu.kanade.tachiyomi.util.system.launchRequestPackageInstallsPermission import tachiyomi.i18n.MR import tachiyomi.presentation.core.i18n.stringResource @@ -117,28 +118,30 @@ internal class PermissionStep : OnboardingStep { }, ) - HorizontalDivider( - modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp), - color = MaterialTheme.colorScheme.onPrimaryContainer, - ) + if (!isFossFlavor) { + HorizontalDivider( + modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp), + color = MaterialTheme.colorScheme.onPrimaryContainer, + ) - val crashlyticsPref = privacyPreferences.crashlytics() - val crashlytics by crashlyticsPref.collectAsState() - PermissionSwitch( - title = stringResource(MR.strings.onboarding_permission_crashlytics), - subtitle = stringResource(MR.strings.onboarding_permission_crashlytics_description), - granted = crashlytics, - onToggleChange = crashlyticsPref::set, - ) + val crashlyticsPref = privacyPreferences.crashlytics() + val crashlytics by crashlyticsPref.collectAsState() + PermissionSwitch( + title = stringResource(MR.strings.onboarding_permission_crashlytics), + subtitle = stringResource(MR.strings.onboarding_permission_crashlytics_description), + granted = crashlytics, + onToggleChange = crashlyticsPref::set, + ) - val analyticsPref = privacyPreferences.analytics() - val analytics by analyticsPref.collectAsState() - PermissionSwitch( - title = stringResource(MR.strings.onboarding_permission_analytics), - subtitle = stringResource(MR.strings.onboarding_permission_analytics_description), - granted = analytics, - onToggleChange = analyticsPref::set, - ) + val analyticsPref = privacyPreferences.analytics() + val analytics by analyticsPref.collectAsState() + PermissionSwitch( + title = stringResource(MR.strings.onboarding_permission_analytics), + subtitle = stringResource(MR.strings.onboarding_permission_analytics_description), + granted = analytics, + onToggleChange = analyticsPref::set, + ) + } } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt index 315cc41fb7..77d6f66019 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.core.security.PrivacyPreferences import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported +import eu.kanade.tachiyomi.util.system.isFossFlavor import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableMap import tachiyomi.core.common.i18n.stringResource @@ -31,9 +32,9 @@ object SettingsSecurityScreen : SearchableSettings { override fun getPreferences(): List { val securityPreferences = remember { Injekt.get() } val privacyPreferences = remember { Injekt.get() } - return listOf( + return listOfNotNull( getSecurityGroup(securityPreferences), - getFirebaseGroup(privacyPreferences), + if (!isFossFlavor) getFirebaseGroup(privacyPreferences) else null, ) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/about/AboutScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/about/AboutScreen.kt index e91a0576c7..ebdbe90c95 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/about/AboutScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/about/AboutScreen.kt @@ -35,6 +35,7 @@ import eu.kanade.tachiyomi.ui.more.NewUpdateScreen import eu.kanade.tachiyomi.util.CrashLogUtil import eu.kanade.tachiyomi.util.lang.toDateTimestampString import eu.kanade.tachiyomi.util.system.copyToClipboard +import eu.kanade.tachiyomi.util.system.isFossFlavor import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.launch import logcat.LogPriority @@ -121,7 +122,7 @@ object AboutScreen : Screen() { versionName = result.release.version, changelogInfo = result.release.info, releaseLink = result.release.releaseLink, - downloadLink = result.release.getDownloadLink(), + downloadLink = result.release.getDownloadLink(isFossFlavor), ) navigator.push(updateScreen) }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 0f15cf0952..7c35126042 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -44,6 +44,7 @@ import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.animatorDurationScale import eu.kanade.tachiyomi.util.system.cancelNotification +import eu.kanade.tachiyomi.util.system.isFossFlavor import eu.kanade.tachiyomi.util.system.notify import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn @@ -132,15 +133,17 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor } .launchIn(scope) - privacyPreferences.analytics() - .changes() - .onEach(FirebaseConfig::setAnalyticsEnabled) - .launchIn(scope) + if (!isFossFlavor) { + privacyPreferences.analytics() + .changes() + .onEach(FirebaseConfig::setAnalyticsEnabled) + .launchIn(scope) - privacyPreferences.crashlytics() - .changes() - .onEach(FirebaseConfig::setCrashlyticsEnabled) - .launchIn(scope) + privacyPreferences.crashlytics() + .changes() + .onEach(FirebaseConfig::setCrashlyticsEnabled) + .launchIn(scope) + } setAppCompatDelegateThemeMode(Injekt.get().themeMode().get()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt index 35147790f3..c21399ae61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.util.system.isFossFlavor import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notify import tachiyomi.core.common.i18n.stringResource @@ -38,7 +39,7 @@ internal class AppUpdateNotifier(private val context: Context) { fun promptUpdate(release: Release) { val updateIntent = NotificationReceiver.downloadAppUpdatePendingBroadcast( context, - release.getDownloadLink(), + release.getDownloadLink(isFossFlavor), release.version, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index aefe0fe77a..2fcfb0c8fa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -78,6 +78,7 @@ import eu.kanade.tachiyomi.ui.manga.MangaScreen import eu.kanade.tachiyomi.ui.more.NewUpdateScreen import eu.kanade.tachiyomi.ui.more.OnboardingScreen import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.system.isFossFlavor import eu.kanade.tachiyomi.util.system.isNavigationBarNeedsScrim import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.view.setComposeContent @@ -303,7 +304,7 @@ class MainActivity : BaseActivity() { versionName = result.release.version, changelogInfo = result.release.info, releaseLink = result.release.releaseLink, - downloadLink = result.release.getDownloadLink(), + downloadLink = result.release.getDownloadLink(isFossFlavor), ) navigator.push(updateScreen) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/BuildConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/BuildConfig.kt index 933f44d904..881b4f82d9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/BuildConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/BuildConfig.kt @@ -5,6 +5,9 @@ import eu.kanade.tachiyomi.BuildConfig val isDevFlavor: Boolean get() = BuildConfig.FLAVOR == "dev" +val isFossFlavor: Boolean + get() = BuildConfig.FLAVOR == "foss" + val isPreviewBuildType: Boolean get() = BuildConfig.BUILD_TYPE == "preview" diff --git a/domain/src/main/java/tachiyomi/domain/release/model/Release.kt b/domain/src/main/java/tachiyomi/domain/release/model/Release.kt index 311d2f34ff..15a0124c58 100644 --- a/domain/src/main/java/tachiyomi/domain/release/model/Release.kt +++ b/domain/src/main/java/tachiyomi/domain/release/model/Release.kt @@ -16,7 +16,13 @@ data class Release( * Get download link of latest release from the assets. * @return download link of latest release. */ - fun getDownloadLink(): String { + fun getDownloadLink(isFossFlavor: Boolean): String { + val fossFlavor = if (isFossFlavor) { + "foss" + } else { + "" + } + val apkVariant = when (Build.SUPPORTED_ABIS[0]) { "arm64-v8a" -> "-arm64-v8a" "armeabi-v7a" -> "-armeabi-v7a" @@ -25,7 +31,7 @@ data class Release( else -> "" } - return assets.find { it.contains("mihon$apkVariant-") } ?: assets[0] + return assets.find { it.contains("mihon$fossFlavor$apkVariant-") } ?: assets[0] } /**