From 3ad1721c283e5ca17b19edb2ae08663ecce39d99 Mon Sep 17 00:00:00 2001 From: fan xia Date: Thu, 19 Oct 2023 13:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon/src/clipboard/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addon/src/clipboard/mod.rs b/addon/src/clipboard/mod.rs index 77aa180..2acd2b8 100644 --- a/addon/src/clipboard/mod.rs +++ b/addon/src/clipboard/mod.rs @@ -1,6 +1,5 @@ use clipboard_files; use copypasta::{ClipboardContext, ClipboardProvider}; -use napi::Result; // use std::{ // path::PathBuf, @@ -94,25 +93,25 @@ pub struct ClipBoardContentJson { // 获取剪切板文件或者文本 #[napi] -pub fn get_clipboard_content() -> Result> { +pub fn get_clipboard_content() -> Option { let files = clipboard_files::read(); let mut ctx = ClipboardContext::new().unwrap(); match files { - Ok(f) => Ok(Some(ClipBoardContentJson { + Ok(f) => Some(ClipBoardContentJson { r#type: "file".to_string(), content: f .into_iter() .map(|c| c.to_str().unwrap().to_string()) .collect::>(), - })), + }), Err(_) => { let content = ctx.get_contents(); match content { - Ok(text) => Ok(Some(ClipBoardContentJson { + Ok(text) => Some(ClipBoardContentJson { r#type: "text".to_string(), content: vec![text], - })), - Err(_) => Ok(None), + }), + Err(_) => None, } } }