diff --git a/.github/actions/native-build/action.yml b/.github/actions/native-build/action.yml deleted file mode 100644 index 309c6b590..000000000 --- a/.github/actions/native-build/action.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: "Native build" -description: "Performs native builds" -inputs: - cache: - description: "Whether to use the cache or not" - required: true -runs: - using: "composite" - steps: - - name: Load ffmpeg module cache - id: cache_ffmpeg_module - if: ${{ inputs.cache }} - uses: actions/cache/restore@v4 - with: - path: | - app/libs - key: ${{ runner.os }}-ffmpeg-${{ hashFiles('**/libs.versions.toml', '**/scripts/ffmpeg/build_ffmpeg_decoder.sh') }} - - name: Load libmpv module cache - id: cache_libmpv_module - if: ${{ inputs.cache }} - uses: actions/cache/restore@v4 - with: - path: | - app/src/main/libs - key: ${{ runner.os }}-libmpv-${{ hashFiles('**/scripts/mpv/*.sh', '**/scripts/mpv/include/*', '**/scripts/mpv/scripts/*', 'app/src/main/jni/*') }} - - name: Install dependencies - if: steps.cache_ffmpeg_module.outputs.cache-hit != 'true' || steps.cache_libmpv_module.outputs.cache-hit != 'true' - shell: bash - run: | - python -m pip install --upgrade pip - pip install jsonschema jinja2 - sudo apt update - sudo apt install -y build-essential autoconf pkg-config libtool ninja-build unzip wget meson nasm - - -# ffmpeg - - name: Build ffmpeg decoder - id: ffmpeg-decoder - if: steps.cache_ffmpeg_module.outputs.cache-hit != 'true' - shell: bash - run: | - cd scripts/ffmpeg - ./build_ffmpeg_decoder.sh "${{ env.ANDROID_SDK_ROOT }}/ndk/${{ env.NDK_VERSION }}" - - name: Save ffmpeg module cache - id: cache_ffmpeg_module_save - uses: actions/cache/save@v4 - with: - path: | - app/libs - key: ${{ steps.cache_ffmpeg_module.outputs.cache-primary-key }} - -# libmpv - - name: Get libmpv dependencies - if: steps.cache_libmpv_module.outputs.cache-hit != 'true' - shell: bash - run: | - cd scripts/mpv - ./get_dependencies.sh - - name: Build libmpv dependencies - if: steps.cache_libmpv_module.outputs.cache-hit != 'true' - shell: bash - run: | - cd scripts/mpv - ./buildall.sh --clean --arch arm64 mpv - ./buildall.sh mpv - cd ../.. - env PREFIX32="$(realpath scripts/mpv/prefix/armv7l)" PREFIX64="$(realpath scripts/mpv/prefix/arm64)" ndk-build -C app/src/main -j - - - name: Setup jniLibs - shell: bash - run: | - cd app/src/main - mkdir -p jniLibs - cp -r libs/* jniLibs - #ln -s libs jniLibs - - name: Save libmpv module cache - id: cache_libmpv_module_save - uses: actions/cache/save@v4 - with: - path: | - app/src/main/libs - key: ${{ steps.cache_libmpv_module.outputs.cache-primary-key }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 2f39c41a0..e04fb7699 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -38,16 +38,15 @@ jobs: submodules: true # Need the submodules to build - name: Setup uses: ./.github/actions/setup - - name: Native build - uses: ./.github/actions/native-build - with: - cache: true - name: Build app id: buildapp run: | ./gradlew clean assembleDebug testDebugUnitTest --no-daemon apks=$(find app/build/outputs/apk -name '*.apk' -print0 | tr '\0' ',' | sed 's/,$//') echo "apks=$apks" >> "$GITHUB_OUTPUT" + env: + ORG_GRADLE_PROJECT_WholphinExtensionsUsername: "${{ secrets.EXTENSIONS_USERNAME }}" + ORG_GRADLE_PROJECT_WholphinExtensionsPassword: "${{ secrets.EXTENSIONS_PASSWORD }}" - name: Tar build dirs run: | tar -czf build.tgz ./app/. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5fd885756..bb9130786 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,10 +27,6 @@ jobs: submodules: true # Need the submodules to build - name: Setup uses: ./.github/actions/setup - - name: Native build - uses: ./.github/actions/native-build - with: - cache: false - name: Build app id: buildapp env: @@ -38,6 +34,8 @@ jobs: KEY_PASSWORD: "${{ secrets.KEY_PASSWORD }}" KEY_STORE_PASSWORD: "${{ secrets.KEY_STORE_PASSWORD }}" SIGNING_KEY: "${{ secrets.SIGNING_KEY }}" + ORG_GRADLE_PROJECT_WholphinExtensionsUsername: "${{ secrets.EXTENSIONS_USERNAME }}" + ORG_GRADLE_PROJECT_WholphinExtensionsPassword: "${{ secrets.EXTENSIONS_PASSWORD }}" run: | ./gradlew clean assembleRelease --no-daemon - name: Verify signatures diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 33d0a3bff..d044b167a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,4 +1,5 @@ - +import com.android.build.api.dsl.ApplicationExtension +import com.android.build.api.variant.FilterConfiguration import com.android.build.gradle.internal.cxx.io.writeTextIfDifferent import com.android.build.gradle.internal.tasks.factory.dependsOn import com.google.protobuf.gradle.id @@ -6,13 +7,11 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import java.util.Base64 val isCI = if (System.getenv("CI") != null) System.getenv("CI").toBoolean() else false -val ffmpegModuleExists = project.file("libs/lib-decoder-ffmpeg-release.aar").exists() -val av1ModuleExists = project.file("libs/lib-decoder-av1-release.aar").exists() val shouldSign = isCI && System.getenv("KEY_ALIAS") != null +val extensionsRepoActive = project.hasProperty("WholphinExtensionsUsername") plugins { alias(libs.plugins.android.application) - alias(libs.plugins.kotlin.android) alias(libs.plugins.ksp) id("kotlin-parcelize") alias(libs.plugins.apollo) @@ -34,7 +33,15 @@ val gitDescribe = .standardOutput.asText .getOrElse("v0.0.0") -android { +kotlin { + compilerOptions { + languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_3 + jvmTarget = JvmTarget.JVM_11 + javaParameters = true + } +} + +configure { namespace = "com.github.damontecres.stashapp" compileSdk = 36 @@ -99,18 +106,6 @@ android { signingConfig = signingConfigs.getByName("ci") } } - - applicationVariants.all { - val variant = this - variant.outputs - .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } - .forEach { output -> - val abi = output.getFilter("ABI").let { if (it != null) "-$it" else "" } - val outputFileName = - "StashAppAndroidTV-${variant.baseName}-${variant.versionName}-${variant.versionCode}$abi.apk" - output.outputFileName = outputFileName - } - } } splits { abi { @@ -125,18 +120,29 @@ android { targetCompatibility = JavaVersion.VERSION_11 isCoreLibraryDesugaringEnabled = true } - kotlin { - compilerOptions { - jvmTarget = JvmTarget.JVM_11 - javaParameters = true - } - } lint { disable.add("MissingTranslation") disable.add("LocalContextGetResourceValueCall") // TODO } - room { - schemaDirectory("$projectDir/schemas") +} + +room { + schemaDirectory("$projectDir/schemas") +} + +androidComponents { + onVariants(selector().all()) { variant -> + variant.outputs + .map { it as com.android.build.api.variant.impl.VariantOutputImpl } + .forEach { output -> + val abi = + output + .getFilter(FilterConfiguration.FilterType.ABI) + .let { if (it != null) "-${it.identifier}" else "" } + val outputFileName = + "StashAppAndroidTV-${variant.flavorName}-${variant.buildType}-${output.versionName.get()}-${output.versionCode.get()}$abi.apk" + output.outputFileName = outputFileName + } } } @@ -172,11 +178,6 @@ apollo { packageName.set("com.github.damontecres.stashapp.api") schemaFile = File("$projectDir/src/main/graphql/schema.graphqls") generateOptionalOperationVariables.set(false) - outputDirConnection { - // Fixes where classes aren't detected in unit tests - // See: https://community.apollographql.com/t/android-warning-duplicate-content-roots-detected-after-just-adding-apollo3-kotlin-client/4529/6 - connectToKotlinSourceSet("main") - } plugin(project(":apollo-compiler")) } } @@ -299,11 +300,12 @@ dependencies { implementation(libs.multiplatform.markdown.renderer) implementation(libs.multiplatform.markdown.renderer.m3) - if (ffmpegModuleExists || isCI) { - implementation(files("libs/lib-decoder-ffmpeg-release.aar")) - } - if (av1ModuleExists || isCI) { - implementation(files("libs/lib-decoder-av1-release.aar")) + implementation(libs.timber) + implementation(libs.slf4j2.timber) + if (extensionsRepoActive) { + implementation(libs.wholphin.extensions.mpv) + implementation(libs.wholphin.extensions.ffmpeg) + implementation(libs.wholphin.extensions.av1) } testImplementation(libs.androidx.test.core.ktx) diff --git a/app/src/main/java/com/github/damontecres/stashapp/StashApplication.kt b/app/src/main/java/com/github/damontecres/stashapp/StashApplication.kt index 2cf493785..5c0810a49 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/StashApplication.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/StashApplication.kt @@ -29,6 +29,7 @@ import org.acra.ReportField import org.acra.config.dialog import org.acra.data.StringFormat import org.acra.ktx.initAcra +import timber.log.Timber class StashApplication : Application() { @OptIn(ExperimentalComposeRuntimeApi::class) @@ -52,6 +53,8 @@ class StashApplication : Application() { // ) } + Timber.plant(Timber.DebugTree()) + application = this val pkgInfo = packageManager.getPackageInfo(packageName, 0) diff --git a/app/src/main/java/com/github/damontecres/stashapp/StashExoPlayer.kt b/app/src/main/java/com/github/damontecres/stashapp/StashExoPlayer.kt index b5b7a0419..d68fce95e 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/StashExoPlayer.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/StashExoPlayer.kt @@ -19,13 +19,16 @@ import androidx.media3.extractor.ts.TsExtractor import androidx.preference.PreferenceManager import com.github.damontecres.stashapp.StashExoPlayer.Companion.getInstance import com.github.damontecres.stashapp.proto.PlaybackBackend +import com.github.damontecres.stashapp.proto.PlaybackHttpClient +import com.github.damontecres.stashapp.proto.PlaybackPreferences +import com.github.damontecres.stashapp.proto.copy import com.github.damontecres.stashapp.util.Constants import com.github.damontecres.stashapp.util.SkipParams import com.github.damontecres.stashapp.util.StashClient import com.github.damontecres.stashapp.util.StashServer -import com.github.damontecres.stashapp.util.getPreference import com.github.damontecres.stashapp.util.isNotNullOrBlank import com.github.damontecres.stashapp.util.mpv.MpvPlayer +import timber.log.Timber /** * Manages a static [ExoPlayer] which might be reused between views @@ -41,46 +44,40 @@ class StashExoPlayer private constructor() { private var instance: Player? = null // Volatile modifier is necessary @Volatile - private var skipParams: SkipParams? = null + private var playbackPreferences: PlaybackPreferences? = null @OptIn(UnstableApi::class) - fun getInstance( + fun getInstanceForCard( context: Context, server: StashServer, - ): Player = getInstance(context, server, SkipParams.Default) + ): Player = + getInstance( + context, + server, + PlaybackPreferences + .newBuilder() + .apply { + playbackBackend = PlaybackBackend.EXO_PLAYER + skipForwardMs = 30_000 + skipBackwardMs = 30_000 + }.build(), + ) @OptIn(UnstableApi::class) fun getInstance( context: Context, server: StashServer, - skipParams: SkipParams, - httpClientChoice: String = - getPreference( - context, - R.string.pref_key_playback_http_client, - context.getString(R.string.playback_http_client_okhttp), - )!!, - debugLogging: Boolean = - getPreference( - context, - R.string.pref_key_playback_debug_logging, - false, - ), - backend: PlaybackBackend = PlaybackBackend.EXO_PLAYER, + playbackPreferences: PlaybackPreferences, ): Player { - if (instance == null || skipParams != this.skipParams) { + if (instance == null || playbackPreferences != this.playbackPreferences) { synchronized(this) { // synchronized to avoid concurrency problem - if (instance == null || skipParams != this.skipParams) { - this.skipParams = skipParams + if (instance == null || playbackPreferences != this.playbackPreferences) { instance = createInstance( context, server, - skipParams, - httpClientChoice, - debugLogging, - backend, + playbackPreferences, ) } } @@ -95,19 +92,30 @@ class StashExoPlayer private constructor() { fun createInstance( context: Context, server: StashServer, - skipParams: SkipParams, - httpClientChoice: String, - debugLogging: Boolean, - backend: PlaybackBackend = PlaybackBackend.EXO_PLAYER, + playbackPreferences: PlaybackPreferences, ): Player { releasePlayer() - Log.i(TAG, "backend=$backend") - return if (backend == PlaybackBackend.MPV) { - MpvPlayer(context, true, false) + Timber.i("backend=%s", playbackPreferences.playbackBackend) + val skipParams = + playbackPreferences.let { + SkipParams.Values( + it.skipForwardMs, + it.skipBackwardMs, + ) + } + val httpClient = playbackPreferences.playbackHttpClient + val debugLogging = playbackPreferences.debugLoggingEnabled + this.playbackPreferences = playbackPreferences.copy {} + return if (playbackPreferences.playbackBackend == PlaybackBackend.MPV) { + MpvPlayer( + context, + playbackPreferences.mpvPreferences.hardwareDecoding, + playbackPreferences.mpvPreferences.gpuNext, + ) } else { val dataSourceFactory = - when (httpClientChoice.lowercase()) { - context.getString(R.string.playback_http_client_okhttp) -> { + when (httpClient) { + PlaybackHttpClient.OKHTTP -> { OkHttpDataSource .Factory(server.streamingOkHttpClient) } @@ -215,7 +223,7 @@ class StashExoPlayer private constructor() { instance!!.release() } instance = null - skipParams = null + playbackPreferences = null } } } diff --git a/app/src/main/java/com/github/damontecres/stashapp/image/ImageClipFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/image/ImageClipFragment.kt index 2e7a20a98..ca747c8f0 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/image/ImageClipFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/image/ImageClipFragment.kt @@ -14,6 +14,7 @@ import com.github.damontecres.stashapp.StashApplication import com.github.damontecres.stashapp.StashExoPlayer import com.github.damontecres.stashapp.playback.StashPlayerView import com.github.damontecres.stashapp.playback.maybeMuteAudio +import com.github.damontecres.stashapp.ui.playbackPreferencesForOldUi import com.github.damontecres.stashapp.util.StashServer import com.github.damontecres.stashapp.util.isImageClip import com.github.damontecres.stashapp.util.keepScreenOn @@ -91,11 +92,13 @@ class ImageClipFragment : override fun onStart() { // Always release the player and recreate StashExoPlayer.releasePlayer() + val playbackPreferences = requireContext().playbackPreferencesForOldUi player = StashExoPlayer .getInstance( requireContext(), StashServer.requireCurrentServer(), + playbackPreferences, ).also { videoView.player = it it.repeatMode = diff --git a/app/src/main/java/com/github/damontecres/stashapp/playback/PlaybackFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/playback/PlaybackFragment.kt index 8f59de7ad..163a3ace3 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/playback/PlaybackFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/playback/PlaybackFragment.kt @@ -41,6 +41,7 @@ import com.github.damontecres.stashapp.data.Scene import com.github.damontecres.stashapp.data.ThrottledLiveData import com.github.damontecres.stashapp.isReleased import com.github.damontecres.stashapp.navigation.Destination +import com.github.damontecres.stashapp.ui.playbackPreferencesForOldUi import com.github.damontecres.stashapp.util.Constants import com.github.damontecres.stashapp.util.KeyEventDispatcher import com.github.damontecres.stashapp.util.MutationEngine @@ -152,12 +153,13 @@ abstract class PlaybackFragment( return false } - private fun preparePlayer(): Player = - StashExoPlayer + private fun preparePlayer(): Player { + val playbackPreferences = requireContext().playbackPreferencesForOldUi + return StashExoPlayer .getInstance( requireContext(), serverViewModel.requireServer(), - skipParams, + playbackPreferences, ).also { it.setupPlayer() } .also { StashExoPlayer.addListener( @@ -220,6 +222,7 @@ abstract class PlaybackFragment( }, ) } + } protected fun updateDebugInfo( streamDecision: StreamDecision, diff --git a/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt b/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt index eddb18fda..c3e7fd800 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt @@ -285,7 +285,7 @@ class StashImageCardView( .setUri(Uri.parse(videoUrl)) .setMimeType(MimeTypes.VIDEO_MP4) .build() - val player = StashExoPlayer.getInstance(context, StashServer.requireCurrentServer()) + val player = StashExoPlayer.getInstanceForCard(context, StashServer.requireCurrentServer()) StashExoPlayer.addListener(listener) if (videoView == null) { diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/Extensions.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/Extensions.kt index b5d6d55ab..2b9facf98 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/Extensions.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/Extensions.kt @@ -39,13 +39,19 @@ import com.github.damontecres.stashapp.api.type.FloatCriterionInput import com.github.damontecres.stashapp.api.type.ImageFilterType import com.github.damontecres.stashapp.api.type.IntCriterionInput import com.github.damontecres.stashapp.navigation.NavigationManager +import com.github.damontecres.stashapp.proto.PlaybackBackend +import com.github.damontecres.stashapp.proto.PlaybackPreferences import com.github.damontecres.stashapp.proto.StashPreferences +import com.github.damontecres.stashapp.proto.copy import com.github.damontecres.stashapp.suppliers.FilterArgs import com.github.damontecres.stashapp.ui.compat.detectTvDevice import com.github.damontecres.stashapp.util.StashServer import com.github.damontecres.stashapp.util.getFilterArgs import com.github.damontecres.stashapp.util.name +import com.github.damontecres.stashapp.util.preferences import com.github.damontecres.stashapp.util.putFilterArgs +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking import kotlin.time.Duration.Companion.seconds data class GlobalContext( @@ -62,7 +68,7 @@ object PlayerContext { context: Context, server: StashServer, ): Player = - StashExoPlayer.getInstance(context, server).apply { + StashExoPlayer.getInstanceForCard(context, server).apply { repeatMode = Player.REPEAT_MODE_ONE playWhenReady = true } @@ -189,3 +195,11 @@ val ImageFilterType.galleryId: String? } } } + +val Context.playbackPreferencesForOldUi: PlaybackPreferences + get() = + runBlocking { + this@playbackPreferencesForOldUi.preferences.data.first().playbackPreferences.copy { + playbackBackend = PlaybackBackend.EXO_PLAYER + } + } diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/PreferencesContent.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/PreferencesContent.kt index cf53c2e8b..11b2332a1 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/PreferencesContent.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/PreferencesContent.kt @@ -168,6 +168,13 @@ val advancedPreferences = StashPreference.DirectPlayFormat, ), ), + PreferenceGroup( + R.string.mpv_settings, + listOf( + StashPreference.MpvHardwareDecoding, + StashPreference.MpvGpuNext, + ), + ), PreferenceGroup( R.string.screensaver, listOf( diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/StashPreference.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/StashPreference.kt index b0b716ebf..9583da99a 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/StashPreference.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/components/prefs/StashPreference.kt @@ -27,6 +27,7 @@ import com.github.damontecres.stashapp.util.isNotNullOrBlank import com.github.damontecres.stashapp.util.updateAdvancedPreferences import com.github.damontecres.stashapp.util.updateCachePreferences import com.github.damontecres.stashapp.util.updateInterfacePreferences +import com.github.damontecres.stashapp.util.updateMpvPreferences import com.github.damontecres.stashapp.util.updatePinPreferences import com.github.damontecres.stashapp.util.updatePlaybackPreferences import com.github.damontecres.stashapp.util.updateScreensaverPreferences @@ -1393,6 +1394,32 @@ sealed interface StashPreference { }, ) + val MpvHardwareDecoding = + StashSwitchPreference( + title = R.string.mpv_hardware_decoding, + prefKey = R.string.pref_key_mpv_hardware_decoding, + defaultValue = true, + getter = { it.playbackPreferences.mpvPreferences.hardwareDecoding }, + setter = { prefs, value -> + prefs.updateMpvPreferences { hardwareDecoding = value } + }, + summaryOn = R.string.stashapp_actions_enable, + summaryOff = R.string.transcode_options_disabled, + ) + + val MpvGpuNext = + StashSwitchPreference( + title = R.string.mpv_gpu_next, + prefKey = R.string.pref_key_mpv_gpu_next, + defaultValue = false, + getter = { it.playbackPreferences.mpvPreferences.gpuNext }, + setter = { prefs, value -> + prefs.updateMpvPreferences { gpuNext = value } + }, + summaryOn = R.string.stashapp_actions_enable, + summaryOff = R.string.transcode_options_disabled, + ) + val ImageThreads = StashSliderPreference( title = R.string.image_loading_threads, diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/ImagePage.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/ImagePage.kt index 114c5e6e9..727da3093 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/ImagePage.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/ImagePage.kt @@ -260,11 +260,13 @@ fun ImagePage( } val player = remember { - StashExoPlayer.getInstance(context, server).apply { - maybeMuteAudio(uiConfig.preferences, false, this) - repeatMode = Player.REPEAT_MODE_OFF - playWhenReady = true - } + StashExoPlayer + .getInstance(context, server, uiConfig.preferences.playbackPreferences) + .apply { + maybeMuteAudio(uiConfig.preferences, false, this) + repeatMode = Player.REPEAT_MODE_OFF + playWhenReady = true + } } LifecycleStartEffect(Unit) { onStopOrDispose { diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/MarkerTimestampPage.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/MarkerTimestampPage.kt index d86c6c9c9..526efc171 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/MarkerTimestampPage.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/MarkerTimestampPage.kt @@ -126,9 +126,14 @@ fun MarkerTimestampPage( val player = remember { - StashExoPlayer.getInstance(context, server).apply { - playWhenReady = false - } + StashExoPlayer + .getInstance( + context, + server, + uiConfig.preferences.playbackPreferences, + ).apply { + playWhenReady = false + } } var timestampChanged by remember { mutableStateOf(false) } val presentationState = rememberPresentationState(player) diff --git a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/PlaybackPage.kt b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/PlaybackPage.kt index b9241a089..4ce9035e9 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/ui/pages/PlaybackPage.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/ui/pages/PlaybackPage.kt @@ -52,7 +52,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlin.time.Duration -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @Composable @@ -95,10 +94,7 @@ fun PlaybackPage( .getInstance( context, server, - skipParams, - httpClient.name, - debugLogging, - backend, + uiConfig.preferences.playbackPreferences, ).apply { repeatMode = Player.REPEAT_MODE_OFF playWhenReady = true @@ -227,27 +223,8 @@ fun PlaylistPlaybackPage( if (playlist.isNotEmpty()) { val player = remember { - val skipForward = - uiConfig.preferences.playbackPreferences.skipForwardMs.milliseconds - val skipBack = - uiConfig.preferences.playbackPreferences.skipBackwardMs.milliseconds - val skipParams = - if (viewModel.dataType == DataType.MARKER) { - // Override the skip forward/back since many users will have default seeking values larger than the duration - SkipParams.Values( - (clipDuration / 4).coerceAtMost(skipForward).inWholeMilliseconds, - (clipDuration / 4).coerceAtMost(skipBack).inWholeMilliseconds, - ) - } else { - SkipParams.Values( - skipForward.inWholeMilliseconds, - skipBack.inWholeMilliseconds, - ) - } - val httpClient = uiConfig.preferences.playbackPreferences.playbackHttpClient - val debugLogging = uiConfig.preferences.playbackPreferences.debugLoggingEnabled StashExoPlayer - .getInstance(context, server, skipParams, httpClient.name, debugLogging) + .getInstance(context, server, uiConfig.preferences.playbackPreferences) .apply { repeatMode = Player.REPEAT_MODE_OFF playWhenReady = true diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/AppUpgradeHandler.kt b/app/src/main/java/com/github/damontecres/stashapp/util/AppUpgradeHandler.kt index 71ff3ad7d..5f138021a 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/AppUpgradeHandler.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/AppUpgradeHandler.kt @@ -202,6 +202,16 @@ class AppUpgradeHandler( } } } + if (previousVersion.isLessThan(Version.fromString("v0.9.0-2-g0"))) { + CoroutineScope(Dispatchers.IO + StashCoroutineExceptionHandler()).launch { + context.preferences.updateData { + it.updateMpvPreferences { + hardwareDecoding = StashPreference.MpvHardwareDecoding.defaultValue + gpuNext = StashPreference.MpvGpuNext.defaultValue + } + } + } + } } private fun SharedPreferences.ensureSetHas( diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/StashPreferencesSerializer.kt b/app/src/main/java/com/github/damontecres/stashapp/util/StashPreferencesSerializer.kt index fc0429481..f90786fe0 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/StashPreferencesSerializer.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/StashPreferencesSerializer.kt @@ -8,6 +8,7 @@ import androidx.datastore.dataStore import com.github.damontecres.stashapp.proto.AdvancedPreferences import com.github.damontecres.stashapp.proto.CachePreferences import com.github.damontecres.stashapp.proto.InterfacePreferences +import com.github.damontecres.stashapp.proto.MpvPreferences import com.github.damontecres.stashapp.proto.PinPreferences import com.github.damontecres.stashapp.proto.PlaybackPreferences import com.github.damontecres.stashapp.proto.ScreensaverPreferences @@ -83,6 +84,15 @@ object StashPreferencesSerializer : Serializer { addAllDirectPlayVideo(StashPreference.DirectPlayVideo.defaultValue) addAllDirectPlayAudio(StashPreference.DirectPlayAudio.defaultValue) addAllDirectPlayFormat(StashPreference.DirectPlayFormat.defaultValue) + + playbackBackend = StashPreference.PlaybackBackendPref.defaultValue + mpvPreferences = + MpvPreferences + .newBuilder() + .apply { + hardwareDecoding = StashPreference.MpvHardwareDecoding.defaultValue + gpuNext = StashPreference.MpvGpuNext.defaultValue + }.build() }.build() updatePreferences = UpdatePreferences @@ -165,6 +175,11 @@ inline fun StashPreferences.updatePlaybackPreferences(block: PlaybackPreferences playbackPreferences = playbackPreferences.toBuilder().apply(block).build() } +inline fun StashPreferences.updateMpvPreferences(block: MpvPreferences.Builder.() -> Unit): StashPreferences = + updatePlaybackPreferences { + mpvPreferences = mpvPreferences.toBuilder().apply(block).build() + } + inline fun StashPreferences.updateAdvancedPreferences(block: AdvancedPreferences.Builder.() -> Unit): StashPreferences = update { advancedPreferences = advancedPreferences.toBuilder().apply(block).build() diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MPVLib.kt b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MPVLib.kt index e24fd28dd..fd9d23892 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MPVLib.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MPVLib.kt @@ -39,17 +39,9 @@ object MPVLib { external fun create(appctx: Context) - fun initialize() { - synchronized(this) { init() } - } - - private external fun init() - - fun tearDown() { - synchronized(this) { destroy() } - } + external fun init() - private external fun destroy() + external fun destroy() external fun attachSurface(surface: Surface) diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvLogger.kt b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvLogger.kt index c8bc04aa8..3ccf4f600 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvLogger.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvLogger.kt @@ -1,6 +1,6 @@ package com.github.damontecres.stashapp.util.mpv -import android.util.Log +import timber.log.Timber class MpvLogger : MPVLib.LogObserver { override fun logMessage( @@ -19,35 +19,3 @@ class MpvLogger : MPVLib.LogObserver { } } } - -object Timber { - fun wtf( - format: String, - vararg args: Any?, - ) = Log.wtf("MPV", String.format(format, *args)) - - fun e( - format: String, - vararg args: Any?, - ) = Log.e("MPV", String.format(format, *args)) - - fun w( - format: String, - vararg args: Any?, - ) = Log.w("MPV", String.format(format, *args)) - - fun i( - format: String, - vararg args: Any?, - ) = Log.i("MPV", String.format(format, *args)) - - fun d( - format: String, - vararg args: Any?, - ) = Log.d("MPV", String.format(format, *args)) - - fun v( - format: String, - vararg args: Any?, - ) = Log.v("MPV", String.format(format, *args)) -} diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvPlayer.kt b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvPlayer.kt index 1fa46cbf1..bec89c300 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvPlayer.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/mpv/MpvPlayer.kt @@ -48,6 +48,7 @@ import com.github.damontecres.stashapp.util.mpv.MPVLib.MpvEvent.MPV_EVENT_FILE_L import com.github.damontecres.stashapp.util.mpv.MPVLib.MpvEvent.MPV_EVENT_PLAYBACK_RESTART import com.github.damontecres.stashapp.util.mpv.MPVLib.MpvEvent.MPV_EVENT_START_FILE import com.github.damontecres.stashapp.util.mpv.MPVLib.MpvEvent.MPV_EVENT_VIDEO_RECONFIG +import timber.log.Timber import kotlin.concurrent.atomics.AtomicReference import kotlin.concurrent.atomics.ExperimentalAtomicApi import kotlin.concurrent.atomics.update @@ -73,6 +74,8 @@ class MpvPlayer( SurfaceHolder.Callback { companion object { private const val DEBUG = false + + private val initLock = Any() } private var surface: Surface? = null @@ -130,7 +133,7 @@ class MpvPlayer( MPVLib.setOptionString("demuxer-max-back-bytes", "${cacheMegs * 1024 * 1024}") Timber.v("Initializing MPVLib") - MPVLib.initialize() + MPVLib.init() MPVLib.setOptionString("force-window", "no") MPVLib.setOptionString("idle", "yes") @@ -441,7 +444,8 @@ class MpvPlayer( override fun getAudioAttributes(): AudioAttributes = throw UnsupportedOperationException() - override fun setVolume(volume: Float): Unit = throw UnsupportedOperationException() + override fun setVolume(volume: Float) { + } override fun getVolume(): Float = 1f @@ -1085,14 +1089,18 @@ class MpvPlayer( } MpvCommand.INITIALIZE -> { - init() + synchronized(initLock) { + init() + } } MpvCommand.DESTROY -> { - clearVideoSurfaceView(null) - MPVLib.removeLogObserver(mpvLogger) - MPVLib.tearDown() - Timber.d("MPVLib destroyed") + synchronized(initLock) { + MPVLib.setPropertyBoolean("pause", true) + MPVLib.removeLogObserver(mpvLogger) + MPVLib.destroy() + Timber.d("MPVLib destroyed") + } } } } diff --git a/app/src/main/java/com/github/damontecres/stashapp/views/MarkerPickerFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/views/MarkerPickerFragment.kt index b60bccac1..4254bda87 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/views/MarkerPickerFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/views/MarkerPickerFragment.kt @@ -23,6 +23,7 @@ import com.github.damontecres.stashapp.playback.buildMediaItem import com.github.damontecres.stashapp.playback.getStreamChoiceFromPreferences import com.github.damontecres.stashapp.playback.getStreamDecision import com.github.damontecres.stashapp.playback.getTranscodeAboveFromPreferences +import com.github.damontecres.stashapp.ui.playbackPreferencesForOldUi import com.github.damontecres.stashapp.util.MutationEngine import com.github.damontecres.stashapp.util.StashCoroutineExceptionHandler import com.github.damontecres.stashapp.util.StashServer @@ -89,9 +90,14 @@ class MarkerPickerFragment : Fragment(R.layout.marker_picker) { val mediaItem = buildMediaItem(requireContext(), streamDecision, scene) StashExoPlayer.releasePlayer() + val playbackPreferences = requireContext().playbackPreferencesForOldUi val player = StashExoPlayer - .getInstance(requireContext(), serverViewModel.requireServer()) + .getInstance( + requireContext(), + serverViewModel.requireServer(), + playbackPreferences, + ) playerView.player = player sceneTitle.text = diff --git a/app/src/main/proto/preferences.proto b/app/src/main/proto/preferences.proto index 3b2a7a392..fc59d20b7 100644 --- a/app/src/main/proto/preferences.proto +++ b/app/src/main/proto/preferences.proto @@ -104,6 +104,11 @@ enum PlaybackBackend{ MPV = 1; } +message MpvPreferences { + bool hardware_decoding = 1; + bool gpu_next = 2; +} + message PlaybackPreferences { int64 skip_forward_ms = 1; int64 skip_backward_ms = 2; @@ -126,6 +131,7 @@ message PlaybackPreferences { repeated string direct_play_format = 18; PlaybackBackend playback_backend = 19; bool mobile_touch_gestures = 20; + MpvPreferences mpv_preferences = 21; } message CachePreferences { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4a62c072..776f8595f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -244,5 +244,10 @@ Enable screensaver Set filter for screensaver Screensaver + MPV: Ue hardware decoding + playback.mpv.hardwareDecoding + playback.mpv.gpuNext + MPV: Use gpu-next + MPV Settings diff --git a/build.gradle.kts b/build.gradle.kts index 9ea31f414..0097d47db 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.android.application) apply false - alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.ksp) apply false alias(libs.plugins.compose.compiler) apply false diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 000000000..5c34300fa --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,13 @@ +#This file is generated by updateDaemonJvm +toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/56a19bc915b9ba2eb62ba7554c61b919/redirect +toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/398ffe3949748bfb1d5636f023d228fd/redirect +toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/56a19bc915b9ba2eb62ba7554c61b919/redirect +toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/398ffe3949748bfb1d5636f023d228fd/redirect +toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/e99bae143b75f9a10ead10248f02055e/redirect +toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/04e088f8677de3b384108493cc9481d0/redirect +toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/56a19bc915b9ba2eb62ba7554c61b919/redirect +toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/398ffe3949748bfb1d5636f023d228fd/redirect +toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/e55dccbfe27cb97945148c61a39c89c5/redirect +toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/dbd05c4936d573642f94cd149e1356c8/redirect +toolchainVendor=JETBRAINS +toolchainVersion=21 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2f24e1960..308148a52 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,29 +1,29 @@ [versions] acra = "5.13.1" -activity-compose = "1.12.2" +activity-compose = "1.13.0" androidsvg-aar = "1.4" -android-application = "8.13.2" -apollo = "4.4.0" -androidx-media3 = "1.9.0" +android-application = "9.1.1" +apollo = "4.4.3" +androidx-media3 = "1.10.0" androidx-test = "1.7.0" androidx-test-runner = "1.7.0" androidx-test-ext-junit = "1.3.0" androidx-test-ext-truth = "1.7.0" auto-service = "1.1.1" coil-compose = "3.4.0" -compose-bom = "2026.01.00" +compose-bom = "2026.05.00" compose-wheel-picker = "1.0.0-rc02" constraintlayout = "2.2.1" -datastore = "1.2.0" +datastore = "1.2.1" desugar_jdk_libs = "2.1.5" markwon-core = "4.6.2" -core-ktx = "1.17.0" -glide = "5.0.5" +core-ktx = "1.18.0" +glide = "5.0.7" junit = "4.13.2" -kotlin = "2.3.0" +kotlin = "2.3.21" kotlinx-coroutines-android = "1.10.2" -kotlinx-serialization = "1.10.0" -ksp = "2.3.0" +kotlinx-serialization = "1.11.0" +ksp = "2.3.7" leanback = "1.2.0" leanback-preference = "1.2.0" leanback-tab = "1.1.0" @@ -33,24 +33,27 @@ lifecycle-viewmodel-compose = "2.10.0" material = "1.13.0" material3-adaptive = "1.0.0-alpha06" material3-android = "1.4.0" -mockito-core = "5.21.0" -mockito-kotlin = "6.2.2" -multiplatformMarkdownRenderer = "0.39.2" +mockito-core = "5.23.0" +mockito-kotlin = "6.3.0" +multiplatformMarkdownRenderer = "0.40.2" navigation-reimagined = "1.5.0" parcelable-core = "0.9.0" preference-ktx-version = "1.2.1" previewseekbar = "3.1.1" previewseekbar-media3 = "1.1.1.0" -protobuf = "0.9.6" -protobuf-javalite = "4.33.4" +protobuf = "0.10.0" +protobuf-javalite = "4.34.1" restring = "6.0.0" reword = "4.0.4" room = "2.8.4" swiperefreshlayout = "1.2.0" -tv-foundation = "1.0.0-alpha12" -tv-material = "1.0.1" -viewpump = "4.0.14" +tv-foundation = "1.0.0" +tv-material = "1.1.0" +viewpump = "4.0.15" zoomlayout = "1.9.0" +slf4j2Timber = "1.2" +timber = "5.0.1" +wholphin-extensions = "0.1.2" [libraries] acra-dialog = { module = "ch.acra:acra-dialog", version.ref = "acra" } @@ -137,12 +140,17 @@ androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = " androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "tv-material" } androidx-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } androidx-ui-viewbinding = { module = "androidx.compose.ui:ui-viewbinding" } +timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" } +slf4j2-timber = { module = "uk.kulikov:slf4j2-timber", version.ref = "slf4j2Timber" } + +wholphin-extensions-mpv = { module = "com.github.damontecres.wholphin.mpv:wholphin-mpv", version.ref = "wholphin-extensions" } +wholphin-extensions-ffmpeg = { module = "com.github.damontecres.wholphin.media3:decoder-ffmpeg", version.ref = "wholphin-extensions" } +wholphin-extensions-av1 = { module = "com.github.damontecres.wholphin.media3:decoder-av1", version.ref = "wholphin-extensions" } [plugins] android-application = { id = "com.android.application", version.ref = "android-application" } apollo = { id = "com.apollographql.apollo", version.ref = "apollo" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } -kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c02..61285a659 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b7c6aaa60..1a704683a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Fri Mar 22 20:44:36 EDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c8..adff685a0 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,81 +15,114 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..e509b2dd8 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,33 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle.kts b/settings.gradle.kts index 2a781aac3..c44ab6574 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,9 @@ pluginManagement { gradlePluginPortal() } } +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" +} dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -12,6 +15,14 @@ dependencyResolutionManagement { mavenCentral() maven { url = uri("https://repo.repsy.io/mvn/chrynan/public") } maven { url = uri("https://jitpack.io") } + @Suppress("ktlint:standard:property-naming") + val WholphinExtensionsUsername: String? by settings + if (!WholphinExtensionsUsername.isNullOrBlank()) { + maven("https://maven.pkg.github.com/damontecres/wholphin-extensions") { + name = "WholphinExtensions" + credentials(PasswordCredentials::class) + } + } } }