Improved Focus handling on seeks#2341
Conversation
|
Thanks for this. But I don't think we should do that. When the app goes into background the socket connection remains active for 5 minutes, which means in theory the user is seeking a game for that long. Canceling the seek is certainly better than having aborted games, but it is counterintuitive as how an app should work. |
I am not sure at all that this is the case. I think both OS pause background processes really quickly. For example: https://developer.apple.com/forums/thread/685525/ . So I dont think we can assume the user continues listening to the websocket once the app is backgrounded. I think a solution would be to get a push notification from lila when a game starts, which we will then only display if the user is currently not in the app, but I guess serverside changes would be needed too for this. Or we could restart the seek automatically when the user returns the app to the foreground. |
|
Maintaining the websocket connection is not the same as executing code in background. It is true that platforms are somewhat conservative in allowing that. Especially on iOS. It was important to allow the connection to remain active for playing games, otherwise lichess thinks you are disconnected and you may lose games quickly (for longer time controls it is useful). It is not because the connection is maintained that you can do what you want while challenging real time or seeking a game. The game was never designed to allow this, so this is why you just can't do it. It is not a bug, that is just never been possible. Now, ideally I think we should allow users to go in the background while searching for a game, as I said above. And if we want to do that, we'll probably have issues with the background execution restrictions, so it is not that simple. This plugin is probably what we want: https://pub.dev/packages/workmanager |
I don't think push notifications are the good choice for that. Not reliable enough. Also Thibault probably don't want to do that change server side. |
We can't do that as people will think the app is looking for a game while in background where actually it is not the case. Very confusing. |
I can not replicate. If I watch lichess tv on my Android 15 Phone and check with a browser on my laptop if I am online or not, it switches to offline within 20s of the app being backgrounded. Same for my iPad, there it is even within a few seconds. |
that is not the way to do it; try with friends as I suggested. TV socket is closed automatically when the app is backgrounded. |
|
Veloce I had two related tickets with repro videos on these comments Should friend status be preserved for several minutes if they’re not in active game? should realtime challenge connection be sent if one has been in the app in past few minutes? not sure if I’m misunderstanding how you are saying the websocket connection should work |
I still can not replicate, see the attached video: Socket_closing.mp4Where the white account was me playing on my phone account and immediately after playing Qxf1 I switched to another app. |
|
Ok, that is interesting. Possibly a regression, thanks for reporting. That thing is tested at the socket level but it definitely should be tested at the game level. Note that I have tested it with the friend online status and it works (on iOS). |
Is there any version you want me to test? I tried with my iPad too and while I do not replicate the socket staying alive for 5min it is significantly longer(more than 1 min normally) than on my Android device. |
|
I have no clue about a version sorry. I'm also surprised that there is a difference between android and iOS here, especially since it stays longer on iOS as I would expect the opposite. |
|
@HaonRekcef I confirm as well that on android the websocket shuts down only after a few seconds when the app is put into background. I have no idea why tbh; I am pretty sure that at the time when I first implemented this I had tested that and it was working on android, unless I overlooked android... To investigate... I don't know what is shutting the connection. I doubt that is at the OS level, because in the previous lichess app socket was definitely staying alive in background on android. |
Veloce, are you sure it's not an issue on iOS as well I had created 2 separate issue tickets with videos for each scenario Would you have expected web socket to apply for either of these where connection was lost in one minute or less |
ed04dac to
8199cc2
Compare
|
Updated the PR, needs a thorough review as it is quite critical
|
| switch (widget.source) { | ||
| case LobbySource(): | ||
| ref.read(gameScreenLoaderProvider(widget.source).notifier).cancelSeek(); | ||
| await ref.read(createGameServiceProvider).cancelSeek(); |
There was a problem hiding this comment.
Better to call the service from the GameScreenLoader.cancelSeek.
| BottomBarButton( | ||
| onTap: () => Navigator.of(context).pop(), | ||
| label: context.l10n.cancel, | ||
| label: showBackButton ? 'Back' : context.l10n.cancel, |
There was a problem hiding this comment.
The label shows Back but the icon is still a cross, this is confusing. Better remove this change and see the other comment.
lib/src/view/game/game_screen.dart
Outdated
| return Scaffold( | ||
| resizeToAvoidBottomInset: false, | ||
| appBar: AppBar( | ||
| leading: const SocketPingRatingIcon(), |
There was a problem hiding this comment.
Instead of showing the back button in the bottom bar, remove this widget to show it in the top bar as it should be.
lib/src/view/game/game_screen.dart
Outdated
| _ => const SizedBox.shrink(), | ||
| }, | ||
| ), | ||
| body: const LoadGameError('The game search was cancelled.', showBackButton: true), |
There was a problem hiding this comment.
Remove the showBackButton parameter.
|
Addressed the review comments. |

Fixes issue reported on lichess: https://lichess.org/forum/team-lichess-beta-testers/mobile-app-alpha?page=16#156
The issue was that while seeking a game the screen could lock or the user could switch to another app without cancelling the seek, which led to game aborts.
Implemented fix: