Skip to content

Commit 70746cf

Browse files
committed
Fix: Use connectObject and disconnectObject for clipboard tab signals.
1 parent 5e93973 commit 70746cf

1 file changed

Lines changed: 52 additions & 30 deletions

File tree

gnome-extensions/extension/features/Clipboard/tabClipboard.js

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export const ClipboardTabContent = GObject.registerClass(
5656
this._redrawIdleId = 0;
5757
this._redrawScheduled = false;
5858
this._retryId = 0;
59-
this._settingSignalIds = [];
60-
this._managerSignalIds = [];
6159

6260
this._copyService = new ClipboardCopyService();
6361
this._selectionService = new ClipboardSelectionService();
@@ -98,21 +96,26 @@ export const ClipboardTabContent = GObject.registerClass(
9896
* @private
9997
*/
10098
_setupSettingsSignals() {
101-
this._settingSignalIds = [
102-
this._settings.connect('changed::clipboard-image-preview-size', () => {
99+
this._settings.connectObject(
100+
'changed::clipboard-image-preview-size',
101+
() => {
103102
this._imagePreviewSize = this._settings.get_int('clipboard-image-preview-size');
104103
this._currentView?.setImagePreviewSize(this._imagePreviewSize);
105104
this._scheduleRedraw();
106-
}),
107-
this._settings.connect('changed::clipboard-layout-mode', () => {
105+
},
106+
'changed::clipboard-layout-mode',
107+
() => {
108108
this._applyLayoutMode(this._settings.get_string('clipboard-layout-mode') || 'list');
109-
}),
110-
this._settings.connect('changed::extension-width', () => {
109+
},
110+
'changed::extension-width',
111+
() => {
111112
this._currentView?.resetScrollAndPagination?.();
112113
this._scheduleRedraw();
113-
}),
114-
this._settings.connect('changed::extension-height', () => this._scheduleRedraw()),
115-
];
114+
},
115+
'changed::extension-height',
116+
() => this._scheduleRedraw(),
117+
this,
118+
);
116119
}
117120

118121
/**
@@ -142,16 +145,24 @@ export const ClipboardTabContent = GObject.registerClass(
142145
_buildActionBar() {
143146
this._actionBar = new ClipboardActionBar(this._settings, this._manager, this._selectionService.selectedIds);
144147

145-
this._actionBar.connect('layout-toggled', () => {
146-
const next = this._layoutMode === 'list' ? 'grid' : 'list';
147-
this._settings.set_string('clipboard-layout-mode', next);
148-
});
149-
150-
this._actionBar.connect('selection-cleared', () => this._scheduleRedraw());
151-
this._actionBar.connect('select-all-requested', () => this._onSelectAllClicked());
152-
this._actionBar.connect('merge-selected-requested', () => this._onMergeSelectedRequested());
153-
this._actionBar.connect('navigate-up', () => this._searchComponent?.grabFocus());
154-
this._actionBar.connect('navigate-down', () => this._focusFirstContentItem());
148+
this._actionBar.connectObject(
149+
'layout-toggled',
150+
() => {
151+
const next = this._layoutMode === 'list' ? 'grid' : 'list';
152+
this._settings.set_string('clipboard-layout-mode', next);
153+
},
154+
'selection-cleared',
155+
() => this._scheduleRedraw(),
156+
'select-all-requested',
157+
() => this._onSelectAllClicked(),
158+
'merge-selected-requested',
159+
() => this._onMergeSelectedRequested(),
160+
'navigate-up',
161+
() => this._searchComponent?.grabFocus(),
162+
'navigate-down',
163+
() => this._focusFirstContentItem(),
164+
this,
165+
);
155166

156167
this._mainBox.add_child(this._actionBar);
157168
}
@@ -181,6 +192,7 @@ export const ClipboardTabContent = GObject.registerClass(
181192
*/
182193
_createView(mode) {
183194
if (this._currentView) {
195+
this._currentView.disconnectObject(this);
184196
this._scrollView.set_child(null);
185197
this._currentView.destroy();
186198
}
@@ -197,10 +209,14 @@ export const ClipboardTabContent = GObject.registerClass(
197209

198210
this._currentView = mode === 'grid' ? new ClipboardGridView(options) : new ClipboardListView(options);
199211

200-
this._currentView.connect('navigate-up', () => {
201-
if (this._actionBar?.visible) this._actionBar.grabFocus();
202-
else this._searchComponent?.grabFocus();
203-
});
212+
this._currentView.connectObject(
213+
'navigate-up',
214+
() => {
215+
if (this._actionBar?.visible) this._actionBar.grabFocus();
216+
else this._searchComponent?.grabFocus();
217+
},
218+
this,
219+
);
204220

205221
this._scrollView.set_child(this._currentView);
206222
}
@@ -292,7 +308,13 @@ export const ClipboardTabContent = GObject.registerClass(
292308
* @private
293309
*/
294310
_connectManagerSignals() {
295-
this._managerSignalIds = [this._manager.connect('history-changed', () => this._scheduleRedraw()), this._manager.connect('pinned-list-changed', () => this._scheduleRedraw())];
311+
this._manager.connectObject(
312+
'history-changed',
313+
() => this._scheduleRedraw(),
314+
'pinned-list-changed',
315+
() => this._scheduleRedraw(),
316+
this,
317+
);
296318
}
297319

298320
// ========================================================================
@@ -514,11 +536,11 @@ export const ClipboardTabContent = GObject.registerClass(
514536
destroy() {
515537
this._clearRedrawSources();
516538

517-
this._settingSignalIds.forEach((id) => this._settings?.disconnect(id));
518-
this._managerSignalIds?.forEach((id) => this._manager?.disconnect(id));
539+
this._settings?.disconnectObject(this);
540+
this._manager?.disconnectObject(this);
541+
this._actionBar?.disconnectObject(this);
542+
this._currentView?.disconnectObject(this);
519543
this.disconnectObject(this);
520-
this._settingSignalIds = [];
521-
this._managerSignalIds = [];
522544

523545
this._searchComponent?.destroy();
524546
this._actionBar?.destroy();

0 commit comments

Comments
 (0)