mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-27 11:56:05 +02:00
e3d41f4011
* fix: use webview's resources table * fix clipboard into_img usage * fix mobile
63 lines
1.5 KiB
Rust
63 lines
1.5 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use tauri::{command, AppHandle, Manager, ResourceId, Runtime, State, Webview};
|
|
|
|
use crate::{ClipKind, Clipboard, ClipboardContents, Result};
|
|
|
|
#[command]
|
|
pub(crate) async fn write_text<R: Runtime>(
|
|
_app: AppHandle<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
data: ClipKind,
|
|
) -> Result<()> {
|
|
clipboard.write_text(data)
|
|
}
|
|
|
|
#[command]
|
|
pub(crate) async fn write_image<R: Runtime>(
|
|
webview: Webview<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
data: ClipKind,
|
|
) -> Result<()> {
|
|
let resources_table = webview.resources_table();
|
|
clipboard.write_image_inner(data, &resources_table)
|
|
}
|
|
|
|
#[command]
|
|
pub(crate) async fn read_text<R: Runtime>(
|
|
_app: AppHandle<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
) -> Result<ClipboardContents> {
|
|
clipboard.read_text()
|
|
}
|
|
|
|
#[command]
|
|
pub(crate) async fn read_image<R: Runtime>(
|
|
webview: Webview<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
) -> Result<ResourceId> {
|
|
let image = clipboard.read_image()?.to_owned();
|
|
let mut resources_table = webview.resources_table();
|
|
let rid = resources_table.add(image);
|
|
Ok(rid)
|
|
}
|
|
|
|
#[command]
|
|
pub(crate) async fn write_html<R: Runtime>(
|
|
_app: AppHandle<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
data: ClipKind,
|
|
) -> Result<()> {
|
|
clipboard.write_html(data)
|
|
}
|
|
|
|
#[command]
|
|
pub(crate) async fn clear<R: Runtime>(
|
|
_app: AppHandle<R>,
|
|
clipboard: State<'_, Clipboard<R>>,
|
|
) -> Result<()> {
|
|
clipboard.clear()
|
|
}
|