Automatic refresh rate switching setting (#382)

Adds an advanced playback setting to enable automatic refresh rate
switching during playback

When enabled, the app looks at the available display modes, chooses the
best candidate, and attempts to switch to it. After playback ends, the
display is switched back to the original mode.

Closes #62
Closes #379
This commit is contained in:
damontecres 2025-12-06 16:35:43 -05:00 committed by GitHub
parent e669f3ad59
commit 20bef8fb6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 176 additions and 3 deletions

View file

@ -39,6 +39,7 @@ import com.github.damontecres.wholphin.services.DeviceProfileService
import com.github.damontecres.wholphin.services.ImageUrlService
import com.github.damontecres.wholphin.services.NavigationManager
import com.github.damontecres.wholphin.services.PlaybackLifecycleObserver
import com.github.damontecres.wholphin.services.RefreshRateService
import com.github.damontecres.wholphin.services.ServerEventListener
import com.github.damontecres.wholphin.services.UpdateChecker
import com.github.damontecres.wholphin.services.hilt.AuthOkHttpClient
@ -93,6 +94,9 @@ class MainActivity : AppCompatActivity() {
@Inject
lateinit var imageUrlService: ImageUrlService
@Inject
lateinit var refreshRateService: RefreshRateService
@OptIn(ExperimentalTvMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -101,6 +105,14 @@ class MainActivity : AppCompatActivity() {
if (savedInstanceState == null) {
appUpgradeHandler.copySubfont(false)
}
refreshRateService.refreshRateMode.observe(this) { mode ->
// Listen for refresh rate changes
val attrs = window.attributes
if (attrs.preferredDisplayModeId != mode.modeId) {
Timber.d("Switch preferredRefreshRate to %s", mode.refreshRate)
window.attributes = attrs.apply { preferredRefreshRate = mode.refreshRate }
}
}
setContent {
val appPreferences by userPreferencesDataStore.data.collectAsState(null)
appPreferences?.let { appPreferences ->