mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix: use webview's resources table (#1191)
* fix: use webview's resources table * fix clipboard into_img usage * fix mobile
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"fs": "patch"
|
||||
"http": "patch"
|
||||
"updater": "patch"
|
||||
"clipboard-manager": "patch"
|
||||
---
|
||||
|
||||
Internally use the webview scoped resources table instead of the app one, so other webviews can't access other webviews resources.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"fs": patch
|
||||
"http": patch
|
||||
"updater": patch
|
||||
"clipboard-manager": patch
|
||||
---
|
||||
|
||||
Update for tauri 2.0.0-beta.15.
|
||||
Generated
+15
-14
@@ -5992,14 +5992,15 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-beta.14"
|
||||
version = "2.0.0-beta.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a50fb0bdb687486415224f8be47c78993e9f3ea575ee0d5177c90d0c71842f4a"
|
||||
checksum = "cd0aba659957a3f1f1666acbf17723e8d41dcc177539bf1adbe55305f5d7118a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"cocoa 0.25.0",
|
||||
"dirs-next",
|
||||
"dunce",
|
||||
"embed_plist",
|
||||
"futures-util",
|
||||
"getrandom 0.2.12",
|
||||
@@ -6043,9 +6044,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-build"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82a46303cc4bce0b17ad95965cbd8326e3511b9d2cb6fb13a4a4c98a11b0dcaf"
|
||||
checksum = "33de24aabe2b9c340d67005800cb6dd40aac5283126a42896fc8eec0b87cbe45"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
@@ -6067,9 +6068,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-codegen"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1665f6a986842061a67cb9dcbe2fa27076c1a616f6525fc06de9d6d52838d63"
|
||||
checksum = "9d1d211268a9590bbf75cc85b47208f59b447626c76396256e12479ac7df6c8b"
|
||||
dependencies = [
|
||||
"base64 0.22.0",
|
||||
"brotli",
|
||||
@@ -6094,9 +6095,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-macros"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0c1558fc42cc2a1735cfd5edb2954c735d4516f8ba31c58b7180ba8a2bc18de"
|
||||
checksum = "b096f63f2724a1280ae0f5a34d0731de18ca18305e2ef6e5e9a39bb2710e8a85"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -6571,9 +6572,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "612e05de1382575b32b5220b546861256f630f37ac64c29cab252592861b9bd4"
|
||||
checksum = "96c957749c40db7999959f379f799db095f2248a80bdbb13d8c078f6c299240e"
|
||||
dependencies = [
|
||||
"dpi",
|
||||
"gtk",
|
||||
@@ -6590,9 +6591,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f73672897b5396cb05c2f21b12b66ecfd4b51fae619dd35387467660d6c00fb"
|
||||
checksum = "6b937adb1cf3fa0457928ace959ca3fc1a85ddd69f56b124682d40f3e5683e60"
|
||||
dependencies = [
|
||||
"cocoa 0.25.0",
|
||||
"gtk",
|
||||
@@ -6614,9 +6615,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-utils"
|
||||
version = "2.0.0-beta.11"
|
||||
version = "2.0.0-beta.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a148adf8077e1891c8b7d1c2be90c1c8eb8c7a071c35bb8edbdfe7cd9d8e23c"
|
||||
checksum = "760ac613d7f0de95067bcbcbcea175fe1df88fc4ab59c7f0b2cc2d01dc16a199"
|
||||
dependencies = [
|
||||
"aes-gcm 0.10.3",
|
||||
"brotli",
|
||||
|
||||
@@ -5983,6 +5983,13 @@
|
||||
"webview:allow-set-webview-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "webview:allow-set-webview-zoom -> Enables the set_webview_zoom command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"webview:allow-set-webview-zoom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "webview:allow-webview-close -> Enables the webview_close command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -6060,6 +6067,13 @@
|
||||
"webview:deny-set-webview-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "webview:deny-set-webview-zoom -> Denies the set_webview_zoom command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"webview:deny-set-webview-zoom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "webview:deny-webview-close -> Denies the webview_close command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use tauri::{command, AppHandle, Manager, ResourceId, Runtime, State};
|
||||
use tauri::{command, AppHandle, Manager, ResourceId, Runtime, State, Webview};
|
||||
|
||||
use crate::{ClipKind, Clipboard, ClipboardContents, Result};
|
||||
|
||||
@@ -17,11 +17,12 @@ pub(crate) async fn write_text<R: Runtime>(
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn write_image<R: Runtime>(
|
||||
_app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
clipboard: State<'_, Clipboard<R>>,
|
||||
data: ClipKind,
|
||||
) -> Result<()> {
|
||||
clipboard.write_image(data)
|
||||
let resources_table = webview.resources_table();
|
||||
clipboard.write_image_inner(data, &resources_table)
|
||||
}
|
||||
|
||||
#[command]
|
||||
@@ -34,11 +35,11 @@ pub(crate) async fn read_text<R: Runtime>(
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn read_image<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
clipboard: State<'_, Clipboard<R>>,
|
||||
) -> Result<ResourceId> {
|
||||
let image = clipboard.read_image()?.to_owned();
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
let rid = resources_table.add(image);
|
||||
Ok(rid)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use arboard::ImageData;
|
||||
use image::ImageEncoder;
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};
|
||||
use tauri::{image::Image, plugin::PluginApi, AppHandle, Manager, ResourceTable, Runtime};
|
||||
|
||||
use crate::models::*;
|
||||
|
||||
@@ -39,11 +39,15 @@ impl<R: Runtime> Clipboard<R> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
|
||||
pub(crate) fn write_image_inner(
|
||||
&self,
|
||||
kind: ClipKind,
|
||||
resources_table: &ResourceTable,
|
||||
) -> crate::Result<()> {
|
||||
match kind {
|
||||
ClipKind::Image { image, .. } => match &self.clipboard {
|
||||
Ok(clipboard) => {
|
||||
let image = image.into_img(&self.app)?;
|
||||
let image = image.into_img(resources_table)?;
|
||||
clipboard
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -60,6 +64,11 @@ impl<R: Runtime> Clipboard<R> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
|
||||
let resources_table = self.app.resources_table();
|
||||
self.write_image_inner(kind, &resources_table)
|
||||
}
|
||||
|
||||
pub fn read_text(&self) -> crate::Result<ClipboardContents> {
|
||||
match &self.clipboard {
|
||||
Ok(clipboard) => {
|
||||
|
||||
@@ -37,6 +37,16 @@ impl<R: Runtime> Clipboard<R> {
|
||||
self.0.run_mobile_plugin("write", kind).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub(crate) fn write_image_inner(
|
||||
&self,
|
||||
kind: ClipKind,
|
||||
resources_table: &tauri::ResourceTable,
|
||||
) -> crate::Result<()> {
|
||||
Err(crate::Error::Clipboard(
|
||||
"Unsupported on this platform".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn write_image(&self, kind: ClipKind) -> crate::Result<()> {
|
||||
Err(crate::Error::Clipboard(
|
||||
"Unsupported on this platform".to_string(),
|
||||
|
||||
@@ -8,7 +8,6 @@ pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
|
||||
+55
-55
@@ -9,7 +9,7 @@ use tauri::{
|
||||
ipc::{CommandScope, GlobalScope},
|
||||
path::{BaseDirectory, SafePathBuf},
|
||||
utils::config::FsScope,
|
||||
AppHandle, Manager, Resource, ResourceId, Runtime,
|
||||
Manager, Resource, ResourceId, Runtime, Webview,
|
||||
};
|
||||
|
||||
use std::{
|
||||
@@ -72,14 +72,14 @@ pub struct BaseOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<ResourceId> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -91,7 +91,7 @@ pub fn create<R: Runtime>(
|
||||
resolved_path.display()
|
||||
)
|
||||
})?;
|
||||
let rid = app.resources_table().add(StdFileResource::new(file));
|
||||
let rid = webview.resources_table().add(StdFileResource::new(file));
|
||||
Ok(rid)
|
||||
}
|
||||
|
||||
@@ -122,14 +122,14 @@ fn default_true() -> bool {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn open<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<OpenOptions>,
|
||||
) -> CommandResult<ResourceId> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -164,14 +164,14 @@ pub fn open<R: Runtime>(
|
||||
)
|
||||
})?;
|
||||
|
||||
let rid = app.resources_table().add(StdFileResource::new(file));
|
||||
let rid = webview.resources_table().add(StdFileResource::new(file));
|
||||
|
||||
Ok(rid)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn close<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> CommandResult<()> {
|
||||
app.resources_table().close(rid).map_err(Into::into)
|
||||
pub fn close<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> CommandResult<()> {
|
||||
webview.resources_table().close(rid).map_err(Into::into)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -183,7 +183,7 @@ pub struct CopyFileOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn copy_file<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
from_path: SafePathBuf,
|
||||
@@ -191,14 +191,14 @@ pub fn copy_file<R: Runtime>(
|
||||
options: Option<CopyFileOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_from_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
from_path,
|
||||
options.as_ref().and_then(|o| o.from_path_base_dir),
|
||||
)?;
|
||||
let resolved_to_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
to_path,
|
||||
@@ -225,14 +225,14 @@ pub struct MkdirOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn mkdir<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<MkdirOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -292,14 +292,14 @@ fn read_dir_inner<P: AsRef<Path>>(path: P) -> crate::Result<Vec<DirEntry>> {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_dir<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<Vec<DirEntry>> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -318,12 +318,12 @@ pub fn read_dir<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
len: u32,
|
||||
) -> CommandResult<(Vec<u8>, usize)> {
|
||||
let mut data = vec![0; len as usize];
|
||||
let file = app.resources_table().get::<StdFileResource>(rid)?;
|
||||
let file = webview.resources_table().get::<StdFileResource>(rid)?;
|
||||
let nread = StdFileResource::with_lock(&file, |mut file| file.read(&mut data))
|
||||
.map_err(|e| format!("faied to read bytes from file with error: {e}"))?;
|
||||
Ok((data, nread))
|
||||
@@ -331,14 +331,14 @@ pub fn read<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_file<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<Vec<u8>> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -356,14 +356,14 @@ pub fn read_file<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_text_file<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<String> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -381,7 +381,7 @@ pub fn read_text_file<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_text_file_lines<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
@@ -390,7 +390,7 @@ pub fn read_text_file_lines<R: Runtime>(
|
||||
use std::io::BufRead;
|
||||
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -405,17 +405,17 @@ pub fn read_text_file_lines<R: Runtime>(
|
||||
})?;
|
||||
|
||||
let lines = BufReader::new(file).lines();
|
||||
let rid = app.resources_table().add(StdLinesResource::new(lines));
|
||||
let rid = webview.resources_table().add(StdLinesResource::new(lines));
|
||||
|
||||
Ok(rid)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_text_file_lines_next<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
) -> CommandResult<(Option<String>, bool)> {
|
||||
let mut resource_table = app.resources_table();
|
||||
let mut resource_table = webview.resources_table();
|
||||
let lines = resource_table.get::<StdLinesResource>(rid)?;
|
||||
|
||||
let ret = StdLinesResource::with_lock(&lines, |lines| {
|
||||
@@ -437,14 +437,14 @@ pub struct RemoveOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn remove<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<RemoveOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -505,7 +505,7 @@ pub struct RenameOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn rename<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
old_path: SafePathBuf,
|
||||
@@ -513,14 +513,14 @@ pub fn rename<R: Runtime>(
|
||||
options: Option<RenameOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_old_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
old_path,
|
||||
options.as_ref().and_then(|o| o.old_path_base_dir),
|
||||
)?;
|
||||
let resolved_new_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
new_path,
|
||||
@@ -547,13 +547,13 @@ pub enum SeekMode {
|
||||
|
||||
#[tauri::command]
|
||||
pub fn seek<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
offset: i64,
|
||||
whence: SeekMode,
|
||||
) -> CommandResult<u64> {
|
||||
use std::io::{Seek, SeekFrom};
|
||||
let file = app.resources_table().get::<StdFileResource>(rid)?;
|
||||
let file = webview.resources_table().get::<StdFileResource>(rid)?;
|
||||
StdFileResource::with_lock(&file, |mut file| {
|
||||
file.seek(match whence {
|
||||
SeekMode::Start => SeekFrom::Start(offset as u64),
|
||||
@@ -567,14 +567,14 @@ pub fn seek<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn stat<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<FileInfo> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -591,14 +591,14 @@ pub fn stat<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn lstat<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<FileInfo> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -614,8 +614,8 @@ pub fn lstat<R: Runtime>(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn fstat<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> CommandResult<FileInfo> {
|
||||
let file = app.resources_table().get::<StdFileResource>(rid)?;
|
||||
pub fn fstat<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> CommandResult<FileInfo> {
|
||||
let file = webview.resources_table().get::<StdFileResource>(rid)?;
|
||||
let metadata = StdFileResource::with_lock(&file, |file| file.metadata())
|
||||
.map_err(|e| format!("failed to get metadata of file with error: {e}"))?;
|
||||
Ok(get_stat(metadata))
|
||||
@@ -623,7 +623,7 @@ pub fn fstat<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> CommandResult<Fi
|
||||
|
||||
#[tauri::command]
|
||||
pub fn truncate<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
@@ -631,7 +631,7 @@ pub fn truncate<R: Runtime>(
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -658,11 +658,11 @@ pub fn truncate<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn ftruncate<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
len: Option<u64>,
|
||||
) -> CommandResult<()> {
|
||||
let file = app.resources_table().get::<StdFileResource>(rid)?;
|
||||
let file = webview.resources_table().get::<StdFileResource>(rid)?;
|
||||
StdFileResource::with_lock(&file, |file| file.set_len(len.unwrap_or(0)))
|
||||
.map_err(|e| format!("failed to truncate file with error: {e}"))
|
||||
.map_err(Into::into)
|
||||
@@ -670,11 +670,11 @@ pub fn ftruncate<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn write<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
data: Vec<u8>,
|
||||
) -> CommandResult<usize> {
|
||||
let file = app.resources_table().get::<StdFileResource>(rid)?;
|
||||
let file = webview.resources_table().get::<StdFileResource>(rid)?;
|
||||
StdFileResource::with_lock(&file, |mut file| file.write(&data))
|
||||
.map_err(|e| format!("failed to write bytes to file with error: {e}"))
|
||||
.map_err(Into::into)
|
||||
@@ -700,7 +700,7 @@ fn default_create_value() -> bool {
|
||||
}
|
||||
|
||||
fn write_file_inner<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: &GlobalScope<Entry>,
|
||||
command_scope: &CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
@@ -708,7 +708,7 @@ fn write_file_inner<R: Runtime>(
|
||||
options: Option<WriteFileOptions>,
|
||||
) -> CommandResult<()> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
global_scope,
|
||||
command_scope,
|
||||
path,
|
||||
@@ -753,19 +753,19 @@ fn write_file_inner<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn write_file<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
data: Vec<u8>,
|
||||
options: Option<WriteFileOptions>,
|
||||
) -> CommandResult<()> {
|
||||
write_file_inner(app, &global_scope, &command_scope, path, &data, options)
|
||||
write_file_inner(webview, &global_scope, &command_scope, path, &data, options)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn write_text_file<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
@@ -773,7 +773,7 @@ pub fn write_text_file<R: Runtime>(
|
||||
options: Option<WriteFileOptions>,
|
||||
) -> CommandResult<()> {
|
||||
write_file_inner(
|
||||
app,
|
||||
webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -784,14 +784,14 @@ pub fn write_text_file<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub fn exists<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
command_scope: CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
options: Option<BaseOptions>,
|
||||
) -> CommandResult<bool> {
|
||||
let resolved_path = resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -801,7 +801,7 @@ pub fn exists<R: Runtime>(
|
||||
}
|
||||
|
||||
pub fn resolve_path<R: Runtime>(
|
||||
app: &AppHandle<R>,
|
||||
app: &Webview<R>,
|
||||
global_scope: &GlobalScope<Entry>,
|
||||
command_scope: &CommandScope<Entry>,
|
||||
path: SafePathBuf,
|
||||
|
||||
@@ -8,7 +8,7 @@ use serde::Deserialize;
|
||||
use tauri::{
|
||||
ipc::{Channel, CommandScope, GlobalScope},
|
||||
path::{BaseDirectory, SafePathBuf},
|
||||
AppHandle, Manager, Resource, ResourceId, Runtime,
|
||||
Manager, Resource, ResourceId, Runtime, Webview,
|
||||
};
|
||||
|
||||
use std::{
|
||||
@@ -82,7 +82,7 @@ pub struct WatchOptions {
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn watch<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
paths: Vec<SafePathBuf>,
|
||||
options: WatchOptions,
|
||||
on_event: Channel,
|
||||
@@ -92,7 +92,7 @@ pub async fn watch<R: Runtime>(
|
||||
let mut resolved_paths = Vec::with_capacity(paths.capacity());
|
||||
for path in paths {
|
||||
resolved_paths.push(resolve_path(
|
||||
&app,
|
||||
&webview,
|
||||
&global_scope,
|
||||
&command_scope,
|
||||
path,
|
||||
@@ -124,7 +124,7 @@ pub async fn watch<R: Runtime>(
|
||||
WatcherKind::Watcher(watcher)
|
||||
};
|
||||
|
||||
let rid = app
|
||||
let rid = webview
|
||||
.resources_table()
|
||||
.add(WatcherResource::new(kind, resolved_paths));
|
||||
|
||||
@@ -132,8 +132,8 @@ pub async fn watch<R: Runtime>(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn unwatch<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> CommandResult<()> {
|
||||
let watcher = app.resources_table().take::<WatcherResource>(rid)?;
|
||||
pub async fn unwatch<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> CommandResult<()> {
|
||||
let watcher = webview.resources_table().take::<WatcherResource>(rid)?;
|
||||
WatcherResource::with_lock(&watcher, |watcher| {
|
||||
match &mut watcher.kind {
|
||||
WatcherKind::Debouncer(ref mut debouncer) => {
|
||||
|
||||
@@ -11,7 +11,7 @@ use tauri::{
|
||||
async_runtime::Mutex,
|
||||
command,
|
||||
ipc::{CommandScope, GlobalScope},
|
||||
AppHandle, Manager, ResourceId, Runtime,
|
||||
Manager, ResourceId, Runtime, Webview,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -137,7 +137,7 @@ fn attach_proxy(
|
||||
|
||||
#[command]
|
||||
pub async fn fetch<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
client_config: ClientConfig,
|
||||
command_scope: CommandScope<Entry>,
|
||||
global_scope: GlobalScope<Entry>,
|
||||
@@ -249,7 +249,7 @@ pub async fn fetch<R: Runtime>(
|
||||
}
|
||||
|
||||
let fut = async move { Ok(request.send().await.map_err(Into::into)) };
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
let rid = resources_table.add(FetchRequest::new(Box::pin(fut)));
|
||||
|
||||
Ok(rid)
|
||||
@@ -270,7 +270,7 @@ pub async fn fetch<R: Runtime>(
|
||||
.body(reqwest::Body::from(body))?;
|
||||
|
||||
let fut = async move { Ok(Ok(reqwest::Response::from(response))) };
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
let rid = resources_table.add(FetchRequest::new(Box::pin(fut)));
|
||||
Ok(rid)
|
||||
}
|
||||
@@ -279,9 +279,9 @@ pub async fn fetch<R: Runtime>(
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub async fn fetch_cancel<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> crate::Result<()> {
|
||||
pub async fn fetch_cancel<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> crate::Result<()> {
|
||||
let req = {
|
||||
let resources_table = app.resources_table();
|
||||
let resources_table = webview.resources_table();
|
||||
resources_table.get::<FetchRequest>(rid)?
|
||||
};
|
||||
let mut req = req.0.lock().await;
|
||||
@@ -292,11 +292,11 @@ pub async fn fetch_cancel<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> cra
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn fetch_send<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
) -> crate::Result<FetchResponse> {
|
||||
let req = {
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
resources_table.take::<FetchRequest>(rid)?
|
||||
};
|
||||
|
||||
@@ -315,7 +315,7 @@ pub async fn fetch_send<R: Runtime>(
|
||||
));
|
||||
}
|
||||
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
let rid = resources_table.add(ReqwestResponse(res));
|
||||
|
||||
Ok(FetchResponse {
|
||||
@@ -329,11 +329,11 @@ pub async fn fetch_send<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn fetch_read_body<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
) -> crate::Result<tauri::ipc::Response> {
|
||||
let res = {
|
||||
let mut resources_table = app.resources_table();
|
||||
let mut resources_table = webview.resources_table();
|
||||
resources_table.take::<ReqwestResponse>(rid)?
|
||||
};
|
||||
let res = Arc::into_inner(res).unwrap().0;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::{Result, Update, UpdaterExt};
|
||||
|
||||
use serde::Serialize;
|
||||
use tauri::{ipc::Channel, AppHandle, Manager, ResourceId, Runtime};
|
||||
use tauri::{ipc::Channel, Manager, ResourceId, Runtime, Webview};
|
||||
|
||||
use std::time::Duration;
|
||||
use url::Url;
|
||||
@@ -37,13 +37,13 @@ pub(crate) struct Metadata {
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn check<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
headers: Option<Vec<(String, String)>>,
|
||||
timeout: Option<u64>,
|
||||
proxy: Option<String>,
|
||||
target: Option<String>,
|
||||
) -> Result<Metadata> {
|
||||
let mut builder = app.updater_builder();
|
||||
let mut builder = webview.updater_builder();
|
||||
if let Some(headers) = headers {
|
||||
for (k, v) in headers {
|
||||
builder = builder.header(k, v)?;
|
||||
@@ -69,7 +69,7 @@ pub(crate) async fn check<R: Runtime>(
|
||||
metadata.version = update.version.clone();
|
||||
metadata.date = update.date.map(|d| d.to_string());
|
||||
metadata.body = update.body.clone();
|
||||
metadata.rid = Some(app.resources_table().add(update));
|
||||
metadata.rid = Some(webview.resources_table().add(update));
|
||||
}
|
||||
|
||||
Ok(metadata)
|
||||
@@ -77,11 +77,11 @@ pub(crate) async fn check<R: Runtime>(
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn download_and_install<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
on_event: Channel,
|
||||
) -> Result<()> {
|
||||
let update = app.resources_table().get::<Update>(rid)?;
|
||||
let update = webview.resources_table().get::<Update>(rid)?;
|
||||
|
||||
let mut first_chunk = true;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"identifier": "com.tauri.dev",
|
||||
"build": {
|
||||
"devUrl": "http://localhost:5173/",
|
||||
"frontendDist": "../build",
|
||||
"frontendDist": "../dist",
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"beforeBuildCommand": "pnpm build"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user