♻️ refactor(dock/components): delay visibility checks and initialization in dock components to prevent showing during startup

This commit is contained in:
sankalp committed 2025-07-04 12:13:13 +05:45
1 parent 1e755e60dc
commit bc11606e11
3 files changed
+36 -12

No files matched your search

+5
View File
@@ -183,6 +183,11 @@ class DockComponents(Box):
# Battery component manages its own visibility based on config and battery presence # Battery component manages its own visibility based on config and battery presence
# Don't override its visibility here, let it handle it internally # Don't override its visibility here, let it handle it internally
pass pass
# Special handling for music player - let it manage its own visibility based on media content
elif component_name == "music_player":
# Music player component manages its own visibility based on config and media presence
# Don't override its visibility here, let it handle it internally
pass
else: else:
widget.set_visible(visibility) widget.set_visible(visibility)
+11 -2
View File
@@ -195,8 +195,8 @@ class RecordingIndicator(Button):
self.hide() self.hide()
self.check_recording_status() # Delay initial check to prevent showing during dock initialization
self.timeout_id = GLib.timeout_add(1000, self.check_recording_status) GLib.timeout_add(1000, self._delayed_init)
def check_recording_status(self): def check_recording_status(self):
try: try:
@@ -250,6 +250,15 @@ class RecordingIndicator(Button):
except Exception as e: except Exception as e:
print(f"Error stopping recording: {e}") print(f"Error stopping recording: {e}")
def _delayed_init(self):
"""Initialize recording status check after a delay to prevent showing during dock startup"""
try:
self.check_recording_status()
self.timeout_id = GLib.timeout_add(1000, self.check_recording_status)
except Exception as e:
print(f"[DEBUG] Error in delayed recording indicator init: {e}")
return False # Don't repeat this timeout
def cleanup(self): def cleanup(self):
if hasattr(self, "timeout_id"): if hasattr(self, "timeout_id"):
GLib.source_remove(self.timeout_id) GLib.source_remove(self.timeout_id)
+20 -10
View File
@@ -152,11 +152,11 @@ class MusicPlayer(Box):
# Popup window will be created on-demand # Popup window will be created on-demand
self.popup = None self.popup = None
# Initialize players # Initialize players with delayed visibility check
self.manager.init_all_players() GLib.timeout_add(500, self._delayed_init)
# Set initial visibility # Hide initially - will show only when media players are detected
self.update_visibility() self.hide()
# Set up periodic check for active player # Set up periodic check for active player
self.active_player_check_timeout = GLib.timeout_add_seconds( self.active_player_check_timeout = GLib.timeout_add_seconds(
@@ -378,6 +378,15 @@ class MusicPlayer(Box):
# Return True to continue the timeout # Return True to continue the timeout
return True return True
def _delayed_init(self):
"""Initialize players after a delay to prevent showing during dock startup"""
try:
self.manager.init_all_players()
self.update_visibility()
except Exception as e:
print(f"[DEBUG] Error in delayed music player init: {e}")
return False # Don't repeat this timeout
def _try_switch_to_alternative_player(self, current_time): def _try_switch_to_alternative_player(self, current_time):
"""Try to switch to an alternative player when current is paused/invalid""" """Try to switch to an alternative player when current is paused/invalid"""
try: try:
@@ -727,12 +736,13 @@ class MusicPlayer(Box):
def update_visibility(self): def update_visibility(self):
"""Update component visibility based on players with actual media content""" """Update component visibility based on players with actual media content"""
# Show component only if there are players with actual media content # Check if music player is enabled in configuration
has_media_players = self.has_running_players() if hasattr(data, "DOCK_COMPONENTS_VISIBILITY"):
self.set_visible(has_media_players)
# Hide in vertical mode if user preference is set
if data.VERTICAL and hasattr(data, "DOCK_COMPONENTS_VISIBILITY"):
music_visible = data.DOCK_COMPONENTS_VISIBILITY.get("music_player", True) music_visible = data.DOCK_COMPONENTS_VISIBILITY.get("music_player", True)
if not music_visible: if not music_visible:
self.set_visible(False) self.set_visible(False)
return
# Show component only if there are players with actual media content
has_media_players = self.has_running_players()
self.set_visible(has_media_players)