diff --git a/system/ui/mici_setup.py b/system/ui/mici_setup.py index 186f8e58e..c2034ffda 100755 --- a/system/ui/mici_setup.py +++ b/system/ui/mici_setup.py @@ -355,7 +355,6 @@ class NetworkSetupPageBase(Scroller): self._wifi_manager.set_active(True) self._network_monitor = network_monitor self._custom_software = False - self._prev_has_internet = False self._wifi_ui = WifiUIMici(self._wifi_manager) self._connect_button = GreyBigButton("connect to\ninternet", "swipe down to go back", @@ -365,8 +364,9 @@ class NetworkSetupPageBase(Scroller): self._wifi_button = WifiNetworkButton(self._wifi_manager) self._wifi_button.set_click_callback(lambda: gui_app.push_widget(self._wifi_ui)) - self._show_time = 0.0 - self._pending_has_internet_scroll = False + self._prev_has_internet = False + self._prev_wifi_connected = False + self._pending_has_internet_scroll: float | None = None # stores time to use as delay self._pending_continue_grow_animation = False self._pending_wifi_grow_animation = False @@ -394,12 +394,26 @@ class NetworkSetupPageBase(Scroller): super().show_event() # make sure we populate strength and ip immediately if already have wifi self._wifi_manager.set_active(True) - self._show_time = rl.get_time() - self._prev_has_internet = False - self._pending_has_internet_scroll = False + self._prev_has_internet = self._has_internet + self._prev_wifi_connected = self._wifi_manager.wifi_state.status == ConnectStatus.CONNECTED + self._pending_has_internet_scroll = None self._pending_continue_grow_animation = False self._pending_wifi_grow_animation = False + if self._prev_has_internet or self._prev_wifi_connected: + self.set_shown_callback(lambda: self._scroll_to_end_and_grow()) + + @property + def _has_internet(self) -> bool: + network_changing = self._wifi_ui.any_network_forgetting or self._wifi_manager.wifi_state.status == ConnectStatus.CONNECTING + if network_changing: + self._network_monitor.invalidate() + + has_internet = (self._network_monitor.network_connected.is_set() and + not network_changing and + not self._network_monitor.recheck_event.is_set()) + return has_internet + def _nav_stack_tick(self): # Only run tick when this page or its WiFi UI is on the stack if gui_app.get_active_widget() is not self and not gui_app.widget_in_stack(self._wifi_ui): @@ -408,37 +422,39 @@ class NetworkSetupPageBase(Scroller): # Check network state before processing callbacks so forgetting flag # is still set on the frame the forgotten callback fires - network_changing = self._wifi_ui.any_network_forgetting or self._wifi_manager.wifi_state.status == ConnectStatus.CONNECTING - if network_changing: - self._network_monitor.invalidate() - - has_internet = (self._network_monitor.network_connected.is_set() and - not network_changing and - not self._network_monitor.recheck_event.is_set()) + has_internet = self._has_internet self._continue_button.set_visible(has_internet) self._waiting_button.set_visible(not has_internet) + # TODO: fire show/hide events on visibility changes + if not has_internet: + self._pending_continue_grow_animation = False + self._wifi_manager.process_callbacks() - if has_internet and not self._prev_has_internet: - self._pending_has_internet_scroll = True + # Dismiss WiFi UI and scroll on WiFi connect or internet gain + wifi_connected = self._wifi_manager.wifi_state.status == ConnectStatus.CONNECTED + if (has_internet and not self._prev_has_internet) or (wifi_connected and not self._prev_wifi_connected): + # TODO: cancel if connect is transient + self._pending_has_internet_scroll = rl.get_time() + self._prev_has_internet = has_internet + self._prev_wifi_connected = wifi_connected - if self._pending_has_internet_scroll: + if self._pending_has_internet_scroll is not None: # Scrolls over to continue button, then grows once in view - elapsed = rl.get_time() - self._show_time - if elapsed > 0.5: - self._pending_has_internet_scroll = False - - def scroll_to_end(): - self._scroller._layout() - end_offset = -(self._scroller.content_size - self._rect.width) - remaining = self._scroller.scroll_panel.get_offset() - end_offset - self._scroller.scroll_to(remaining, smooth=True, block_interaction=True) - self._pending_continue_grow_animation = True - + elapsed = rl.get_time() - self._pending_has_internet_scroll + if elapsed > 0.7 or gui_app.get_active_widget() is self: # instant scroll + grow if not popping # Animate WifiUi down first before scroll - gui_app.pop_widgets_to(self, scroll_to_end) + self._pending_has_internet_scroll = None + gui_app.pop_widgets_to(self, self._scroll_to_end_and_grow) + + def _scroll_to_end_and_grow(self): + self._scroller._layout() + end_offset = -(self._scroller.content_size - self._rect.width) + remaining = self._scroller.scroll_panel.get_offset() - end_offset + self._scroller.scroll_to(remaining, smooth=True, block_interaction=True) + self._pending_continue_grow_animation = True def set_custom_software(self, custom_software: bool): self._custom_software = custom_software