Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coffeeispower opened this issue Dec 25, 2024 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@coffeeispower
Copy link

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 coffeeispower added the enhancement New feature or request label Dec 25, 2024
@ARKye03
Copy link

ARKye03 commented Dec 25, 2024

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.

@coffeeispower
Copy link
Author

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

@coffeeispower
Copy link
Author

coffeeispower commented Dec 26, 2024

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";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants