mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 09:52:00 -04:00
Run cargo fmt --all.
Fixes code styling in all source files.
This commit is contained in:
parent
bf3cca29ac
commit
0c4b661d16
2 changed files with 135 additions and 60 deletions
14
src/main.rs
14
src/main.rs
|
@ -28,21 +28,19 @@ use zbus::{ConnectionBuilder, Result};
|
||||||
pub mod manager;
|
pub mod manager;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()>
|
async fn main() -> Result<()> {
|
||||||
{
|
|
||||||
// This daemon is responsible for creating a dbus api that steam client can use to do various OS
|
// This daemon is responsible for creating a dbus api that steam client can use to do various OS
|
||||||
// level things. It implements com.steampowered.SteamOSManager1 interface
|
// level things. It implements com.steampowered.SteamOSManager1 interface
|
||||||
|
|
||||||
let manager = manager::SMManager {};
|
let manager = manager::SMManager {};
|
||||||
|
|
||||||
let _system_connection = ConnectionBuilder::system()?
|
let _system_connection = ConnectionBuilder::system()?
|
||||||
.name("com.steampowered.SteamOSManager1")?
|
.name("com.steampowered.SteamOSManager1")?
|
||||||
.serve_at("/com/steampowered/SteamOSManager1", manager)?
|
.serve_at("/com/steampowered/SteamOSManager1", manager)?
|
||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
loop
|
loop {
|
||||||
{
|
|
||||||
std::future::pending::<()>().await;
|
std::future::pending::<()>().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
163
src/manager.rs
163
src/manager.rs
|
@ -23,14 +23,19 @@
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{ffi::OsStr, os::fd::{FromRawFd, IntoRawFd}};
|
use std::{
|
||||||
use tokio::{process::Command, fs::File, io::AsyncWriteExt};
|
ffi::OsStr,
|
||||||
|
os::fd::{FromRawFd, IntoRawFd},
|
||||||
|
};
|
||||||
|
use tokio::{fs::File, io::AsyncWriteExt, process::Command};
|
||||||
use zbus::zvariant::OwnedFd;
|
use zbus::zvariant::OwnedFd;
|
||||||
use zbus_macros::dbus_interface;
|
use zbus_macros::dbus_interface;
|
||||||
pub struct SMManager {
|
pub struct SMManager {}
|
||||||
}
|
|
||||||
|
|
||||||
async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<bool, Box<dyn std::error::Error>> {
|
async fn script_exit_code(
|
||||||
|
executable: &str,
|
||||||
|
args: &[impl AsRef<OsStr>],
|
||||||
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
// Run given script and return true on success
|
// Run given script and return true on success
|
||||||
let mut child = Command::new(executable)
|
let mut child = Command::new(executable)
|
||||||
.args(args)
|
.args(args)
|
||||||
|
@ -45,14 +50,19 @@ async fn run_script(name: &str, executable: &str, args: &[impl AsRef<OsStr>]) ->
|
||||||
// Return false on failure, but also print an error if needed
|
// Return false on failure, but also print an error if needed
|
||||||
match script_exit_code(executable, args).await {
|
match script_exit_code(executable, args).await {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(err) => { println!("Error running {} {}", name, err); false}
|
Err(err) => {
|
||||||
|
println!("Error running {} {}", name, err);
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn script_output(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<String, Box<dyn std::error::Error>> {
|
async fn script_output(
|
||||||
|
executable: &str,
|
||||||
|
args: &[impl AsRef<OsStr>],
|
||||||
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
// Run given command and return the output given
|
// Run given command and return the output given
|
||||||
let output = Command::new(executable)
|
let output = Command::new(executable).args(args).output();
|
||||||
.args(args).output();
|
|
||||||
|
|
||||||
let output = output.await?;
|
let output = output.await?;
|
||||||
|
|
||||||
|
@ -67,7 +77,6 @@ async fn script_output(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<S
|
||||||
impl SMManager {
|
impl SMManager {
|
||||||
const API_VERSION: u32 = 1;
|
const API_VERSION: u32 = 1;
|
||||||
|
|
||||||
|
|
||||||
async fn say_hello(&self, name: &str) -> String {
|
async fn say_hello(&self, name: &str) -> String {
|
||||||
format!("Hello {}!", name)
|
format!("Hello {}!", name)
|
||||||
}
|
}
|
||||||
|
@ -79,15 +88,30 @@ impl SMManager {
|
||||||
|
|
||||||
async fn disable_wifi_power_management(&self) -> bool {
|
async fn disable_wifi_power_management(&self) -> bool {
|
||||||
// Run polkit helper script and return true on success
|
// Run polkit helper script and return true on success
|
||||||
run_script("disable wifi power management", "/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management", &[""]).await
|
run_script(
|
||||||
|
"disable wifi power management",
|
||||||
|
"/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn enable_fan_control(&self, enable: bool) -> bool {
|
async fn enable_fan_control(&self, enable: bool) -> bool {
|
||||||
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
// Run what steamos-polkit-helpers/jupiter-fan-control does
|
||||||
if enable {
|
if enable {
|
||||||
run_script("enable fan control", "systemcltl", &["start", "jupiter-fan-control-service"]).await
|
run_script(
|
||||||
|
"enable fan control",
|
||||||
|
"systemcltl",
|
||||||
|
&["start", "jupiter-fan-control-service"],
|
||||||
|
)
|
||||||
|
.await
|
||||||
} else {
|
} else {
|
||||||
run_script("disable fan control", "systemctl", &["stop", "jupiter-fan-control.service"]).await
|
run_script(
|
||||||
|
"disable fan control",
|
||||||
|
"systemctl",
|
||||||
|
&["stop", "jupiter-fan-control.service"],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +123,11 @@ impl SMManager {
|
||||||
|
|
||||||
async fn read_als_calibration(&self) -> f32 {
|
async fn read_als_calibration(&self) -> f32 {
|
||||||
// Run script to get calibration value
|
// Run script to get calibration value
|
||||||
let result = script_output("/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain", &[""]).await;
|
let result = script_output(
|
||||||
|
"/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
let mut value: f32 = -1.0;
|
let mut value: f32 = -1.0;
|
||||||
match result {
|
match result {
|
||||||
Ok(as_string) => value = as_string.trim().parse().unwrap(),
|
Ok(as_string) => value = as_string.trim().parse().unwrap(),
|
||||||
|
@ -112,55 +140,76 @@ impl SMManager {
|
||||||
async fn update_bios(&self) -> bool {
|
async fn update_bios(&self) -> bool {
|
||||||
// Update the bios as needed
|
// Update the bios as needed
|
||||||
// Return true if the script was successful (though that might mean no update was needed), false otherwise
|
// Return true if the script was successful (though that might mean no update was needed), false otherwise
|
||||||
run_script("update bios", "/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate", &["--auto"]).await
|
run_script(
|
||||||
|
"update bios",
|
||||||
|
"/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate",
|
||||||
|
&["--auto"],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_dock(&self) -> bool {
|
async fn update_dock(&self) -> bool {
|
||||||
// Update the dock firmware as needed
|
// Update the dock firmware as needed
|
||||||
// Retur true if successful, false otherwise
|
// Retur true if successful, false otherwise
|
||||||
run_script("update dock firmware", "/usr/bin/steamos-polkit-helpers/jupiter-dock-updater", &[""]).await
|
run_script(
|
||||||
|
"update dock firmware",
|
||||||
|
"/usr/bin/steamos-polkit-helpers/jupiter-dock-updater",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn trim_devices(&self) -> bool {
|
async fn trim_devices(&self) -> bool {
|
||||||
// Run steamos-trim-devices script
|
// Run steamos-trim-devices script
|
||||||
// return true on success, false otherwise
|
// return true on success, false otherwise
|
||||||
run_script("trim devices", "/usr/bin/steamos-polkit-helpers/steamos-trim-devices", &[""]).await
|
run_script(
|
||||||
|
"trim devices",
|
||||||
|
"/usr/bin/steamos-polkit-helpers/steamos-trim-devices",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn format_sdcard(&self) -> bool {
|
async fn format_sdcard(&self) -> bool {
|
||||||
// Run steamos-format-sdcard script
|
// Run steamos-format-sdcard script
|
||||||
// return true on success, false otherwise
|
// return true on success, false otherwise
|
||||||
run_script("format sdcard", "/usr/bin/steamos-polkit-helpers/steamos-format-sdcard", &[""]).await
|
run_script(
|
||||||
|
"format sdcard",
|
||||||
|
"/usr/bin/steamos-polkit-helpers/steamos-format-sdcard",
|
||||||
|
&[""],
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_gpu_performance_level(&self, level: i32) -> bool {
|
async fn set_gpu_performance_level(&self, level: i32) -> bool {
|
||||||
// Set given level to sysfs path /sys/class/drm/card0/device/power_dpm_force_performance_level
|
// Set given level to sysfs path /sys/class/drm/card0/device/power_dpm_force_performance_level
|
||||||
// Levels are defined below
|
// Levels are defined below
|
||||||
// return true if able to write, false otherwise or if level is out of range, etc.
|
// return true if able to write, false otherwise or if level is out of range, etc.
|
||||||
let levels = [
|
let levels = ["auto", "low", "high", "manual", "peak_performance"];
|
||||||
"auto",
|
|
||||||
"low",
|
|
||||||
"high",
|
|
||||||
"manual",
|
|
||||||
"peak_performance"
|
|
||||||
];
|
|
||||||
if level < 0 || level >= levels.len() as i32 {
|
if level < 0 || level >= levels.len() as i32 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open sysfs file
|
// Open sysfs file
|
||||||
let result = File::create("/sys/class/drm/card0/device/power_dpm_force_performance_level").await;
|
let result =
|
||||||
|
File::create("/sys/class/drm/card0/device/power_dpm_force_performance_level").await;
|
||||||
let mut myfile;
|
let mut myfile;
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => myfile = f,
|
Ok(f) => myfile = f,
|
||||||
Err(message) => { println!("Error opening sysfs file for writing {message}"); return false; }
|
Err(message) => {
|
||||||
|
println!("Error opening sysfs file for writing {message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// write value
|
// write value
|
||||||
let result = myfile.write_all(levels[level as usize].as_bytes()).await;
|
let result = myfile.write_all(levels[level as usize].as_bytes()).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(_worked) => true,
|
Ok(_worked) => true,
|
||||||
Err(message) => { println!("Error writing to sysfs file {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to sysfs file {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +225,10 @@ impl SMManager {
|
||||||
let mut myfile;
|
let mut myfile;
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => myfile = f,
|
Ok(f) => myfile = f,
|
||||||
Err(message) => { println!("Error opening sysfs file for writing {message}"); return false; }
|
Err(message) => {
|
||||||
|
println!("Error opening sysfs file for writing {message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// write value
|
// write value
|
||||||
|
@ -191,13 +243,22 @@ impl SMManager {
|
||||||
let result = myfile.write("c\n".as_bytes()).await;
|
let result = myfile.write("c\n".as_bytes()).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(_worked) => true,
|
Ok(_worked) => true,
|
||||||
Err(message) => { println!("Error writing to sysfs file {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to sysfs file {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(message) => { println!("Error writing to sysfs file {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to sysfs file {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(message) => { println!("Error writing to sysfs file {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to sysfs file {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,14 +274,20 @@ impl SMManager {
|
||||||
let mut power1file;
|
let mut power1file;
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => power1file = f,
|
Ok(f) => power1file = f,
|
||||||
Err(message) => { println!("Error opening sysfs power1_cap file for writing TDP limits {message}"); return false; }
|
Err(message) => {
|
||||||
|
println!("Error opening sysfs power1_cap file for writing TDP limits {message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = File::create("/sys/class/hwmon/hwmon5/power2_cap").await;
|
let result = File::create("/sys/class/hwmon/hwmon5/power2_cap").await;
|
||||||
let mut power2file;
|
let mut power2file;
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => power2file = f,
|
Ok(f) => power2file = f,
|
||||||
Err(message) => { println!("Error opening sysfs power2_cap file for wtriting TDP limits {message}"); return false; }
|
Err(message) => {
|
||||||
|
println!("Error opening sysfs power2_cap file for wtriting TDP limits {message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Now write the value * 1,000,000
|
// Now write the value * 1,000,000
|
||||||
|
@ -231,14 +298,22 @@ impl SMManager {
|
||||||
let result = power2file.write(data.as_bytes()).await;
|
let result = power2file.write(data.as_bytes()).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(_worked) => true,
|
Ok(_worked) => true,
|
||||||
Err(message) => { println!("Error writing to power2_cap file: {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to power2_cap file: {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(message) => { println!("Error writing to power1_cap file: {message}"); false }
|
Err(message) => {
|
||||||
|
println!("Error writing to power1_cap file: {message}");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_als_integration_time_file_descriptor(&self) -> Result<zbus::zvariant::OwnedFd, zbus::fdo::Error> {
|
async fn get_als_integration_time_file_descriptor(
|
||||||
|
&self,
|
||||||
|
) -> Result<zbus::zvariant::OwnedFd, zbus::fdo::Error> {
|
||||||
// Get the file descriptor for the als integration time sysfs path
|
// Get the file descriptor for the als integration time sysfs path
|
||||||
// /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time
|
// /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time
|
||||||
// Return -1 on error
|
// Return -1 on error
|
||||||
|
@ -250,8 +325,11 @@ impl SMManager {
|
||||||
let fd: OwnedFd = OwnedFd::from_raw_fd(raw);
|
let fd: OwnedFd = OwnedFd::from_raw_fd(raw);
|
||||||
Ok(fd)
|
Ok(fd)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(message) => { println!("Error opening sysfs file for giving file descriptor {message}"); Err(zbus::fdo::Error::IOError(message.to_string())) }
|
Err(message) => {
|
||||||
|
println!("Error opening sysfs file for giving file descriptor {message}");
|
||||||
|
Err(zbus::fdo::Error::IOError(message.to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,4 +339,3 @@ impl SMManager {
|
||||||
SMManager::API_VERSION
|
SMManager::API_VERSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue