mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
Ask the user permission to use the online database
This commit is contained in:
parent
6b02b4a31c
commit
4d61971a08
@ -3,7 +3,14 @@ use daemon::daemon_connection::DaemonConnection;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
enum Curve {
|
||||
enum ConfigOpt {
|
||||
Show,
|
||||
AllowOnlineUpdating,
|
||||
DisallowOnlineUpdating,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
enum CurveOpt {
|
||||
/// Shows current fan control information
|
||||
Status {
|
||||
/// Specify a GPU ID as printed in `lact-cli gpus`. By default, all GPUs are printed.
|
||||
@ -26,8 +33,9 @@ enum Opt {
|
||||
/// Specify a GPU ID as printed in `lact-cli gpus`. By default, all GPUs are printed.
|
||||
gpu_id: Option<u32>,
|
||||
},
|
||||
Config(ConfigOpt),
|
||||
/// Fan curve control
|
||||
Curve(Curve),
|
||||
Curve(CurveOpt),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -74,7 +82,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
Opt::Curve(curve) => match curve {
|
||||
Curve::Status { gpu_id } => {
|
||||
CurveOpt::Status { gpu_id } => {
|
||||
let mut gpu_ids: Vec<u32> = Vec::new();
|
||||
|
||||
if let Some(gpu_id) = gpu_id {
|
||||
@ -90,9 +98,36 @@ fn main() {
|
||||
}
|
||||
}
|
||||
},
|
||||
Opt::Config(config_opt) => match config_opt {
|
||||
ConfigOpt::Show => print_config(&d),
|
||||
ConfigOpt::AllowOnlineUpdating => enable_online_update(&d),
|
||||
ConfigOpt::DisallowOnlineUpdating => disable_online_update(&d),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn disable_online_update(d: &DaemonConnection) {
|
||||
let mut config = d.get_config().unwrap();
|
||||
config.allow_online_update = Some(false);
|
||||
d.set_config(config).unwrap();
|
||||
}
|
||||
|
||||
fn enable_online_update(d: &DaemonConnection) {
|
||||
let mut config = d.get_config().unwrap();
|
||||
config.allow_online_update = Some(true);
|
||||
d.set_config(config).unwrap();
|
||||
}
|
||||
|
||||
fn print_config(d: &DaemonConnection) {
|
||||
let config = d.get_config().unwrap();
|
||||
|
||||
println!(
|
||||
"{} {:?}",
|
||||
"Online PCI DB updating:".purple(),
|
||||
config.allow_online_update
|
||||
);
|
||||
}
|
||||
|
||||
fn print_fan_curve(d: &DaemonConnection, gpu_id: u32) {
|
||||
let fan_control = d.get_fan_control(gpu_id).unwrap();
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
use crate::gpu_controller::{FanControlInfo, GpuStats};
|
||||
use crate::gpu_controller::{GpuInfo, PowerProfile};
|
||||
use crate::DaemonError;
|
||||
use crate::{
|
||||
config::Config,
|
||||
gpu_controller::{FanControlInfo, GpuStats},
|
||||
};
|
||||
use crate::{Action, DaemonResponse, SOCK_PATH};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::io::{Read, Write};
|
||||
@ -164,4 +167,18 @@ impl DaemonConnection {
|
||||
s.write_all(&bincode::serialize(&Action::Shutdown).unwrap())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn get_config(&self) -> Result<Config, DaemonError> {
|
||||
match self.send_action(Action::GetConfig)? {
|
||||
DaemonResponse::Config(config) => Ok(config),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_config(&self, config: Config) -> Result<(), DaemonError> {
|
||||
match self.send_action(Action::SetConfig(config))? {
|
||||
DaemonResponse::OK => Ok(()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +292,10 @@ impl GpuController {
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{:?} pci.ids not found! Make sure you have 'hwdata' installed", err);
|
||||
println!(
|
||||
"{:?} pci.ids not found! Make sure you have 'hwdata' installed",
|
||||
err
|
||||
);
|
||||
VendorData::default()
|
||||
}
|
||||
},
|
||||
|
@ -32,6 +32,8 @@ pub struct Daemon {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum Action {
|
||||
CheckAlive,
|
||||
GetConfig,
|
||||
SetConfig(Config),
|
||||
GetGpus,
|
||||
GetInfo(u32),
|
||||
GetStats(u32),
|
||||
@ -81,8 +83,12 @@ impl Daemon {
|
||||
Config::new(&config_path)
|
||||
} else {
|
||||
match Config::read_from_file(&config_path) {
|
||||
Ok(c) => c,
|
||||
Ok(c) => {
|
||||
log::info!("Loaded config from {}", c.config_path.to_string_lossy());
|
||||
c
|
||||
}
|
||||
Err(_) => {
|
||||
log::info!("Config not found, creating");
|
||||
let c = Config::new(&config_path);
|
||||
//c.save().unwrap();
|
||||
c
|
||||
@ -90,7 +96,7 @@ impl Daemon {
|
||||
}
|
||||
};
|
||||
|
||||
log::trace!("Using config {:?}", config);
|
||||
log::info!("Using config {:?}", config);
|
||||
|
||||
let gpu_controllers = Self::load_gpu_controllers(&mut config);
|
||||
|
||||
@ -129,10 +135,25 @@ impl Daemon {
|
||||
|
||||
let mut controller =
|
||||
GpuController::new(entry.path().join("device"), GpuConfig::new(), &pci_db);
|
||||
let gpu_info = &controller.get_info();
|
||||
|
||||
let current_identifier = controller.get_identifier();
|
||||
|
||||
log::info!(
|
||||
"Searching the config for GPU with identifier {:?}",
|
||||
current_identifier
|
||||
);
|
||||
|
||||
log::info!("{}", &config.gpu_configs.len());
|
||||
for (id, (gpu_identifier, gpu_config)) in &config.gpu_configs {
|
||||
if gpu_info.pci_slot == gpu_identifier.pci_id
|
||||
log::info!("Comparing with {:?}", gpu_identifier);
|
||||
if current_identifier == *gpu_identifier {
|
||||
controller.load_config(&gpu_config);
|
||||
gpu_controllers.insert(id.clone(), controller);
|
||||
log::info!("already known");
|
||||
continue 'entries;
|
||||
}
|
||||
|
||||
/*if gpu_info.pci_slot == gpu_identifier.pci_id
|
||||
&& gpu_info.vendor_data.card_model == gpu_identifier.card_model
|
||||
&& gpu_info.vendor_data.gpu_model == gpu_identifier.gpu_model
|
||||
{
|
||||
@ -140,7 +161,7 @@ impl Daemon {
|
||||
gpu_controllers.insert(id.clone(), controller);
|
||||
log::info!("already known");
|
||||
continue 'entries;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
log::info!("initializing for the first time");
|
||||
@ -403,6 +424,14 @@ impl Daemon {
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
Action::SetConfig(config) => {
|
||||
self.config = config;
|
||||
self.gpu_controllers.clear();
|
||||
self.gpu_controllers = Self::load_gpu_controllers(&mut self.config);
|
||||
self.config.save().expect("Failed to save config");
|
||||
Ok(DaemonResponse::OK)
|
||||
}
|
||||
Action::GetConfig => Ok(DaemonResponse::Config(self.config.clone())),
|
||||
};
|
||||
|
||||
log::trace!("Responding");
|
||||
@ -429,6 +458,7 @@ pub enum DaemonResponse {
|
||||
Gpus(HashMap<u32, Option<String>>),
|
||||
PowerCap((i64, i64)),
|
||||
FanControlInfo(gpu_controller::FanControlInfo),
|
||||
Config(Config),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -12,11 +12,37 @@ fn main() {
|
||||
panic!("Cannot initialize GTK");
|
||||
}
|
||||
|
||||
let app = App::new(connect_daemon());
|
||||
let connection = connect_daemon();
|
||||
|
||||
ask_for_online_update(&connection);
|
||||
|
||||
let app = App::new(connection);
|
||||
|
||||
app.run().unwrap();
|
||||
}
|
||||
|
||||
fn ask_for_online_update(connection: &DaemonConnection) {
|
||||
let mut config = connection.get_config().unwrap();
|
||||
|
||||
if let None = config.allow_online_update {
|
||||
let diag = MessageDialog::new(
|
||||
None::<&Window>,
|
||||
DialogFlags::empty(),
|
||||
MessageType::Warning,
|
||||
ButtonsType::YesNo,
|
||||
"Do you wish to use the online database for GPU identification?",
|
||||
);
|
||||
match diag.run() {
|
||||
ResponseType::Yes => config.allow_online_update = Some(true),
|
||||
ResponseType::No => config.allow_online_update = Some(false),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
diag.hide();
|
||||
|
||||
connection.set_config(config).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn connect_daemon() -> DaemonConnection {
|
||||
match DaemonConnection::new() {
|
||||
Ok(connection) => {
|
||||
|
Loading…
Reference in New Issue
Block a user