Skip to content

Commit

Permalink
Fix signals not being disconnected when destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
fflewddur committed Dec 5, 2024
1 parent 32389f2 commit 6659b1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/mem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,33 @@ export const MemMonitor = GObject.registerClass(
this.menuMemSize.text = _(`${free} available of ${total}`);
});
this.vitalsSignals.push(id);
vitals.connect('notify::swap-size-free', () => {

id = vitals.connect('notify::swap-size-free', () => {
const total = bytesToHumanString(vitals.swap_size);
const free = bytesToHumanString(vitals.swap_size_free);
this.menuSwapSize.text = _(`${free} available of ${total}`);
});
vitals.connect('notify::swap-usage', () => {
this.vitalsSignals.push(id);

id = vitals.connect('notify::swap-usage', () => {
const s = (vitals.swap_usage * 100).toFixed(0) + '%';
this.menuSwapUsage.text = s;
});
vitals.connect('notify::mem-history', () => {
this.vitalsSignals.push(id);

id = vitals.connect('notify::mem-history', () => {
this.historyChart?.update(vitals.ram_usage);
});
vitals.connect('notify::mem-top-procs', () => {
this.vitalsSignals.push(id);

id = vitals.connect('notify::mem-top-procs', () => {
const procs = vitals.getTopMemProcs(NumTopProcs);
for (let i = 0; i < NumTopProcs; i++) {
this.topProcs[i].cmd.text = procs[i].cmd;
this.topProcs[i].usage.text = bytesToHumanString(procs[i].memUsage());
}
});
this.vitalsSignals.push(id);
}
}
);
Expand Down
4 changes: 4 additions & 0 deletions src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ export const TopHatMonitor = GObject.registerClass(
return [fgColor, useAccentColor];
}

public getMonitorName() {
return this.monitorName;
}

public override destroy() {
for (const id of this.vitalsSignals) {
this.vitals?.disconnect(id);
Expand Down

0 comments on commit 6659b1e

Please sign in to comment.