Skip to content

Commit e3d41f4

Browse files
authored
fix: use webview's resources table (#1191)
* fix: use webview's resources table * fix clipboard into_img usage * fix mobile
1 parent 8638740 commit e3d41f4

13 files changed

Lines changed: 152 additions & 102 deletions

File tree

.changes/scoped-resources-table.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"fs": "patch"
3+
"http": "patch"
4+
"updater": "patch"
5+
"clipboard-manager": "patch"
6+
---
7+
8+
Internally use the webview scoped resources table instead of the app one, so other webviews can't access other webviews resources.

.changes/tauri-beta-15.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"fs": patch
3+
"http": patch
4+
"updater": patch
5+
"clipboard-manager": patch
6+
---
7+
8+
Update for tauri 2.0.0-beta.15.

Cargo.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/gen/schemas/desktop-schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5983,6 +5983,13 @@
59835983
"webview:allow-set-webview-size"
59845984
]
59855985
},
5986+
{
5987+
"description": "webview:allow-set-webview-zoom -> Enables the set_webview_zoom command without any pre-configured scope.",
5988+
"type": "string",
5989+
"enum": [
5990+
"webview:allow-set-webview-zoom"
5991+
]
5992+
},
59865993
{
59875994
"description": "webview:allow-webview-close -> Enables the webview_close command without any pre-configured scope.",
59885995
"type": "string",
@@ -6060,6 +6067,13 @@
60606067
"webview:deny-set-webview-size"
60616068
]
60626069
},
6070+
{
6071+
"description": "webview:deny-set-webview-zoom -> Denies the set_webview_zoom command without any pre-configured scope.",
6072+
"type": "string",
6073+
"enum": [
6074+
"webview:deny-set-webview-zoom"
6075+
]
6076+
},
60636077
{
60646078
"description": "webview:deny-webview-close -> Denies the webview_close command without any pre-configured scope.",
60656079
"type": "string",

plugins/clipboard-manager/src/commands.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use tauri::{command, AppHandle, Manager, ResourceId, Runtime, State};
5+
use tauri::{command, AppHandle, Manager, ResourceId, Runtime, State, Webview};
66

77
use crate::{ClipKind, Clipboard, ClipboardContents, Result};
88

@@ -17,11 +17,12 @@ pub(crate) async fn write_text<R: Runtime>(
1717

1818
#[command]
1919
pub(crate) async fn write_image<R: Runtime>(
20-
_app: AppHandle<R>,
20+
webview: Webview<R>,
2121
clipboard: State<'_, Clipboard<R>>,
2222
data: ClipKind,
2323
) -> Result<()> {
24-
clipboard.write_image(data)
24+
let resources_table = webview.resources_table();
25+
clipboard.write_image_inner(data, &resources_table)
2526
}
2627

2728
#[command]
@@ -34,11 +35,11 @@ pub(crate) async fn read_text<R: Runtime>(
3435

3536
#[command]
3637
pub(crate) async fn read_image<R: Runtime>(
37-
app: AppHandle<R>,
38+
webview: Webview<R>,
3839
clipboard: State<'_, Clipboard<R>>,
3940
) -> Result<ResourceId> {
4041
let image = clipboard.read_image()?.to_owned();
41-
let mut resources_table = app.resources_table();
42+
let mut resources_table = webview.resources_table();
4243
let rid = resources_table.add(image);
4344
Ok(rid)
4445
}

plugins/clipboard-manager/src/desktop.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use arboard::ImageData;
66
use image::ImageEncoder;
77
use serde::de::DeserializeOwned;
8-
use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};
8+
use tauri::{image::Image, plugin::PluginApi, AppHandle, Manager, ResourceTable, Runtime};
99

1010
use crate::models::*;
1111

@@ -39,11 +39,15 @@ impl<R: Runtime> Clipboard<R> {
3939
}
4040
}
4141

42-
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
42+
pub(crate) fn write_image_inner(
43+
&self,
44+
kind: ClipKind,
45+
resources_table: &ResourceTable,
46+
) -> crate::Result<()> {
4347
match kind {
4448
ClipKind::Image { image, .. } => match &self.clipboard {
4549
Ok(clipboard) => {
46-
let image = image.into_img(&self.app)?;
50+
let image = image.into_img(resources_table)?;
4751
clipboard
4852
.lock()
4953
.unwrap()
@@ -60,6 +64,11 @@ impl<R: Runtime> Clipboard<R> {
6064
}
6165
}
6266

67+
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
68+
let resources_table = self.app.resources_table();
69+
self.write_image_inner(kind, &resources_table)
70+
}
71+
6372
pub fn read_text(&self) -> crate::Result<ClipboardContents> {
6473
match &self.clipboard {
6574
Ok(clipboard) => {

plugins/clipboard-manager/src/mobile.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ impl<R: Runtime> Clipboard<R> {
3737
self.0.run_mobile_plugin("write", kind).map_err(Into::into)
3838
}
3939

40+
pub(crate) fn write_image_inner(
41+
&self,
42+
kind: ClipKind,
43+
resources_table: &tauri::ResourceTable,
44+
) -> crate::Result<()> {
45+
Err(crate::Error::Clipboard(
46+
"Unsupported on this platform".to_string(),
47+
))
48+
}
49+
4050
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
4151
Err(crate::Error::Clipboard(
4252
"Unsupported on this platform".to_string(),

plugins/deep-link/examples/app/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pnpm-debug.log*
88
lerna-debug.log*
99

1010
node_modules
11-
dist
1211
dist-ssr
1312
*.local
1413

0 commit comments

Comments
 (0)