Astal icon indicating copy to clipboard operation
Astal copied to clipboard

Add functions for fetching information about CPU, RAM and Disk usage

Open coffeeispower opened this issue 1 year ago • 3 comments

I'm trying to build like a dashboard for my system using AGS for displaying CPU, RAM and disk usage as well as wifi, bluetooth, and monitor settings and other utilities.

imagem

There's no builtin function for getting CPU usage, memory usage and disks that are mounted on the system so I'll have to build those myself reading directly from /proc which is not ideal. You have libraries for cava, bluetooth and network manager but you forgot the most basic thing which is CPU and RAM.

coffeeispower avatar Dec 25 '24 22:12 coffeeispower

There's no builtin function for getting CPU usage, memory usage and disks that are mounted on the system so I'll have to build those myself reading directly from /proc which is not ideal. You have libraries for cava, bluetooth and network manager but you forgot the most basic thing which is CPU and RAM.

You could, and should use libgtop which is Glib implementation of top, the library most GTK Dashboards like the Elementary one use. I use it here for instance, but it gives almost all the information you could need.

ARKye03 avatar Dec 25 '24 22:12 ARKye03

@ARKye03 But how do I call it from javascript/GJS?

coffeeispower avatar Dec 26 '24 19:12 coffeeispower

figured it out myself:

flake.nix:

{
  description = "My Awesome Desktop Shell";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

    ags = {
      url = "github:aylur/ags";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    ags,
  }: let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
  in {
    packages.${system} = {
      default = ags.lib.bundle {
        inherit pkgs;
        src = ./.;
        name = "ags-desktop";
        entry = "app.ts";

        # additional libraries and executables to add to gjs' runtime
        extraPackages = with ags.packages.${system}; [
          hyprland
          battery
          apps
          pkgs.libgtop
        ];
      };
    };

    devShells.${system} = {
      default = pkgs.mkShell {
        nativeBuildInputs = [
          pkgs.biome
          pkgs.nodePackages.nodemon
          pkgs.just
          (ags.packages.${system}.agsFull.override {
            extraPackages = [
              # you need to include libgtop here to add to the gjs runtime environment
              pkgs.libgtop
            ];
          })
        ];
      };
    };
  };
}

Javascript/Typescript:

import GTop from "gi://GTop";

coffeeispower avatar Dec 26 '24 22:12 coffeeispower