Repository navigation
fix(settings): flush settings before a phone profile switch and match the server's limits #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Quick104
merged 5 commits into
Silo-Server:main
from
Rhainland:fix/1219-settings-contract
Oct 7, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d57d8c
fix(settings): flush settings before a phone profile switch and match…
Rhainland 5830031
fix(settings): guard the phone profile switch while settings are pushed
Rhainland 2c86823
fix(settings): block system Back while a profile switch pushes settings
Rhainland a8e0d49
Merge remote-tracking branch 'origin/main' into pr-501
Quick104 00a119a
fix(settings): normalize a stored playback speed on read
Quick104 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/auth/ProfileSwitchTeardown.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package org.siloserver.silo.android.auth | ||
|
|
||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.withTimeoutOrNull | ||
| import org.siloserver.silo.common.settings.CardPresentationStore | ||
| import org.siloserver.silo.common.settings.OverlayPrefsStore | ||
| import org.siloserver.silo.common.settings.PlayerSettingsStore | ||
| import org.siloserver.silo.common.settings.SeekIntervalStore | ||
| import org.siloserver.silo.common.settings.TitleArtStore | ||
| import org.siloserver.silo.model.profile.ActiveProfileStore | ||
|
|
||
| /** | ||
| * The phone's "Switch Profile", shared by the profile menu and Settings. | ||
| * | ||
| * Settings writes wait in the flusher's debounce for a moment, and the flusher | ||
| * drops a write once its profile is no longer active. So the pending writes are | ||
| * pushed first, while the profile they were made on is still the active one | ||
| * (the TV switch does the same). Then the shell is left and the per-profile | ||
| * caches are dropped, or the next profile keeps rendering, and writing back, | ||
| * the previous one's values. | ||
| */ | ||
| class ProfileSwitchTeardown( | ||
| private val playerSettingsStore: PlayerSettingsStore, | ||
| private val overlayPrefsStore: OverlayPrefsStore, | ||
| private val activeProfileStore: ActiveProfileStore, | ||
| private val cardPresentationStore: CardPresentationStore, | ||
| private val seekIntervalStore: SeekIntervalStore, | ||
| private val titleArtStore: TitleArtStore, | ||
| private val flushTimeoutMs: Long = FLUSH_TIMEOUT_MS, | ||
| ) { | ||
| private val _switching = MutableStateFlow(false) | ||
|
|
||
| /** True while a switch is pushing settings; the shell shows progress and blocks input. */ | ||
| val switching: StateFlow<Boolean> = _switching.asStateFlow() | ||
|
|
||
| /** | ||
| * Push pending settings, then call [leaveShell] and drop per-profile state. | ||
| * | ||
| * The push is bounded: against an unreachable server each write can wait | ||
| * out a connect timeout, and the switch must not hang on that. A write | ||
| * still unsent when the bound passes stays queued under the old profile, | ||
| * as it would have without this flush. | ||
| * | ||
| * A request made while a switch is already running is ignored, so a | ||
| * second tap during the push cannot open a second profile picker. | ||
| * Returns whether this call performed the switch. | ||
| */ | ||
| suspend fun switchProfile(leaveShell: () -> Unit): Boolean { | ||
| if (!_switching.compareAndSet(expect = false, update = true)) return false | ||
| try { | ||
| withTimeoutOrNull(flushTimeoutMs) { playerSettingsStore.flushPendingDeviceSettings() } | ||
| // Navigate before clearing: clearing while the shell is still composed | ||
| // repaints it with default cards behind the picker. | ||
| leaveShell() | ||
| overlayPrefsStore.clear() | ||
| activeProfileStore.reset() | ||
| cardPresentationStore.clear() | ||
| seekIntervalStore.clear() | ||
| titleArtStore.clear() | ||
| } finally { | ||
| _switching.value = false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| private companion object { | ||
| const val FLUSH_TIMEOUT_MS = 5_000L | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...pp/src/androidMain/kotlin/org/siloserver/silo/android/ui/navigation/LocalProfileSwitch.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.siloserver.silo.android.ui.navigation | ||
|
|
||
| import androidx.compose.runtime.staticCompositionLocalOf | ||
|
|
||
| /** | ||
| * Starts "Switch Profile" in the navigation host's scope, which outlives the | ||
| * tab screen the request came from. Run from a tab's own scope, opening a | ||
| * title while settings were still being pushed cancelled the switch. | ||
| */ | ||
| val LocalProfileSwitch = staticCompositionLocalOf<() -> Unit> { {} } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.