Expanded Player fix
This commit is contained in:
1 parent
84af1ab3bc
commit
d2db8883ab
2 files changed
+58
-25
No files matched your search
@@ -244,6 +244,27 @@ class EmbeddedExpandedPlayer(Box):
|
|||||||
finally:
|
finally:
|
||||||
super().destroy()
|
super().destroy()
|
||||||
|
|
||||||
|
def _periodic_cleanup(self):
|
||||||
|
"""Light cleanup for EmbeddedExpandedPlayer reuse"""
|
||||||
|
try:
|
||||||
|
logger.debug("🧹 EmbeddedExpandedPlayer light cleanup starting")
|
||||||
|
|
||||||
|
# Only clean up the player content lightly
|
||||||
|
if hasattr(self, 'player_content') and hasattr(self.player_content, '_periodic_cleanup'):
|
||||||
|
self.player_content._periodic_cleanup()
|
||||||
|
|
||||||
|
# Clean global caches but don't destroy core functionality
|
||||||
|
global _artwork_cache
|
||||||
|
_artwork_cache.clear()
|
||||||
|
|
||||||
|
# Light garbage collection
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
logger.debug("🧹 EmbeddedExpandedPlayer light cleanup completed")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Error during EmbeddedExpandedPlayer light cleanup: {e}")
|
||||||
|
|
||||||
|
|
||||||
class PlayerBoxStack(Box):
|
class PlayerBoxStack(Box):
|
||||||
"""Memory-optimized widget that displays current player information."""
|
"""Memory-optimized widget that displays current player information."""
|
||||||
@@ -298,26 +319,39 @@ class PlayerBoxStack(Box):
|
|||||||
self._cleanup_source_id = GLib.timeout_add_seconds(300, self._periodic_cleanup) # Every 5 minutes
|
self._cleanup_source_id = GLib.timeout_add_seconds(300, self._periodic_cleanup) # Every 5 minutes
|
||||||
|
|
||||||
def _periodic_cleanup(self):
|
def _periodic_cleanup(self):
|
||||||
"""Periodic cleanup to prevent memory leaks."""
|
"""Light cleanup for widget reuse - preserve functionality."""
|
||||||
try:
|
try:
|
||||||
# Clean artwork cache
|
logger.debug("Starting light expanded player cleanup for reuse")
|
||||||
|
|
||||||
|
# Clean artwork cache to reduce memory
|
||||||
cleanup_artwork_cache()
|
cleanup_artwork_cache()
|
||||||
|
|
||||||
# Remove destroyed widgets from tracking
|
# Reset visual state but preserve connections and core functionality
|
||||||
destroyed_keys = []
|
# Only clear the player widgets that can be recreated
|
||||||
for key, widget in self._player_widgets.items():
|
for widget in list(self._player_widgets.values()):
|
||||||
if not widget or not widget.get_parent():
|
try:
|
||||||
destroyed_keys.append(key)
|
if widget and hasattr(widget, "get_parent") and widget.get_parent():
|
||||||
|
# Only remove from parent, don't destroy (let GTK handle it)
|
||||||
|
widget.get_parent().remove(widget)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
# Don't clear the _player_widgets dict - just let them be recreated
|
||||||
|
|
||||||
for key in destroyed_keys:
|
# Reset stack to show no_media_box without destroying children
|
||||||
if key in self._player_widgets:
|
try:
|
||||||
del self._player_widgets[key]
|
if hasattr(self, 'player_stack') and hasattr(self, 'no_media_box'):
|
||||||
|
self.player_stack.set_visible_child(self.no_media_box)
|
||||||
|
self.current_stack_pos = 0
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# Force garbage collection
|
# Light garbage collection
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
logger.debug("Light expanded player cleanup completed")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Error during periodic cleanup: {e}")
|
logger.warning(f"Error during light cleanup: {e}")
|
||||||
|
|
||||||
return True # Continue timer
|
return True # Continue timer
|
||||||
|
|
||||||
|
|||||||
@@ -425,21 +425,20 @@ class ModusControlCenter(Window):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Clean up expanded player widget - BUT preserve for reuse
|
# Clean up expanded player widget - aggressive cleanup for reuse
|
||||||
if self._expanded_player_widget and hasattr(
|
if self._expanded_player_widget:
|
||||||
self._expanded_player_widget, "destroy"
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
# DON'T destroy the widget, just clean its internal state
|
# Call cleanup directly on the player content (PlayerBoxStack)
|
||||||
if hasattr(self._expanded_player_widget, 'player_content'):
|
if hasattr(self._expanded_player_widget, 'player_content') and \
|
||||||
# Clean up only the player content, keep the widget shell
|
hasattr(self._expanded_player_widget.player_content, '_periodic_cleanup'):
|
||||||
if hasattr(self._expanded_player_widget.player_content, '_periodic_cleanup'):
|
self._expanded_player_widget.player_content._periodic_cleanup()
|
||||||
self._expanded_player_widget.player_content._periodic_cleanup()
|
|
||||||
|
# Also clean any EmbeddedExpandedPlayer specific state
|
||||||
|
if hasattr(self._expanded_player_widget, '_periodic_cleanup'):
|
||||||
|
self._expanded_player_widget._periodic_cleanup()
|
||||||
|
|
||||||
logger.debug("Cleaned expanded player internal state (preserved for reuse)")
|
logger.debug("Cleaned expanded player internal state (preserved for reuse)")
|
||||||
# DON'T set to None - keep for reuse!
|
# DON'T destroy or set to None - keep for reuse!
|
||||||
# self._expanded_player_widget = None
|
|
||||||
# self.expanded_player_widgets = None
|
|
||||||
# self.expanded_player_center_box = None
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to clean expanded player state: {e}")
|
logger.warning(f"Failed to clean expanded player state: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user