Repository: lutris/lutris

Issue:
"Running" tab is not refreshed when a game stops/starts
If you stop a game that is listed in the running tab, it will not disappear from it, this will only happen if you switch to a different one and back.
Similar thing happens when a game starts through an application/desktop shortcut, the game is running but it's not listed because the view is not refreshed.
![Peek 2021-11-28 22-15](https://user-images.githubusercontent.com/10602045/143782556-aed44254-86de-4978-8227-41bacc8ff02c.gif)
![Screenshot from 2021-11-28 22-12-54](https://user-images.githubusercontent.com/10602045/143782562-4dece53f-284c-473f-ba36-a493138dc237.png)


Discussion:

Resolving patch:
diff --git a/lutris/gui/lutriswindow.py b/lutris/gui/lutriswindow.py
--- a/lutris/gui/lutriswindow.py
+++ b/lutris/gui/lutriswindow.py
@@ -123,6 +123,7 @@ def __init__(self, application, **kwargs):
         GObject.add_emission_hook(BaseService, "service-logout", self.on_service_logout)
         GObject.add_emission_hook(BaseService, "service-games-loaded", self.on_service_games_updated)
         GObject.add_emission_hook(Game, "game-updated", self.on_game_updated)
+        GObject.add_emission_hook(Game, "game-stopped", self.on_game_stopped)
         GObject.add_emission_hook(Game, "game-removed", self.on_game_collection_changed)
 
     def _init_actions(self):
@@ -785,6 +786,13 @@ def is_game_displayed(self, game):
         """Return whether a game should be displayed on the view"""
         if game.is_hidden and not self.show_hidden_games:
             return False
+
+        # Stopped games do not get displayed on the running page
+        if game.state == game.STATE_STOPPED:
+            selected_row = self.sidebar.get_selected_row()
+            if selected_row is not None and selected_row.id == "running":
+                return False
+
         return True
 
     def on_game_updated(self, game):
@@ -801,6 +809,15 @@ def on_game_updated(self, game):
             self.game_store.add_game(db_game)
         return True
 
+    def on_game_stopped(self, game):
+        """Updates the game list when a game stops; this keeps the 'running' page updated."""
+        selected_row = self.sidebar.get_selected_row()
+        # Only update the running page- we lose the selected when we do this,
+        # but on the running page this is okay.
+        if selected_row is not None and selected_row.id == "running":
+            self.game_store.remove_game(game.id)
+        return True
+
     def on_game_collection_changed(self, _sender):
         """Simple method used to refresh the view"""
         self.emit("view-updated")
diff --git a/lutris/gui/widgets/sidebar.py b/lutris/gui/widgets/sidebar.py
--- a/lutris/gui/widgets/sidebar.py
+++ b/lutris/gui/widgets/sidebar.py
@@ -388,6 +388,10 @@ def on_game_stop(self, _game):
         """Hide the "running" section when no games are running"""
         if not self.application.running_games.get_n_items():
             self.running_row.hide()
+
+            if self.get_selected_row() == self.running_row:
+                self.select_row(self.get_children()[0])
+
         return True
 
     def on_service_auth_changed(self, service):


Test patch: