refactor(MenuSlider): improve signal handling with connectObject
#258
+53
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The replacement of
connect
withconnectObject
in GNOME Shell 42 and later versions allows signal connections to be automatically tracked and cleaned up, simplifying signal management in extensions or applications.Key changes and benefits include:
connectAndTrack
,disconnectAndUntrack
, anddisconnectAllSignals
are removed.connectObject(signal, handler, owner)
, where theowner
(oftenthis
) is used to automatically track the connection.disconnectObject(this)
, which disconnects all signal handlers associated with thatowner
without manually iterating signal IDs.destroy
method is simplified to just calldisconnectObject(this)
on relevant objects rather than cleaning up each signal connection individually.onAdjustmentChanged
andonShowChanged
), callingdisconnectObject(this)
ensures no duplicate signal handlers are present.This approach can be applied not only in one place but throughout related components such as
PanelButton.js
,PlayerProxy.js
, andScrollingLabel.js
in extensions or GNOME Shell modifications.This mechanism is designed to prevent dangling signal handlers and improve code maintainability by leveraging signal handler tracking via the owner object and automatic cleanup when objects are destroyed. It requires the type to support a
destroy
signal, which is typical forGObject.Object
subclasses orClutter.Actor
-based classes in GNOME Shell extensions.