Skip to content

Commit e9d1274

Browse files
authored
Merge pull request #18 from derenv/wakatime_badge
Added badges & Enabling CodeCov
2 parents ef22059 + 1c20b1e commit e9d1274

File tree

15 files changed

+154
-154
lines changed

15 files changed

+154
-154
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
55

66
# Description
77

8+
[![wakatime](https://wakatime.com/badge/user/8ce81774-1d46-4c72-8a15-b5cf4032138f/project/64d5b278-0a3f-4b93-9a34-5cf88c7a8a3a.svg)](https://wakatime.com/badge/user/8ce81774-1d46-4c72-8a15-b5cf4032138f/project/64d5b278-0a3f-4b93-9a34-5cf88c7a8a3a)
9+
10+
![CI](https://github.com/derenv/gtk4-nvidia-monitor-rust/actions/workflows/rust.yml/badge.svg)
11+
12+
[![Test Coverage](https://codecov.io/gh/derenv/gtk4-nvidia-monitor-rust/branch/main/graph/badge.svg?token=PHDU5O3VFZ)](https://codecov.io/gh/derenv/gtk4-nvidia-monitor-rust)
13+
814
This project is a rewrite of gnome-nvidia-extension in Rust - intended as a practise Rust project.
915

1016
# Usage

build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* [build-dependencies]
2222
* gtk = { version = "^0.4.8", package = "gtk4" }
2323
*/
24-
2524
// Imports
2625
use adwaita::gio::compile_resources;
2726

src/custom_button/imp.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Notes:
1818
*
1919
*/
20-
2120
// Imports
2221
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
2322
use gtk::{glib, subclass::prelude::*};
@@ -97,7 +96,7 @@ impl ObjectImpl for CustomButton {
9796

9897
match pspec.name() {
9998
//
100-
_ => panic!("Property `{}` does not exist..", pspec.name())
99+
_ => panic!("Property `{}` does not exist..", pspec.name()),
101100
}
102101
}
103102

@@ -122,7 +121,7 @@ impl ObjectImpl for CustomButton {
122121

123122
match pspec.name() {
124123
//
125-
_ => panic!("Property `{}` does not exist..", pspec.name())
124+
_ => panic!("Property `{}` does not exist..", pspec.name()),
126125
}
127126
}
128127
}

src/custom_button/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Notes:
1818
*
1919
*/
20-
2120
// Custom GObjects
2221
mod imp;
2322

src/formatter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ impl Formatter {
186186
// Grab all format info from settings (this is done here to keep in one place)
187187
//===
188188
let mut _params: Vec<(String, String)> = vec![]; //mut
189-
//TODO: ???
190-
//
191-
//===
189+
//TODO: ???
190+
//
191+
//===
192192

193193
// Use function
194194
let result: Option<String>;

src/gpu_page/mod.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ mod imp;
2424
use adwaita::{gio, glib};
2525
use gio::Settings;
2626
use glib::Object;
27-
use gtk::{
28-
prelude::*, subclass::prelude::*, Grid, Button, Label, LayoutChild, Orientation, Align
29-
};
27+
use gtk::{prelude::*, subclass::prelude::*, Align, Button, Grid, Label, LayoutChild, Orientation};
3028
use std::{sync::Arc, sync::Mutex, sync::MutexGuard};
3129

3230
// Modules
@@ -165,8 +163,11 @@ impl GpuPage {
165163
// TODO: Load config of gpu (use uuid as ID)
166164
// TODO: needs to be a vector as may bed of variable size..
167165
//let statistics: Vec<&str> = load_json_settings(&self.property("uuid"));//array?vector?json-type object?
168-
let statistics_data: Vec<&str>;//TEST
169-
match self.property::<Provider>("provider").property::<i32>("provider-type") {
166+
let statistics_data: Vec<&str>; //TEST
167+
match self
168+
.property::<Provider>("provider")
169+
.property::<i32>("provider-type")
170+
{
170171
1 => {
171172
statistics_data = vec![
172173
"util",
@@ -245,43 +246,43 @@ impl GpuPage {
245246
"util" => {
246247
pretty_label = "GPU Utilization";
247248
space = 5
248-
},
249+
}
249250
"mem_ctrl_util" => {
250251
pretty_label = "Memory Controller Utilization";
251252
space = 5
252-
},
253+
}
253254
"encoder_util" => {
254255
pretty_label = "Encoder Utilization";
255256
space = 5
256-
},
257+
}
257258
"decoder_util" => {
258259
pretty_label = "Decoder Utilization";
259260
space = 5
260-
},
261+
}
261262
"fan_speed" => {
262263
pretty_label = "Fan Speed";
263264
space = 5
264-
},
265+
}
265266
"temp" => {
266267
pretty_label = "Temperature";
267268
space = 5
268-
},
269+
}
269270
"memory_usage" => {
270271
pretty_label = "Memory Usage";
271272
space = 8
272-
},
273+
}
273274
"memory_total" => {
274275
pretty_label = "Memory Total";
275276
space = 8
276-
},
277+
}
277278
"power_usage" => {
278279
pretty_label = "Power Usage";
279280
space = 8
280-
},
281+
}
281282
_ => {
282283
pretty_label = statistic;
283284
space = 5
284-
},
285+
}
285286
}
286287

