Skip to content

refactor(core): use webview's URI schemes for IPC#7170

Merged
lucasfernog merged 101 commits intotauri-apps:devfrom
lucasfernog:feat/ipc-custom-protocol
Aug 10, 2023
Merged

refactor(core): use webview's URI schemes for IPC#7170
lucasfernog merged 101 commits intotauri-apps:devfrom
lucasfernog:feat/ipc-custom-protocol

Conversation

@lucasfernog
Copy link
Member

@lucasfernog lucasfernog commented Jun 8, 2023

closes #4875

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

@lucasfernog lucasfernog changed the base branch from dev to next June 8, 2023 20:14
@lucasfernog
Copy link
Member Author

A command returning a 150MB file now takes less than 60ms to resolve. Previously: almost 50 seconds.

@amrbashir
Copy link
Member

image

@lucasfernog
Copy link
Member Author

Needs tauri-apps/wry#970

@lucasfernog
Copy link
Member Author

Also needs #4752 to fix the unit tests.

@lucasfernog
Copy link
Member Author

We'll detect and use the custom protocol IPC on Linux if available when tauri-apps/wry#969 lands. On older webkit2gtk, we'll need to stick with the current approach (JSON :( )

@lucasfernog lucasfernog merged commit fbeb5b9 into tauri-apps:dev Aug 10, 2023
@lucasfernog lucasfernog deleted the feat/ipc-custom-protocol branch August 10, 2023 13:12
@ghost
Copy link

ghost commented Aug 10, 2023

Having lurked in this thread since the PR was first made I'm quite delighted to see this merged! I have been using the alpha releases for a while now and wonder how I would go about using this new feature together with the new v2 api plugins?

Naively switching over the tauri and tauri-build dependencies to use the dev branch of course creates version conflicts with the fs plugin that I use. From where should I pull in the plugins?

@amrbashir
Copy link
Member

amrbashir commented Aug 10, 2023

Naively switching over the tauri and tauri-build dependencies to use the dev branch of course creates version conflicts with the fs plugin that I use. From where should I pull in the plugins?

The v2 branch of plugins-workspace repo https://github.com/tauri-apps/plugins-workspace/tree/v2 or from the published crates on crates.io
but probably you should wait for the next alpha release (soon to be released).

@kris-ava
Copy link

On MacOS this breaks IPC using Remote Domains. Safari blocks the requests to localhost from other domains.

@Xiaobaishushu25
Copy link

I want to know how to use this new IPC?i update to v2,but the file transder between js and rust is also slow in Windows OS, Here is my Cargo. toml

[build-dependencies]
tauri-build = { version = "2.0.0-beta", features = [] }

[dependencies]
tauri = { version = "2.0.0-beta.13", features = ["custom-protocol"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
chrono = "0.4.31"
tokio = { version = "1.20", features = ["macros", "rt-multi-thread"] }
tauri-plugin-dialog = "2.0.0-beta.3"
tauri-plugin-http = "2.0.0-beta.3"
tauri-plugin-fs = "2.0.0-beta.3"


[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

this is my rust code:

#[tauri::command]
async fn append_chunk_to_file(
    window: Window,
    path: String,
    chunk: Vec<u8>,
    end: bool,
) -> Result<(), String> {
    let current_time = Local::now().time();
    println!("enter rust time: {}", current_time);
    println!("start{:?}", Instant::now()); //收到函数时间Instant { t: 644913.1384745s }
    tokio::spawn(async move {
        let mut file = OpenOptions::new()
            .create(true)
            .append(true)
            .open(&path)
            .map_err(|e| e.to_string())
            .unwrap();
        file.write_all(&chunk).map_err(|e| e.to_string()).unwrap();
        if end {
            window.emit("insert", Payload { message: path }).unwrap();
        }
    });
    let instant = Instant::now();
    println!("end{:?}", instant); //结束函数时间Instant { t: 644913.1386845s }
    let current_time = Local::now().time();
    println!("return time: {}", current_time);
    Ok(())
}

i use it in js:

import {mkdir, readFile, writeFile, BaseDirectory} from "@tauri-apps/plugin-fs";
import {convertFileSrc, invoke} from "@tauri-apps/api/core";
const content = await file.arrayBuffer()
let content1 = new Uint8Array(content);
await invoke("append_chunk_to_file", {path: url, chunk: chunk1,end:true})

It took 8 seconds to transfer a 23MB image using the above code(most time take in se and de),but @lucasfernog say A command returning a 150MB file now takes less than 60ms to resolve. Previously: almost 50 seconds.
Where did I go wrong? Do you have the correct example code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security: needs audit This issue/PR needs a security audit

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

[bug] naming an argument cmd causes unexpected and undocumented error

10 participants