Skip to content

Commit

Permalink
リファクタ
Browse files Browse the repository at this point in the history
  • Loading branch information
shm11C3 committed Dec 1, 2024
1 parent 246af90 commit d81a6fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
38 changes: 17 additions & 21 deletions src-tauri/src/services/wmi_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,23 @@ pub async fn get_gpu_usage_by_device_and_engine(
// 正規表現で `engtype_xxx` の部分を抽出
let re = Regex::new(r"engtype_(\w+)").unwrap();

for engine in results.iter() {
if let Some(captures) = re.captures(&engine.name) {
if let Some(engine_name) = captures.get(1) {
if engine_name.as_str() == engine_type {
if let Some(load) = engine.utilization_percentage {
return Ok(load as f32 / 100.0);
} else {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("No usage data available for engine type: {}", engine_type),
)));
}
}
}
}
}

Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("No GPU engine found: engine_type: {}", engine_type,),
)))
results
.iter()
.find_map(|engine| {
re.captures(&engine.name)
.and_then(|captures| captures.get(1))
.filter(|engine_name| engine_name.as_str() == engine_type)
.and_then(|_| {
engine
.utilization_percentage
.map(|load| load as f32 / 100.0)
})
})
.ok_or_else(|| {
let message = format!("No usage data available for engine type: {}", engine_type);
Box::new(std::io::Error::new(std::io::ErrorKind::NotFound, message))
as Box<dyn Error>
})
}

///
Expand Down
2 changes: 1 addition & 1 deletion src/rspc/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async getBackgroundImages() : Promise<Result<BackgroundImage[], string>> {
*
* ### TODO
* - JsImage https://docs.rs/tauri/2.1.1/tauri/image/enum.JsImage.html を使用する
* -
* - specta での型定義が難しかったため一旦 Base64 で実装
*
*
*/
Expand Down

0 comments on commit d81a6fc

Please sign in to comment.