mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-14 14:27:48 +02:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e80626cf81 | |||
| 2e2fc8de69 | |||
| 85f8419682 | |||
| c60123093d | |||
| 38b5d37b54 | |||
| 8b1d821a37 | |||
| bfa87da848 |
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"fs-js": patch
|
||||
---
|
||||
|
||||
Fix `DebouncedEvent` type to correctly represent the actual type.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"deep-link": patch
|
||||
---
|
||||
|
||||
Fixes issue with tauri alpha.20.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"fs": "patch"
|
||||
"fs-js": "patch"
|
||||
---
|
||||
|
||||
Add `createNew` option for `writeFile` and `writeTextFile` to create the file if doesn't exist and fail if it does.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"fs": "patch"
|
||||
"fs-js": "patch"
|
||||
---
|
||||
|
||||
Truncate files when using `writeFile` and `writeTextFile` with `append: false`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"fs-js": "patch"
|
||||
---
|
||||
|
||||
Fix `invalid args id for command unwatch` error when trying to unwatch a previously watched file or directory.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"fs": "patch"
|
||||
"fs-js": "patch"
|
||||
---
|
||||
|
||||
Fix panic when using `writeFile` or `writeTextFile` without passing an option object.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"http": minor
|
||||
"http-js": minor
|
||||
---
|
||||
|
||||
Add `proxy` field to `fetch` options to configure proxy.
|
||||
@@ -16,6 +16,8 @@
|
||||
".changes/dialog-export-fileresponse.md",
|
||||
".changes/dialog-pin-rfd.md",
|
||||
".changes/dialog-return-result.md",
|
||||
".changes/fix-debounced-event-type.md",
|
||||
".changes/fix-deep-link-alpha-20.md",
|
||||
".changes/fix-docs-build.md",
|
||||
".changes/fix-emit-all-usage.md",
|
||||
".changes/fix-invoke-usage.md",
|
||||
@@ -23,14 +25,19 @@
|
||||
".changes/fix-permission-notification.md",
|
||||
".changes/fix-updater-macos.md",
|
||||
".changes/fix-window-state-api.md",
|
||||
".changes/fs-create-new.md",
|
||||
".changes/fs-exists-2nd-arg.md",
|
||||
".changes/fs-improve-error-message.md",
|
||||
".changes/fs-improved-apis.md",
|
||||
".changes/fs-scope-tauri.md",
|
||||
".changes/fs-trunacte-non-append.md",
|
||||
".changes/fs-unwtach-rid.md",
|
||||
".changes/fs-wiret-binary-file.md",
|
||||
".changes/fs-write-panic.md",
|
||||
".changes/global-shortcut-app-handle.md",
|
||||
".changes/http-multipart-refactor.md",
|
||||
".changes/http-plugin-refactor.md",
|
||||
".changes/http-proxy-config.md",
|
||||
".changes/http-remove-cmd-property.md",
|
||||
".changes/http-response.md",
|
||||
".changes/msrv-1.70.md",
|
||||
|
||||
Generated
+6
-6
@@ -230,7 +230,7 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "api"
|
||||
version = "2.0.0-alpha.9"
|
||||
version = "2.0.0-alpha.11"
|
||||
dependencies = [
|
||||
"log",
|
||||
"serde",
|
||||
@@ -5965,7 +5965,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-deep-link"
|
||||
version = "2.0.0-alpha.4"
|
||||
version = "2.0.0-alpha.5"
|
||||
dependencies = [
|
||||
"log",
|
||||
"serde",
|
||||
@@ -5978,7 +5978,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-dialog"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
dependencies = [
|
||||
"glib 0.16.9",
|
||||
"log",
|
||||
@@ -5994,7 +5994,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-fs"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"glob",
|
||||
@@ -6022,7 +6022,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-http"
|
||||
version = "2.0.0-alpha.7"
|
||||
version = "2.0.0-alpha.9"
|
||||
dependencies = [
|
||||
"data-url",
|
||||
"glob",
|
||||
@@ -6117,7 +6117,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-persisted-scope"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"bincode",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.9]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `fs-js@2.0.0-alpha.6`
|
||||
|
||||
## \[2.0.0-alpha.8]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `http-js@2.0.0-alpha.6`
|
||||
|
||||
## \[2.0.0-alpha.7]
|
||||
|
||||
### Dependencies
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "svelte-app",
|
||||
"private": true,
|
||||
"version": "2.0.0-alpha.7",
|
||||
"version": "2.0.0-alpha.9",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --clearScreen false",
|
||||
@@ -15,9 +15,9 @@
|
||||
"@tauri-apps/plugin-cli": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-clipboard-manager": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-dialog": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-fs": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-fs": "2.0.0-alpha.6",
|
||||
"@tauri-apps/plugin-global-shortcut": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-http": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-http": "2.0.0-alpha.6",
|
||||
"@tauri-apps/plugin-nfc": "2.0.0-alpha.0",
|
||||
"@tauri-apps/plugin-notification": "2.0.0-alpha.5",
|
||||
"@tauri-apps/plugin-os": "2.0.0-alpha.6",
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.11]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `fs@2.0.0-alpha.7`
|
||||
- Upgraded to `dialog@2.0.0-alpha.7`
|
||||
- Upgraded to `http@2.0.0-alpha.9`
|
||||
|
||||
## \[2.0.0-alpha.10]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `http@2.0.0-alpha.8`
|
||||
|
||||
## \[2.0.0-alpha.9]
|
||||
|
||||
### Dependencies
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "api"
|
||||
publish = false
|
||||
version = "2.0.0-alpha.9"
|
||||
version = "2.0.0-alpha.11"
|
||||
description = "An example Tauri Application showcasing the api"
|
||||
edition = "2021"
|
||||
rust-version = { workspace = true }
|
||||
@@ -20,10 +20,10 @@ serde = { workspace = true }
|
||||
tiny_http = "0.11"
|
||||
log = { workspace = true }
|
||||
tauri-plugin-log = { path = "../../../plugins/log", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-fs = { path = "../../../plugins/fs", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-fs = { path = "../../../plugins/fs", version = "2.0.0-alpha.7" }
|
||||
tauri-plugin-clipboard-manager = { path = "../../../plugins/clipboard-manager", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-http = { path = "../../../plugins/http", features = [ "multipart" ], version = "2.0.0-alpha.7" }
|
||||
tauri-plugin-dialog = { path = "../../../plugins/dialog", version = "2.0.0-alpha.7" }
|
||||
tauri-plugin-http = { path = "../../../plugins/http", features = [ "multipart" ], version = "2.0.0-alpha.9" }
|
||||
tauri-plugin-notification = { path = "../../../plugins/notification", version = "2.0.0-alpha.7", features = [ "windows7-compat" ] }
|
||||
tauri-plugin-os = { path = "../../../plugins/os", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-process = { path = "../../../plugins/process", version = "2.0.0-alpha.6" }
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.5]
|
||||
|
||||
- [`8b1d821`](https://github.com/tauri-apps/plugins-workspace/commit/8b1d821a375d66a61e06c78b7148e255855cfe1b)([#844](https://github.com/tauri-apps/plugins-workspace/pull/844)) Fixes issue with tauri alpha.20.
|
||||
|
||||
## \[2.0.0-alpha.4]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.13.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tauri-plugin-deep-link"
|
||||
version = "2.0.0-alpha.4"
|
||||
version = "2.0.0-alpha.5"
|
||||
description = "Set your Tauri application as the default handler for an URL"
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
|
||||
@@ -42,12 +42,7 @@ fn init_deep_link<R: Runtime, C: DeserializeOwned>(
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let payload = vec![url];
|
||||
app_handle.trigger_global(
|
||||
"deep-link://new-url",
|
||||
Some(serde_json::to_string(&payload).unwrap()),
|
||||
);
|
||||
let _ = app_handle.emit_all("deep-link://new-url", payload);
|
||||
let _ = app_handle.emit("deep-link://new-url", vec![url]);
|
||||
Ok(())
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.7]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `fs@2.0.0-alpha.7`
|
||||
|
||||
## \[2.0.0-alpha.5]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.13.
|
||||
@@ -55,7 +61,7 @@
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
pull/371)) First v2 alpha release!
|
||||
hub.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
hub.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
pull/371)) First v2 alpha release!
|
||||
ri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
\`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tauri-plugin-dialog"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
description = "Native system dialogs for opening and saving files along with message dialogs on your Tauri application."
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
@@ -19,7 +19,7 @@ serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.7" }
|
||||
|
||||
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
|
||||
glib = "0.16"
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.6]
|
||||
|
||||
- [`85f8419`](https://github.com/tauri-apps/plugins-workspace/commit/85f841968200316958d707db0c39bb115f762471)([#848](https://github.com/tauri-apps/plugins-workspace/pull/848)) Fix `DebouncedEvent` type to correctly represent the actual type.
|
||||
- [`c601230`](https://github.com/tauri-apps/plugins-workspace/commit/c60123093ddf725af7228494182fed697ff8b021)([#847](https://github.com/tauri-apps/plugins-workspace/pull/847)) Add `createNew` option for `writeFile` and `writeTextFile` to create the file if doesn't exist and fail if it does.
|
||||
- [`c601230`](https://github.com/tauri-apps/plugins-workspace/commit/c60123093ddf725af7228494182fed697ff8b021)([#847](https://github.com/tauri-apps/plugins-workspace/pull/847)) Truncate files when using `writeFile` and `writeTextFile` with `append: false`.
|
||||
- [`2e2fc8d`](https://github.com/tauri-apps/plugins-workspace/commit/2e2fc8de69dd8d282b66ec81561d57d8af802dc5)([#857](https://github.com/tauri-apps/plugins-workspace/pull/857)) Fix `invalid args id for command unwatch` error when trying to unwatch a previously watched file or directory.
|
||||
- [`c601230`](https://github.com/tauri-apps/plugins-workspace/commit/c60123093ddf725af7228494182fed697ff8b021)([#847](https://github.com/tauri-apps/plugins-workspace/pull/847)) Fix panic when using `writeFile` or `writeTextFile` without passing an option object.
|
||||
|
||||
## \[2.0.0-alpha.5]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.13.
|
||||
@@ -30,7 +38,7 @@
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
- [`717ae67`](https://github.com/tauri-apps/plugins-workspace/commit/717ae670978feb4492fac1f295998b93f2b9347f)([#371](https://github.com/tauri-apps/plugins-workspace/pull/371)) First v2 alpha release!
|
||||
/pull/454)) Fix `writeBinaryFile` crashing with `command 'write_binary_file' not found`
|
||||
/pull/454)) Fix `writeBinaryFile` crashing with `command 'write_binary_file' not found`
|
||||
- [`d74fc0a`](https://github.com/tauri-apps/plugins-workspace/commit/d74fc0a097996e90a37be8f57d50b7d1f6ca616f)([#555](https://github.com/tauri-apps/plugins-workspace/pull/555)) Update to alpha.11.
|
||||
|
||||
## \[2.0.0-alpha.0]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tauri-plugin-fs"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
description = "Access the file system."
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
|
||||
@@ -980,6 +980,8 @@ interface WriteFileOptions {
|
||||
append?: boolean;
|
||||
/** Sets the option to allow creating a new file, if one doesn't already exist at the specified path (defaults to `true`). */
|
||||
create?: boolean;
|
||||
/** Sets the option to create a new file, failing if it already exists. */
|
||||
createNew?: boolean;
|
||||
/** File permissions. Ignored on Windows. */
|
||||
mode?: number;
|
||||
/** Base directory for `path` */
|
||||
@@ -1023,7 +1025,7 @@ async function writeFile(
|
||||
*
|
||||
* await writeTextFile('file.txt', "Hello world", { dir: BaseDirectory.App });
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function writeTextFile(
|
||||
@@ -1125,16 +1127,16 @@ type RawEventKind =
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type DebouncedEvent =
|
||||
| { kind: "any"; path: string }
|
||||
| { kind: "AnyContinous"; path: string };
|
||||
| { kind: "Any"; path: string }[]
|
||||
| { kind: "AnyContinuous"; path: string }[];
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type UnwatchFn = () => void;
|
||||
|
||||
async function unwatch(id: number): Promise<void> {
|
||||
await invoke("plugin:fs|unwatch", { id });
|
||||
async function unwatch(rid: number): Promise<void> {
|
||||
await invoke("plugin:fs|unwatch", { rid });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tauri-apps/plugin-fs",
|
||||
"version": "2.0.0-alpha.5",
|
||||
"version": "2.0.0-alpha.6",
|
||||
"description": "Access the file system.",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
|
||||
File diff suppressed because one or more lines are too long
+22
-10
@@ -579,11 +579,16 @@ pub fn write<R: Runtime>(
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WriteFileOptions {
|
||||
#[serde(flatten)]
|
||||
base: BaseOptions,
|
||||
append: Option<bool>,
|
||||
create: Option<bool>,
|
||||
#[serde(default)]
|
||||
append: bool,
|
||||
#[serde(default)]
|
||||
create: bool,
|
||||
#[serde(default)]
|
||||
create_new: bool,
|
||||
#[allow(unused)]
|
||||
mode: Option<u32>,
|
||||
}
|
||||
@@ -597,18 +602,25 @@ fn write_file_inner<R: Runtime>(
|
||||
let resolved_path = resolve_path(&app, path, options.as_ref().and_then(|o| o.base.base_dir))?;
|
||||
|
||||
let mut opts = std::fs::OpenOptions::new();
|
||||
opts.append(options.as_ref().map(|o| o.append.unwrap_or(false)).unwrap());
|
||||
opts.create(options.as_ref().map(|o| o.create.unwrap_or(true)).unwrap());
|
||||
// defaults
|
||||
opts.read(false).write(true).truncate(true).create(true);
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
if let Some(Some(mode)) = options.map(|o| o.mode) {
|
||||
opts.mode(mode & 0o777);
|
||||
if let Some(options) = options {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
if let Some(mode) = options.mode {
|
||||
opts.mode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
opts.create(options.create)
|
||||
.append(options.append)
|
||||
.truncate(!options.append)
|
||||
.create_new(options.create_new);
|
||||
}
|
||||
|
||||
let mut file = opts.write(true).open(&resolved_path).map_err(|e| {
|
||||
let mut file = opts.open(&resolved_path).map_err(|e| {
|
||||
format!(
|
||||
"failed to open file at path: {} with error: {e}",
|
||||
resolved_path.display()
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.9]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `fs@2.0.0-alpha.7`
|
||||
|
||||
## \[2.0.0-alpha.6]
|
||||
|
||||
- [`bfa87da`](https://github.com/tauri-apps/plugins-workspace/commit/bfa87da848f9f1da2abae3354eed632881eddf11)([#824](https://github.com/tauri-apps/plugins-workspace/pull/824)) Add `proxy` field to `fetch` options to configure proxy.
|
||||
|
||||
## \[2.0.0-alpha.5]
|
||||
|
||||
- [`387c2f9`](https://github.com/tauri-apps/plugins-workspace/commit/387c2f9e0ce4c75c07ffa3fd76391a25b58f5daf)([#802](https://github.com/tauri-apps/plugins-workspace/pull/802)) Update to @tauri-apps/api v2.0.0-alpha.13.
|
||||
@@ -43,5 +53,5 @@
|
||||
371\)) First v2 alpha release!
|
||||
!
|
||||
371\)) First v2 alpha release!
|
||||
!
|
||||
!
|
||||
371\)) First v2 alpha release!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tauri-plugin-http"
|
||||
version = "2.0.0-alpha.7"
|
||||
version = "2.0.0-alpha.9"
|
||||
description = "Access an HTTP client written in Rust."
|
||||
edition = { workspace = true }
|
||||
authors = { workspace = true }
|
||||
@@ -16,7 +16,7 @@ serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.7" }
|
||||
glob = "0.3"
|
||||
http = "0.2"
|
||||
reqwest = { version = "0.11", default-features = false }
|
||||
|
||||
@@ -26,6 +26,45 @@
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
/**
|
||||
* Configuration of a proxy that a Client should pass requests to.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Proxy = {
|
||||
/**
|
||||
* Proxy all traffic to the passed URL.
|
||||
*/
|
||||
all?: string | ProxyConfig;
|
||||
/**
|
||||
* Proxy all HTTP traffic to the passed URL.
|
||||
*/
|
||||
http?: string | ProxyConfig;
|
||||
/**
|
||||
* Proxy all HTTPS traffic to the passed URL.
|
||||
*/
|
||||
https?: string | ProxyConfig;
|
||||
};
|
||||
|
||||
export interface ProxyConfig {
|
||||
/**
|
||||
* The URL of the proxy server.
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* Set the `Proxy-Authorization` header using Basic auth.
|
||||
*/
|
||||
basicAuth?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
/**
|
||||
* A configuration for filtering out requests that shouldn’t be proxied.
|
||||
* Entries are expected to be comma-separated (whitespace between entries is ignored)
|
||||
*/
|
||||
noProxy?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options to configure the Rust client used to make fetch requests
|
||||
*
|
||||
@@ -39,6 +78,10 @@ export interface ClientOptions {
|
||||
maxRedirections?: number;
|
||||
/** Timeout in milliseconds */
|
||||
connectTimeout?: number;
|
||||
/**
|
||||
* Configuration of a proxy that a Client should pass requests to.
|
||||
*/
|
||||
proxy?: Proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,11 +104,13 @@ export async function fetch(
|
||||
): Promise<Response> {
|
||||
const maxRedirections = init?.maxRedirections;
|
||||
const connectTimeout = init?.maxRedirections;
|
||||
const proxy = init?.proxy;
|
||||
|
||||
// Remove these fields before creating the request
|
||||
if (init) {
|
||||
delete init.maxRedirections;
|
||||
delete init.connectTimeout;
|
||||
delete init.proxy;
|
||||
}
|
||||
|
||||
const req = new Request(input, init);
|
||||
@@ -73,12 +118,15 @@ export async function fetch(
|
||||
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
||||
|
||||
const rid = await invoke<number>("plugin:http|fetch", {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
headers: Array.from(req.headers.entries()),
|
||||
data: reqData,
|
||||
maxRedirections,
|
||||
connectTimeout,
|
||||
clientConfig: {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
headers: Array.from(req.headers.entries()),
|
||||
data: reqData,
|
||||
maxRedirections,
|
||||
connectTimeout,
|
||||
proxy,
|
||||
},
|
||||
});
|
||||
|
||||
req.signal.addEventListener("abort", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tauri-apps/plugin-http",
|
||||
"version": "2.0.0-alpha.5",
|
||||
"version": "2.0.0-alpha.6",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
"Tauri Programme within The Commons Conservancy"
|
||||
|
||||
@@ -1 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_HTTP__=function(e){"use strict";async function t(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,r){const n=r?.maxRedirections,i=r?.maxRedirections;r&&(delete r.maxRedirections,delete r.connectTimeout);const a=new Request(e,r),s=await a.arrayBuffer(),o=s.byteLength?Array.from(new Uint8Array(s)):null,u=await t("plugin:http|fetch",{method:a.method,url:a.url,headers:Array.from(a.headers.entries()),data:o,maxRedirections:n,connectTimeout:i});a.signal.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:u})}));const{status:_,statusText:d,url:c,headers:f}=await t("plugin:http|fetch_send",{rid:u}),h=await t("plugin:http|fetch_read_body",{rid:u}),p=new Response(new Uint8Array(h),{headers:f,status:_,statusText:d});return Object.defineProperty(p,"url",{value:c}),p},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_PLUGIN_HTTP__})}
|
||||
if("__TAURI__"in window){var __TAURI_PLUGIN_HTTP__=function(e){"use strict";async function t(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}return"function"==typeof SuppressedError&&SuppressedError,e.fetch=async function(e,r){const n=r?.maxRedirections,i=r?.maxRedirections,a=r?.proxy;r&&(delete r.maxRedirections,delete r.connectTimeout,delete r.proxy);const o=new Request(e,r),s=await o.arrayBuffer(),d=s.byteLength?Array.from(new Uint8Array(s)):null,u=await t("plugin:http|fetch",{clientConfig:{method:o.method,url:o.url,headers:Array.from(o.headers.entries()),data:d,maxRedirections:n,connectTimeout:i,proxy:a}});o.signal.addEventListener("abort",(()=>{t("plugin:http|fetch_cancel",{rid:u})}));const{status:_,statusText:c,url:p,headers:f}=await t("plugin:http|fetch_send",{rid:u}),l=await t("plugin:http|fetch_read_body",{rid:u}),h=new Response(new Uint8Array(l),{headers:f,status:_,statusText:c});return Object.defineProperty(h,"url",{value:p}),h},e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_PLUGIN_HTTP__})}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use http::{header, HeaderName, HeaderValue, Method, StatusCode};
|
||||
use reqwest::redirect::Policy;
|
||||
use serde::Serialize;
|
||||
use reqwest::{redirect::Policy, NoProxy};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{command, AppHandle, Runtime};
|
||||
|
||||
use crate::{Error, FetchRequest, HttpExt, RequestId};
|
||||
@@ -20,16 +20,111 @@ pub struct FetchResponse {
|
||||
url: String,
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub async fn fetch<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ClientConfig {
|
||||
method: String,
|
||||
url: url::Url,
|
||||
headers: Vec<(String, String)>,
|
||||
data: Option<Vec<u8>>,
|
||||
connect_timeout: Option<u64>,
|
||||
max_redirections: Option<usize>,
|
||||
proxy: Option<Proxy>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Proxy {
|
||||
all: Option<UrlOrConfig>,
|
||||
http: Option<UrlOrConfig>,
|
||||
https: Option<UrlOrConfig>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(untagged)]
|
||||
pub enum UrlOrConfig {
|
||||
Url(String),
|
||||
Config(ProxyConfig),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ProxyConfig {
|
||||
url: String,
|
||||
basic_auth: Option<BasicAuth>,
|
||||
no_proxy: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct BasicAuth {
|
||||
username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn proxy_creator(
|
||||
url_or_config: UrlOrConfig,
|
||||
proxy_fn: fn(String) -> reqwest::Result<reqwest::Proxy>,
|
||||
) -> reqwest::Result<reqwest::Proxy> {
|
||||
match url_or_config {
|
||||
UrlOrConfig::Url(url) => Ok(proxy_fn(url)?),
|
||||
UrlOrConfig::Config(ProxyConfig {
|
||||
url,
|
||||
basic_auth,
|
||||
no_proxy,
|
||||
}) => {
|
||||
let mut proxy = proxy_fn(url)?;
|
||||
if let Some(basic_auth) = basic_auth {
|
||||
proxy = proxy.basic_auth(&basic_auth.username, &basic_auth.password);
|
||||
}
|
||||
if let Some(no_proxy) = no_proxy {
|
||||
proxy = proxy.no_proxy(NoProxy::from_string(&no_proxy));
|
||||
}
|
||||
Ok(proxy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn attach_proxy(
|
||||
proxy: Proxy,
|
||||
mut builder: reqwest::ClientBuilder,
|
||||
) -> crate::Result<reqwest::ClientBuilder> {
|
||||
let Proxy { all, http, https } = proxy;
|
||||
|
||||
if let Some(all) = all {
|
||||
let proxy = proxy_creator(all, reqwest::Proxy::all)?;
|
||||
builder = builder.proxy(proxy);
|
||||
}
|
||||
|
||||
if let Some(http) = http {
|
||||
let proxy = proxy_creator(http, reqwest::Proxy::http)?;
|
||||
builder = builder.proxy(proxy);
|
||||
}
|
||||
|
||||
if let Some(https) = https {
|
||||
let proxy = proxy_creator(https, reqwest::Proxy::https)?;
|
||||
builder = builder.proxy(proxy);
|
||||
}
|
||||
|
||||
Ok(builder)
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub async fn fetch<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
client_config: ClientConfig,
|
||||
) -> crate::Result<RequestId> {
|
||||
let ClientConfig {
|
||||
method,
|
||||
url,
|
||||
headers,
|
||||
data,
|
||||
connect_timeout,
|
||||
max_redirections,
|
||||
proxy,
|
||||
} = client_config;
|
||||
|
||||
let scheme = url.scheme();
|
||||
let method = Method::from_bytes(method.as_bytes())?;
|
||||
let headers: HashMap<String, String> = HashMap::from_iter(headers);
|
||||
@@ -51,6 +146,10 @@ pub async fn fetch<R: Runtime>(
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(proxy_config) = proxy {
|
||||
builder = attach_proxy(proxy_config, builder)?;
|
||||
}
|
||||
|
||||
let mut request = builder.build()?.request(method.clone(), url);
|
||||
|
||||
for (key, value) in &headers {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## \[2.0.0-alpha.7]
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Upgraded to `fs@2.0.0-alpha.7`
|
||||
|
||||
## \[2.0.0-alpha.6]
|
||||
|
||||
- [`2cf8faa`](https://github.com/tauri-apps/plugins-workspace/commit/2cf8faa3e149af55eb86e5aba8ebfc54210ca703)([#839](https://github.com/tauri-apps/plugins-workspace/pull/839)) Update to tauri@alpha.20.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tauri-plugin-persisted-scope"
|
||||
version = "2.0.0-alpha.6"
|
||||
version = "2.0.0-alpha.7"
|
||||
description = "Save filesystem and asset scopes and restore them when the app is reopened."
|
||||
authors = { workspace = true }
|
||||
license = { workspace = true }
|
||||
@@ -19,7 +19,7 @@ log = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
aho-corasick = "1"
|
||||
bincode = "1"
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.6" }
|
||||
tauri-plugin-fs = { path = "../fs", version = "2.0.0-alpha.7" }
|
||||
|
||||
[features]
|
||||
protocol-asset = [ "tauri/protocol-asset" ]
|
||||
|
||||
Generated
+2
-2
@@ -82,13 +82,13 @@ importers:
|
||||
specifier: 2.0.0-alpha.5
|
||||
version: link:../../plugins/dialog
|
||||
'@tauri-apps/plugin-fs':
|
||||
specifier: 2.0.0-alpha.5
|
||||
specifier: 2.0.0-alpha.6
|
||||
version: link:../../plugins/fs
|
||||
'@tauri-apps/plugin-global-shortcut':
|
||||
specifier: 2.0.0-alpha.5
|
||||
version: link:../../plugins/global-shortcut
|
||||
'@tauri-apps/plugin-http':
|
||||
specifier: 2.0.0-alpha.5
|
||||
specifier: 2.0.0-alpha.6
|
||||
version: link:../../plugins/http
|
||||
'@tauri-apps/plugin-nfc':
|
||||
specifier: 2.0.0-alpha.0
|
||||
|
||||
Reference in New Issue
Block a user