refactor(per_app_volume): remove redundant 2s polling
- stream-added/stream-removed signals already handle app list updates - Removed _auto_refresh(), _on_map/_on_unmap timer management - Removed _last_app_names tracking (unused without polling)
This commit is contained in:
1 file changed
-38
@@ -65,7 +65,6 @@ class PerAppVolumeControl(Box):
|
|||||||
self._app_widgets = {}
|
self._app_widgets = {}
|
||||||
self._signal_connections = []
|
self._signal_connections = []
|
||||||
self._destroyed = False
|
self._destroyed = False
|
||||||
self._refresh_timer = None
|
|
||||||
|
|
||||||
# Header with back button
|
# Header with back button
|
||||||
self.header = Box(
|
self.header = Box(
|
||||||
@@ -112,38 +111,9 @@ class PerAppVolumeControl(Box):
|
|||||||
audio_service.connect("stream-removed", self._on_stream_changed)
|
audio_service.connect("stream-removed", self._on_stream_changed)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Track last known app names to avoid unnecessary rebuilds
|
|
||||||
self._last_app_names = frozenset()
|
|
||||||
|
|
||||||
# Initial population
|
# Initial population
|
||||||
self._populate_apps()
|
self._populate_apps()
|
||||||
|
|
||||||
self.connect("map", self._on_map)
|
|
||||||
self.connect("unmap", self._on_unmap)
|
|
||||||
|
|
||||||
def _auto_refresh(self):
|
|
||||||
"""Auto-refresh the application list every 2 seconds"""
|
|
||||||
if self._destroyed:
|
|
||||||
self._refresh_timer = None
|
|
||||||
return False
|
|
||||||
if not audio_service:
|
|
||||||
return True
|
|
||||||
apps = audio_service.applications or []
|
|
||||||
current_names = frozenset(a.name or "" for a in apps)
|
|
||||||
if current_names != self._last_app_names:
|
|
||||||
self._last_app_names = current_names
|
|
||||||
self._populate_apps()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _on_map(self, *_):
|
|
||||||
if self._refresh_timer is None:
|
|
||||||
self._refresh_timer = GLib.timeout_add_seconds(2, self._auto_refresh)
|
|
||||||
|
|
||||||
def _on_unmap(self, *_):
|
|
||||||
if self._refresh_timer is not None:
|
|
||||||
GLib.source_remove(self._refresh_timer)
|
|
||||||
self._refresh_timer = None
|
|
||||||
|
|
||||||
def _go_back(self, *_):
|
def _go_back(self, *_):
|
||||||
"""Return to main control center view"""
|
"""Return to main control center view"""
|
||||||
self.control_center.close_per_app_volume()
|
self.control_center.close_per_app_volume()
|
||||||
@@ -354,14 +324,6 @@ class PerAppVolumeControl(Box):
|
|||||||
"""Clean up resources"""
|
"""Clean up resources"""
|
||||||
self._destroyed = True
|
self._destroyed = True
|
||||||
|
|
||||||
# Stop the auto-refresh timer
|
|
||||||
if self._refresh_timer is not None:
|
|
||||||
try:
|
|
||||||
GLib.source_remove(self._refresh_timer)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"An error occurred: {e}")
|
|
||||||
self._refresh_timer = None
|
|
||||||
|
|
||||||
# Disconnect audio service signals
|
# Disconnect audio service signals
|
||||||
if audio_service:
|
if audio_service:
|
||||||
for connection in self._signal_connections:
|
for connection in self._signal_connections:
|
||||||
|
|||||||
Reference in new issue
Block a user