diff --git a/.vscode/launch.json b/.vscode/launch.json index 4ac33b4..2ec95b5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,7 +16,7 @@ "type": "python", "request": "launch", "program": "main.py", - "args": ["--no-run-check", "--idle", "-vv"], + "args": ["--no-run-check", "-vv"], "console": "integratedTerminal", "justMyCode": false }, @@ -25,7 +25,7 @@ "type": "python", "request": "launch", "program": "main.py", - "args": ["--no-run-check", "--idle", "-vvv"], + "args": ["--no-run-check", "-vvv"], "console": "integratedTerminal", "justMyCode": false }, @@ -34,7 +34,7 @@ "type": "python", "request": "launch", "program": "main.py", - "args": ["--no-run-check", "--idle", "-vvv", "--debug-ws"], + "args": ["--no-run-check", "-vvv", "--debug-ws"], "console": "integratedTerminal", "justMyCode": false }, diff --git a/gui.py b/gui.py index aebfa74..0bfac2d 100644 --- a/gui.py +++ b/gui.py @@ -289,6 +289,7 @@ class GameSelector: def _on_select(self, event): current = self._list.curselection() + print(current) if not current: # can happen when the user clicks on an empty list new_selection = None @@ -298,18 +299,21 @@ class GameSelector: self._selection = new_selection self._manager._twitch.change_state(State.GAME_SELECT) - def get_selection(self) -> Game: + def get_selection(self) -> Optional[Game]: if self._selection is None: - if not self._games: - raise RuntimeError("No games to select from") - # select and return the first game from the list - self._list.selection_clear(0, "end") - self._list.selection_set(0) - first_game = next(iter(self._games.values())) - self._selection = str(first_game) - return first_game + return None return self._games[self._selection] + def set_first(self) -> Game: + # select and return the first game from the list + self._list.selection_clear(0, "end") + self._list.selection_set(0) + for game_name, first_game in self._games.items(): + # just one iteration to get, set and return the first game + self._selection = game_name + return first_game + raise RuntimeError("No games to select from") + class _BaseVars(TypedDict): progress: DoubleVar diff --git a/main.py b/main.py index b3788ac..b60f0f2 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,6 @@ class ParsedArgs(argparse.Namespace): _debug_ws: bool _debug_gql: bool log: bool - idle: bool tray: bool no_run_check: bool game: Optional[str] @@ -69,7 +68,6 @@ parser.add_argument("--no-run-check", dest="no_run_check", action="store_true") parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true") parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true") parser.add_argument("-g", "--game", default=None) -parser.add_argument("--idle", action="store_true") parser.add_argument("--tray", action="store_true") parser.add_argument("--log", action="store_true") options: ParsedArgs = parser.parse_args(namespace=ParsedArgs()) diff --git a/twitch.py b/twitch.py index fb9cc77..27318ab 100644 --- a/twitch.py +++ b/twitch.py @@ -179,6 +179,7 @@ class Twitch: WebsocketTopic("User", "Drops", self._user_id, self.process_drops), WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points), ]) + first_select: bool = True games: List[Game] = [] full_cleanup: bool = False channels: Final[OrderedDict[int, Channel]] = self.channels @@ -215,18 +216,24 @@ class Twitch: # only start the websocket after we confirm there are drops to mine await self.websocket.start() self.gui.games.set_games(games) - if self.options.idle: - self.options.idle = False - self.change_state(State.IDLE) - else: - self.change_state(State.GAME_SELECT) + self.change_state(State.GAME_SELECT) elif self._state is State.GAME_SELECT: self.game = self.gui.games.get_selection() - # restart the watch loop if needed - self.restart_watching() - # signal channel cleanup that we're removing everything - full_cleanup = True - self.change_state(State.CHANNELS_CLEANUP) + if self.game is None: + if first_select: + # on first select, let the user make the choice + first_select = False + else: + self.game = self.gui.games.set_first() + if self.game is not None: + # restart the watch loop if needed + self.restart_watching() + # signal channel cleanup that we're removing everything + full_cleanup = True + self.change_state(State.CHANNELS_CLEANUP) + else: + # with no game selected, we switch to IDLE + self.change_state(State.IDLE) elif self._state is State.CHANNELS_CLEANUP: if self.game is None or full_cleanup: # no game selected or we're doing full cleanup: remove everything