js: Use (dis)connectObject()

Start using the new methods to simplify signal cleanup. For now,
focus on replacing existing cleanups; in most cases this means
signals connected in the constructor and disconnected on destroy,
but also other cases with a similarly defined lifetime (say: from
show to hide).

This doesn't change signal connections that only exist for a short
time (say: once), handlers that are connected on-demand (say: the
first time a particular method is called), or connections that
aren't tracked (read: disconnected) at all.

We will eventually replace the latter with connectObject() as
well - especially from actor subclasses - but the changeset is
already big enough as-is :-)

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
This commit is contained in:
Florian Müllner
2021-08-16 00:36:59 +02:00
committed by Marge Bot
parent f45ccc9143
commit 26235bbe54
54 changed files with 753 additions and 1674 deletions

View File

@ -330,15 +330,13 @@ var BaseAppView = GObject.registerClass({
// Filter the apps through the users parental controls.
this._parentalControlsManager = ParentalControlsManager.getDefault();
this._appFilterChangedId =
this._parentalControlsManager.connect('app-filter-changed', () => {
this._redisplay();
});
this._parentalControlsManager.connectObject('app-filter-changed',
() => this._redisplay(), this);
// Don't duplicate favorites
this._appFavorites = AppFavorites.getAppFavorites();
this._appFavoritesChangedId =
this._appFavorites.connect('changed', () => this._redisplay());
this._appFavorites.connectObject('changed',
() => this._redisplay(), this);
// Drag n' Drop
this._lastOvershoot = -1;
@ -355,16 +353,6 @@ var BaseAppView = GObject.registerClass({
}
_onDestroy() {
if (this._appFilterChangedId > 0) {
this._parentalControlsManager.disconnect(this._appFilterChangedId);
this._appFilterChangedId = 0;
}
if (this._appFavoritesChangedId > 0) {
this._appFavorites.disconnect(this._appFavoritesChangedId);
this._appFavoritesChangedId = 0;
}
if (this._swipeTracker) {
this._swipeTracker.destroy();
delete this._swipeTracker;
@ -1165,14 +1153,9 @@ var BaseAppView = GObject.registerClass({
return (translationX - baseOffset) * page;
}
_getPagePreviewAdjustment(page) {
const previewedPage = this._previewedPages.get(page);
return previewedPage?.adjustment;
}
_syncClip() {
const nextPageAdjustment = this._getPagePreviewAdjustment(1);
const prevPageAdjustment = this._getPagePreviewAdjustment(-1);
const nextPageAdjustment = this._previewedPages.get(1);
const prevPageAdjustment = this._previewedPages.get(-1);
this._grid.clip_to_view =
(!prevPageAdjustment || prevPageAdjustment.value === 0) &&
(!nextPageAdjustment || nextPageAdjustment.value === 0);
@ -1180,7 +1163,7 @@ var BaseAppView = GObject.registerClass({
_setupPagePreview(page, state) {
if (this._previewedPages.has(page))
return this._previewedPages.get(page).adjustment;
return this._previewedPages.get(page);
const adjustment = new St.Adjustment({
actor: this,
@ -1191,7 +1174,7 @@ var BaseAppView = GObject.registerClass({
const indicator = page > 0
? this._nextPageIndicator : this._prevPageIndicator;
const notifyId = adjustment.connect('notify::value', () => {
adjustment.connectObject('notify::value', () => {
const nextPage = this._grid.currentPage + page;
const hasFollowingPage = nextPage >= 0 &&
nextPage < this._grid.nPages;
@ -1229,23 +1212,20 @@ var BaseAppView = GObject.registerClass({
});
}
this._syncClip();
});
}, this);
this._previewedPages.set(page, {
adjustment,
notifyId,
});
this._previewedPages.set(page, adjustment);
return adjustment;
}
_teardownPagePreview(page) {
const previewedPage = this._previewedPages.get(page);
if (!previewedPage)
const adjustment = this._previewedPages.get(page);
if (!adjustment)
return;
previewedPage.adjustment.value = 1;
previewedPage.adjustment.disconnect(previewedPage.notifyId);
adjustment.value = 1;
adjustment.disconnectObject(this);
this._previewedPages.delete(page);
}
@ -1266,7 +1246,7 @@ var BaseAppView = GObject.registerClass({
this._prevPageIndicator.remove_style_class_name('dnd');
}
adjustment = this._getPagePreviewAdjustment(1);
adjustment = this._previewedPages.get(1);
if (showingNextPage) {
adjustment = this._setupPagePreview(1, state);
@ -1289,7 +1269,7 @@ var BaseAppView = GObject.registerClass({
});
}
adjustment = this._getPagePreviewAdjustment(-1);
adjustment = this._previewedPages.get(-1);
if (showingPrevPage) {
adjustment = this._setupPagePreview(-1, state);
@ -1403,7 +1383,6 @@ class AppDisplay extends BaseAppView {
this._currentDialog = null;
this._displayingDialog = false;
this._currentDialogDestroyId = 0;
this._placeholder = null;
@ -1698,19 +1677,14 @@ class AppDisplay extends BaseAppView {
addFolderDialog(dialog) {
Main.layoutManager.overviewGroup.add_child(dialog);
dialog.connect('open-state-changed', (o, isOpen) => {
if (this._currentDialog) {
this._currentDialog.disconnect(this._currentDialogDestroyId);
this._currentDialogDestroyId = 0;
}
this._currentDialog?.disconnectObject(this);
this._currentDialog = null;
if (isOpen) {
this._currentDialog = dialog;
this._currentDialogDestroyId = dialog.connect('destroy', () => {
this._currentDialog = null;
this._currentDialogDestroyId = 0;
});
this._currentDialog.connectObject('destroy',
() => (this._currentDialog = null), this);
}
this._displayingDialog = isOpen;
});
@ -2418,8 +2392,8 @@ var FolderIcon = GObject.registerClass({
this.view = new FolderView(this._folder, id, parentView);
this._folderChangedId = this._folder.connect(
'changed', this._sync.bind(this));
this._folder.connectObject(
'changed', this._sync.bind(this), this);
this._sync();
}
@ -2430,11 +2404,6 @@ var FolderIcon = GObject.registerClass({
this._dialog.destroy();
else
this.view.destroy();
if (this._folderChangedId) {
this._folder.disconnect(this._folderChangedId);
delete this._folderChangedId;
}
}
vfunc_clicked() {
@ -3110,9 +3079,8 @@ var AppIcon = GObject.registerClass({
this._menuManager = new PopupMenu.PopupMenuManager(this);
this._menuTimeoutId = 0;
this._stateChangedId = this.app.connect('notify::state', () => {
this._updateRunningStyle();
});
this.app.connectObject('notify::state',
() => this._updateRunningStyle(), this);
this._updateRunningStyle();
}
@ -3123,10 +3091,7 @@ var AppIcon = GObject.registerClass({
GLib.source_remove(this._folderPreviewId);
this._folderPreviewId = 0;
}
if (this._stateChangedId > 0)
this.app.disconnect(this._stateChangedId);
this._stateChangedId = 0;
this._removeMenuTimeout();
}
@ -3221,12 +3186,8 @@ var AppIcon = GObject.registerClass({
if (!isPoppedUp)
this._onMenuPoppedDown();
});
let id = Main.overview.connect('hiding', () => {
this._menu.close();
});
this.connect('destroy', () => {
Main.overview.disconnect(id);
});
Main.overview.connectObject('hiding',
() => this._menu.close(), this);
Main.uiGroup.add_actor(this._menu.actor);
this._menuManager.addMenu(this._menu);