Skip to content

Commit 6f4c508

Browse files
library: Add Memory Monitor entry (#508)
* library: Add Memory Monitor entry * Update main.json * Update main.blp * Memory Monitor: Suggestions
1 parent 3589030 commit 6f4c508

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.StatusPage {
5+
title: _("Memory Monitor");
6+
description: _("Monitor system memory");
7+
8+
LinkButton {
9+
label: "API Reference";
10+
uri: "https://docs.gtk.org/gio/iface.MemoryMonitor.html";
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Gio from "gi://Gio";
2+
3+
const memory_monitor = Gio.MemoryMonitor.dup_default();
4+
5+
const cache = new Map();
6+
cache.set("a", 1);
7+
cache.set("b", 2);
8+
cache.set("c", 3);
9+
10+
memory_monitor.connect("low-memory-warning", (monitor, level) => {
11+
// Use inequalities for checking as new levels may be added in the future
12+
if (level >= Gio.MemoryMonitorWarningLevel.LOW) {
13+
// Processes should free up unneeded resources
14+
console.log("Warning Level: Low");
15+
drop_caches();
16+
} else if (level >= Gio.MemoryMonitorWarningLevel.MEDIUM) {
17+
// Processes should try harder to free up unneeded resources
18+
console.log("Warning Level: Medium");
19+
} else if (level >= Gio.MemoryMonitorWarningLevel.CRITICAL) {
20+
// system will start terminating processes to reclaim memory
21+
console.log("Warning Level: Critical");
22+
}
23+
});
24+
25+
function drop_caches() {
26+
cache.clear();
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "platform",
3+
"description": "Monitor system memory",
4+
"panels": ["code", "preview"],
5+
"autorun": true
6+
}

0 commit comments

Comments
 (0)