Skip to content

Commit 5bacf62

Browse files
committed
fix(tray): handle null values for app system and clean up menu references on destroy
1 parent c658d8b commit 5bacf62

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/modules/trayIcons/backgroundAppsSource.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class BackgroundAppsSource {
3737
private _knownIds = new Map<string, TrayItem>();
3838
private _proxyChangedId = 0;
3939
private _callbacks: Callbacks;
40-
private _appSystem: Shell.AppSystem;
40+
private _appSystem: Shell.AppSystem | null;
4141
constructor(callbacks: Callbacks) {
4242
this._callbacks = callbacks;
4343
this._appSystem = Shell.AppSystem.get_default();
@@ -64,7 +64,7 @@ export class BackgroundAppsSource {
6464
}
6565

6666
private _sync(): void {
67-
if (!this._proxy) return;
67+
if (!this._proxy || !this._appSystem) return;
6868

6969
const backgroundApps = (this._proxy as any).BackgroundApps;
7070
const currentApps = new Map<string, { app: Shell.App; message: string | null }>();
@@ -153,6 +153,7 @@ export class BackgroundAppsSource {
153153
this._proxyChangedId = 0;
154154
}
155155
this._proxy = null;
156+
this._appSystem = null;
156157
this._knownIds.clear();
157158
}
158159
}

src/modules/trayIcons/trayContainer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class TrayContainer extends PanelMenu.Button {
163163
declare private _userInteracted: boolean;
164164
declare private _attentionTimeoutSeconds: number;
165165
declare private _autoCollapseTimeoutId: number;
166+
declare private _debugPostAllocateId: number;
166167
declare private _opacityTargets: WeakMap<TrayIconItem, number>;
167168
declare private _scrollTarget: number;
168169
declare private _smoothScrollAccumulator: number;
@@ -206,6 +207,7 @@ export class TrayContainer extends PanelMenu.Button {
206207
this._opacityTargets = new WeakMap();
207208
this._scrollTarget = 0;
208209
this._smoothScrollAccumulator = 0;
210+
this._debugPostAllocateId = 0;
209211

210212
// Chevron button (collapse/expand toggle)
211213
this._chevronIcon = new St.Icon({
@@ -569,7 +571,9 @@ export class TrayContainer extends PanelMenu.Button {
569571
);
570572
},
571573
);
572-
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
574+
if (this._debugPostAllocateId > 0) GLib.Source.remove(this._debugPostAllocateId);
575+
this._debugPostAllocateId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
576+
this._debugPostAllocateId = 0;
573577
logger.log(
574578
`Viewport post-allocate chevronX=${Math.round(this._chevron.translationX)} ${this._clipArea.layoutSnapshot()}`,
575579
{ prefix: LOG_PREFIX },
@@ -638,6 +642,10 @@ export class TrayContainer extends PanelMenu.Button {
638642
GLib.Source.remove(this._autoCollapseTimeoutId);
639643
this._autoCollapseTimeoutId = 0;
640644
}
645+
if (this._debugPostAllocateId > 0) {
646+
GLib.Source.remove(this._debugPostAllocateId);
647+
this._debugPostAllocateId = 0;
648+
}
641649
destroyTooltip();
642650
for (const widget of this._items.values()) widget.destroy();
643651
this._items.clear();

src/modules/trayIcons/trayIconItem.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ export class TrayIconItem extends St.Button {
266266
_hideTooltip();
267267
this._dbusMenuClient?.destroy();
268268
this._menu?.destroy();
269+
this._menu = null;
270+
this._menuManager = null;
269271
this._localMenu?.destroy();
272+
this._localMenu = null;
273+
this._localMenuManager = null;
270274
this._trayItem.destroy();
271275
super.destroy();
272276
}

0 commit comments

Comments
 (0)