287288
// Build title label & add to grid
@@ -300,7 +301,8 @@ impl GpuPage {
300301
new_grid.attach(&new_title_label, 0, 0, 1, 1);
301302

302303
// Set layout properties of (title label) child
303-
let title_manager: LayoutChild = internal_grid_manager.layout_child(&new_title_label);
304+
let title_manager: LayoutChild =
305+
internal_grid_manager.layout_child(&new_title_label);
304306
title_manager.set_property("row-span", 1);
305307

306308
// Decide on content label size
@@ -323,10 +325,10 @@ impl GpuPage {
323325
new_grid.attach(&new_content_label, 1, 0, 1, 1);
324326

325327
// Set layout properties of (content label) child
326-
let content_manager: LayoutChild = internal_grid_manager.layout_child(&new_content_label);
328+
let content_manager: LayoutChild =
329+
internal_grid_manager.layout_child(&new_content_label);
327330
content_manager.set_property("row-span", 1);
328331

329-
330332
//==SHOW==
331333
// Show new labels & grid
332334
new_grid.show();
@@ -341,7 +343,8 @@ impl GpuPage {
341343
let uuid_store: Arc<Mutex<String>> = Arc::new(Mutex::new(self.property("uuid")));
342344

343345
// Create thread safe container for provider
344-
let provider_store: Arc<Mutex<Option<Provider>>> = Arc::new(Mutex::new(self.property("provider")));
346+
let provider_store: Arc<Mutex<Option<Provider>>> =
347+
Arc::new(Mutex::new(self.property("provider")));
345348

346349
// Async fill the labels
347350
glib::timeout_add_seconds_local(refresh_rate, move || {
@@ -354,11 +357,12 @@ impl GpuPage {
354357
let uuid: String = uuid_lock.lock().unwrap().as_str().to_owned();
355358
// current provider for scanning gpu data
356359
let provider_lock: Arc<Mutex<Option<Provider>>> = Arc::clone(&provider_store);
357-
let mut provider_container: MutexGuard<Option<Provider>> = provider_lock.lock().unwrap();
360+
let mut provider_container: MutexGuard<Option<Provider>> =
361+
provider_lock.lock().unwrap();
358362

359363
// For each Statistic
360364
match &mut *provider_container {
361-
Some(prov) =>
365+
Some(prov) => {
362366
for statistic in statistics.iter() {
363367
// Grab current stat from provider
364368
match prov.get_gpu_data(&uuid, statistic) {
@@ -377,6 +381,7 @@ impl GpuPage {
377381
}
378382
}
379383
}
384+
}
380385
None => todo!(),
381386
}
382387

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
*/
2020
// Modules
2121
mod formatter;
22+
mod gpu_page;
2223
mod mainwindow;
2324
mod processor;
2425
mod property;
2526
mod provider;
2627
mod subprocess;
27-
mod gpu_page;
2828
use mainwindow::MainWindow;
2929
mod custom_button;
3030
mod settingswindow;

src/mainwindow/imp.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
use adwaita::{gio, glib, prelude::*, subclass::prelude::*};
2222
use gio::Settings;
2323
use glib::{
24-
once_cell::sync::Lazy, once_cell::sync::OnceCell, signal::Inhibit,
24+
clone, once_cell::sync::Lazy, once_cell::sync::OnceCell, signal::Inhibit,
2525
subclass::InitializingObject, FromVariant, ParamSpec, Value,
26-
clone
2726
};
2827
use gtk::{
2928
subclass::prelude::*, Button, CompositeTemplate, PolicyType, ScrolledWindow, Stack,
3029
TemplateChild,
3130
};
32-
use std::{cell::Cell, cell::RefCell, cell::RefMut, rc::Rc, sync::Arc, sync::Mutex, sync::MutexGuard};
31+
use std::{
32+
cell::Cell, cell::RefCell, cell::RefMut, rc::Rc, sync::Arc, sync::Mutex, sync::MutexGuard,
33+
};
3334

3435
// Modules
3536
use crate::{
@@ -1429,7 +1430,8 @@ impl MainWindow {
14291430
// Construct a row for each GPU
14301431
for uuid in gpu_uuids {
14311432
// Grab current provider
1432-
let provider_container: Option<Provider> = self.provider.take();
1433+
let provider_container: Option<Provider> =
1434+
self.provider.take();
14331435
self.provider.set(provider_container.clone());
14341436

14351437
// Get GPU data
@@ -1451,13 +1453,16 @@ impl MainWindow {
14511453
}
14521454
}
14531455
Err(err) => {
1454-
println!("..Attempt to update GPU list failed, returning: {}", err)
1456+
println!(
1457+
"..Attempt to update GPU list failed, returning: {}",
1458+
err
1459+
)
14551460
}
14561461
}
14571462
}
14581463
None => todo!(),
14591464
}
1460-
} else{
1465+
} else {
14611466
// Update GPU list
14621467
match existing_provider.get_gpu_uuids() {
14631468
Ok(gpu_uuids) => {
@@ -1484,7 +1489,9 @@ impl MainWindow {
14841489
}
14851490
}
14861491
}
1487-
Err(err) => println!("..Attempt to update GPU list failed, returning: {}", err),
1492+
Err(err) => {
1493+
println!("..Attempt to update GPU list failed, returning: {}", err)
1494+
}
14881495
}
14891496
}
14901497
}
@@ -1507,7 +1514,7 @@ impl MainWindow {
15071514
// Construct a row for each GPU
15081515
for uuid in gpu_uuids {
15091516
println!("UUID: `{}`", uuid); //TEST
1510-
// Grab current provider
1517+
// Grab current provider
15111518
let provider_container: Option<Provider> = self.provider.take();
15121519
self.provider.set(provider_container.clone());
15131520

src/processor/imp.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-FileCopyrightText: 2022 Deren Vural
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

4+
use adwaita::glib;
5+
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
6+
use gtk::{prelude::*, subclass::prelude::*};
47
/**
58
* Name:
69
* imp.rs
@@ -19,12 +22,8 @@
1922
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_properties/4/custom_button/imp.rs>
2023
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_properties/4/custom_button/mod.rs>
2124
*/
22-
2325
// Imports
2426
use std::cell::Cell;
25-
use adwaita::glib;
26-
use glib::{once_cell::sync::Lazy, ParamSpec, Value};
27-
use gtk::{prelude::*, subclass::prelude::*};
2827

2928
/// Object holding the State and any Template Children
3029
#[derive(Default)]

src/processor/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ impl Processor {
6969
* Notes:
7070
*
7171
*/
72-
pub fn new(base_call: &str, start_call: &str, middle_call: Option<&str>, end_call: &str) -> Self {
72+
pub fn new(
73+
base_call: &str,
74+
start_call: &str,
75+
middle_call: Option<&str>,
76+
end_call: &str,
77+
) -> Self {
7378
let obj: Processor = Object::new(&[]).expect("Failed to create `Processor`");
7479

7580
// Set properties
@@ -109,7 +114,7 @@ impl Processor {
109114
uuid: Option<&str>,
110115
property: Option<&str>,
111116
) -> Result<Option<Vec<String>>, glib::Error> {
112-
println!("PROCESS BEGINNING");//TEST
117+
println!("PROCESS BEGINNING"); //TEST
113118

114119
// Create call stack of program and args
115120
let mut call_stack: String = self.property("base-call"); //"nvidia-smi" OR "nvidia-settings" OR "optirun"
@@ -138,7 +143,7 @@ impl Processor {
138143
}
139144
}
140145

141-
println!("CALL STACK: `{}`", call_stack);//TEST
146+
println!("CALL STACK: `{}`", call_stack); //TEST
142147

143148
// Turn call stack into bytes and create vector for final call stack
144149
let call_stack_bytes: &[u8] = call_stack.as_bytes();
@@ -299,7 +304,11 @@ impl Processor {
299304
3 => {
300305
//nvidia-settings -q=[gpu:GPU-xx-xx-xx-xx-xx]/GPUUtilization -t
301306
// Build array
302-
let argv: [&OsStr; 3] = [call_stack_items[0], call_stack_items[1], call_stack_items[2]];
307+
let argv: [&OsStr; 3] = [
308+
call_stack_items[0],
309+
call_stack_items[1],
310+
call_stack_items[2],
311+
];
303312

304313
// Run process, get output
305314
match exec_communicate(&argv, None::<&gio::Cancellable>) {
@@ -367,8 +376,8 @@ impl Processor {
367376
_invalid_size => {
368377
// This will only occur via programmer error
369378
println!("oops..");
370-
return Ok(None)
371-
},
379+
return Ok(None);
380+
}
372381
}
373382

374383
Ok(None)

0 commit comments

Comments
 (0)