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

Better memory and storage info #251

Merged
merged 5 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (var object in client.object_manager.get_objects ()) {
vjr marked this conversation as resolved.
Show resolved Hide resolved
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