Skip to content

Commit

Permalink
Better memory and storage info (#251)
Browse files Browse the repository at this point in the history
* Better memory info

* Better storage info

* Update github workflow with new dependencies

* Use unowned keyword as suggested
  • Loading branch information
vjr authored Oct 4, 2022
1 parent bd38ffc commit fc4cdcf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y meson libfwupd-dev libgranite-dev libgtk-3-dev libgtop2-dev libhandy-1-dev libswitchboard-2.0-dev libappstream-dev valac
apt install -y meson libfwupd-dev libgranite-dev libgtk-3-dev libgtop2-dev libgudev-1.0-dev libudisks2-dev libhandy-1-dev libswitchboard-2.0-dev libappstream-dev valac
- name: Build
env:
DESTDIR: out
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ You'll need the following dependencies:
* libgranite-dev
* libgtk-3-dev
* libgtop2-dev
* libgudev-1.0-dev
* libudisks2-dev
* libhandy-1-dev
* libappstream-dev
* meson
Expand Down
47 changes: 44 additions & 3 deletions src/Views/HardwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,28 @@ public class About.HardwareView : Gtk.Grid {
}
}

private string get_mem_info () {
uint64 mem_total = 0;

GUdev.Client client = new GUdev.Client ({"dmi"});
GUdev.Device? device = client.query_by_sysfs_path ("/sys/devices/virtual/dmi/id");

if (device != null) {
uint64 devices = device.get_property_as_uint64 ("MEMORY_ARRAY_NUM_DEVICES");
for (int item = 0; item < devices; item++) {
mem_total += device.get_property_as_uint64 ("MEMORY_DEVICE_%d_SIZE".printf (item));
}
}

if (mem_total == 0) {
GLibTop.mem mem;
GLibTop.get_mem (out mem);
mem_total = mem.total;
}

return GLib.format_size (mem_total, GLib.FormatSizeFlags.IEC_UNITS);
}

private void fetch_hardware_info () {
string? cpu = get_cpu_info ();

Expand All @@ -351,9 +373,7 @@ public class About.HardwareView : Gtk.Grid {
processor = cpu;
}

GLibTop.mem mem;
GLibTop.get_mem (out mem);
memory = GLib.format_size (mem.total, GLib.FormatSizeFlags.IEC_UNITS);
memory = get_mem_info ();

get_graphics_info.begin ();
get_storage_info.begin ();
Expand Down Expand Up @@ -395,6 +415,27 @@ public class About.HardwareView : Gtk.Grid {
private async void get_storage_info () {
var file_root = GLib.File.new_for_path ("/");
string storage_capacity = "";

uint64 storage_total = 0;

try {
UDisks.Client client = yield new UDisks.Client (null);
foreach (unowned var object in client.object_manager.get_objects ()) {
UDisks.Drive drive = ((UDisks.Object)object).drive;
if (drive == null || drive.removable || drive.ejectable) {
continue;
}
storage_total += drive.size;
}
if (storage_total != 0) {
storage_capacity = GLib.format_size (storage_total);
storage_info.label = yield get_storage_type (storage_capacity);
return;
}
} catch (Error e) {
warning (e.message);
}

try {
var info = yield file_root.query_filesystem_info_async (GLib.FileAttribute.FILESYSTEM_SIZE);
storage_capacity = GLib.format_size (info.get_attribute_uint64 (GLib.FileAttribute.FILESYSTEM_SIZE));
Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ shared_module(
dependency('granite'),
dependency('gtk+-3.0'),
dependency('libgtop-2.0'),
dependency('gudev-1.0'),
dependency('udisks2'),
dependency('libhandy-1'),
dependency ('appstream', version: '>=0.12.10'),
meson.get_compiler('vala').find_library('posix'),
Expand Down

0 comments on commit fc4cdcf

Please sign in to comment.