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