Comments (5)
@StringKe
tauri 中,应该可以保存到状态对象中吧,我刚刚写了个 demo 测试了一下,你可以看一下,不过我会思考能不能实现 copy ,目前无法保证这个对象在所有平台都线程安全。
https://github.com/ChurchTao/clipboard-rs-tauri-demo
from clipboard-rs.
我是这样写的 tauri 2 beta,还是无法移动它
https://github.com/stringke-org/qingmu/blob/main/src-tauri/src/commands.rs#L26
from clipboard-rs.
我是这样写的 tauri 2 beta,还是无法移动它
https://github.com/stringke-org/qingmu/blob/main/src-tauri/src/commands.rs#L26
@StringKe 我知道你的困惑了,你的代码中:
let clipboard_context = &state.0.lock().unwrap().clipboard_context;
这样做是试图把 对象从 state 中 move 出来,这是移动所有权的做法,这里 move 出来了,state 就会丢失所有权,这在 rust 中是不允许的,你可以改为,使用 &
创建一个不可变引用,在函数 get_clipboard_text
中这个不可变引用足以完成所有工作,并且不会额外内存开销,state 也不会因此丢失所有权。
示例代码如下:
#[tauri::command]
pub fn get_clipboard_text(state: tauri::State<'_, AppState>) -> Result<String> {
// 无法移动
let clipboard_context = &state.0.lock().unwrap().clipboard_context;
match clipboard_context.get_text() {
Ok(str) => {
if str.is_empty() {
Err(Error::from(anyhow::anyhow!("Clipboard text is empty")))
} else {
Ok(str)
}
}
Err(_) => Err(Error::from(anyhow::anyhow!("Failed to get clipboard text"))),
}
}
from clipboard-rs.
具体看下这个
https://kaisery.github.io/trpl-zh-cn/ch04-02-references-and-borrowing.html
from clipboard-rs.
应该没问题了吧,有问题重新打开这个issue即可
from clipboard-rs.
Related Issues (20)
- `get_files` Segmentation Fault when there is no files on clipboard HOT 1
- Error: `The image format could not be determined` on Win11 HOT 2
- Bug: Cannot paste after writing image to clipboard (on Windows) HOT 2
- Bug: No transparent background for clipboard image read on Windows HOT 1
- Bug: Cannot read clipboard image on MacOS for screenshots taken by certain apps HOT 3
- `set_html()` doesn't update text. HOT 1
- 当写入html时,在Windows上长度似乎是有限制的,并且会被自动截断。截断的长度不固定 HOT 1
- 如何计算图像的哈希值? HOT 6
- 如何获取复制内容的 app 来源 HOT 9
- 在微信选中文字就会触发 `on_clipboard_change` HOT 4
- 重新复制 HTML 时,部分软件粘贴失效 HOT 15
- 如何触发富文本的复制 HOT 17
- linux 下 get_files()一直拿不到结果 HOT 8
- [bug] windows 系统 html 写入剪切板的问题 HOT 12
- 设置剪切板时图片失真,像素偏移 HOT 16
- 部分应用中复制时会触发两次on_clipboard_change HOT 4
- [bug] windows 复制内容频繁崩溃 HOT 17
- [bug] windows 系统复制 wps excel 单元格时 html 内容有问题!
- Does the get_image Method Support Windows? HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clipboard-rs.