summaryrefslogtreecommitdiff
path: root/src/services/storage.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-30 21:31:19 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-30 21:31:19 +1100
commitad22dbdfebbb0def2ec2d8e2c91469e9a9e4fdf7 (patch)
tree826e715ae0aa7d4c5bcd29d76421a211b920dca1 /src/services/storage.ts
parentsideright: fix assertion row != -1 (diff)
downloadcaelestia-shell-ad22dbdfebbb0def2ec2d8e2c91469e9a9e4fdf7.tar.gz
caelestia-shell-ad22dbdfebbb0def2ec2d8e2c91469e9a9e4fdf7.tar.bz2
caelestia-shell-ad22dbdfebbb0def2ec2d8e2c91469e9a9e4fdf7.zip
sideleft: create popdown window
Diffstat (limited to 'src/services/storage.ts')
-rw-r--r--src/services/storage.ts61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/services/storage.ts b/src/services/storage.ts
new file mode 100644
index 0000000..e1e1c55
--- /dev/null
+++ b/src/services/storage.ts
@@ -0,0 +1,61 @@
+import { GObject, interval, property, register } from "astal";
+import { storage as config } from "config";
+import GTop from "gi://GTop";
+
+@register({ GTypeName: "Storage" })
+export default class Storage extends GObject.Object {
+ static instance: Storage;
+ static get_default() {
+ if (!this.instance) this.instance = new Storage();
+
+ return this.instance;
+ }
+
+ #total: number = 0;
+ #free: number = 0;
+ #used: number = 0;
+ #usage: number = 0;
+
+ @property(Number)
+ get total() {
+ return this.#total;
+ }
+
+ @property(Number)
+ get free() {
+ return this.#free;
+ }
+
+ @property(Number)
+ get used() {
+ return this.#used;
+ }
+
+ @property(Number)
+ get usage() {
+ return this.#usage;
+ }
+
+ update() {
+ const root = new GTop.glibtop_fsusage();
+ GTop.glibtop_get_fsusage(root, "/");
+ const home = new GTop.glibtop_fsusage();
+ GTop.glibtop_get_fsusage(home, "/home");
+
+ this.#total = root.blocks * root.block_size + home.blocks * home.block_size;
+ this.#free = root.bavail * root.block_size + home.bavail * home.block_size;
+ this.#used = this.#total - this.#free;
+ this.#usage = this.#total > 0 ? (this.#used / this.#total) * 100 : 0;
+
+ this.notify("total");
+ this.notify("free");
+ this.notify("used");
+ this.notify("usage");
+ }
+
+ constructor() {
+ super();
+
+ interval(config.interval, () => this.update());
+ }
+}