Refactor: Fix clippy warnings and introduce AppError
This commit is contained in:
1 parent
3add6c3d31
commit
4e1a633dbd
13 files changed
+129
-103
No files matched your search
@@ -32,25 +32,21 @@ impl McpTool for WriteClipboardHandler {
|
||||
let mut msgs = Vec::new();
|
||||
|
||||
// Handle clipboard_win formats (text, html, files)
|
||||
if tool_args.text.is_some() || tool_args.html.is_some() || tool_args.files.is_some() {
|
||||
if let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Some(text) = &tool_args.text {
|
||||
if clipboard_win::set_clipboard_string(text).is_ok() {
|
||||
if (tool_args.text.is_some() || tool_args.html.is_some() || tool_args.files.is_some())
|
||||
&& let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Some(text) = &tool_args.text
|
||||
&& clipboard_win::set_clipboard_string(text).is_ok() {
|
||||
msgs.push("Wrote text");
|
||||
}
|
||||
}
|
||||
if let Some(html) = &tool_args.html {
|
||||
if formats::Html::new().unwrap().write_clipboard(html).is_ok() {
|
||||
if let Some(html) = &tool_args.html
|
||||
&& formats::Html::new().unwrap().write_clipboard(html).is_ok() {
|
||||
msgs.push("Wrote HTML");
|
||||
}
|
||||
}
|
||||
if let Some(files) = &tool_args.files {
|
||||
if raw::set_file_list(files).is_ok() {
|
||||
if let Some(files) = &tool_args.files
|
||||
&& raw::set_file_list(files).is_ok() {
|
||||
msgs.push("Wrote FileList");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle arboard for image
|
||||
if let Some(image_path) = &tool_args.image_path {
|
||||
@@ -106,26 +102,23 @@ impl McpTool for ReadClipboardHandler {
|
||||
let mut out = serde_json::Map::new();
|
||||
|
||||
if let Ok(_clip) = Clipboard::new_attempts(3) {
|
||||
if let Ok(text) = get_clipboard::<String, _>(formats::Unicode) {
|
||||
if !text.trim().is_empty() {
|
||||
if let Ok(text) = get_clipboard::<String, _>(formats::Unicode)
|
||||
&& !text.trim().is_empty() {
|
||||
out.insert("text".into(), json!(text));
|
||||
}
|
||||
}
|
||||
if let Ok(html) = get_clipboard::<String, _>(formats::Html::new().unwrap()) {
|
||||
if !html.trim().is_empty() {
|
||||
if let Ok(html) = get_clipboard::<String, _>(formats::Html::new().unwrap())
|
||||
&& !html.trim().is_empty() {
|
||||
out.insert("html".into(), json!(html));
|
||||
}
|
||||
}
|
||||
if let Ok(files) = get_clipboard::<Vec<String>, _>(formats::FileList) {
|
||||
if !files.is_empty() {
|
||||
if let Ok(files) = get_clipboard::<Vec<String>, _>(formats::FileList)
|
||||
&& !files.is_empty() {
|
||||
out.insert("files".into(), json!(files));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mut clipboard) = arboard::Clipboard::new() {
|
||||
if let Ok(image_data) = clipboard.get_image() {
|
||||
if let Some(img) = ImageBuffer::<image::Rgba<u8>, _>::from_raw(
|
||||
if let Ok(mut clipboard) = arboard::Clipboard::new()
|
||||
&& let Ok(image_data) = clipboard.get_image()
|
||||
&& let Some(img) = ImageBuffer::<image::Rgba<u8>, _>::from_raw(
|
||||
image_data.width as u32,
|
||||
image_data.height as u32,
|
||||
image_data.bytes.into_owned(),
|
||||
@@ -152,8 +145,6 @@ impl McpTool for ReadClipboardHandler {
|
||||
out.insert("image_path".into(), json!(file_path.to_string_lossy().to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Value::Object(out))
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user