fix: use InvokeResponseBody as packet

pull/2479/head
adrieljss 5 months ago
parent ba122e6396
commit 0a2645ffe8
No known key found for this signature in database
GPG Key ID: 849F13CBD0B4AD05

@ -106,16 +106,6 @@ export interface DangerousSettings {
acceptInvalidHostnames?: boolean acceptInvalidHostnames?: boolean
} }
/**
* Stream Packet for IPC
*/
export interface StreamMessage {
/**
* The chunk - an array of bytes sent from Rust.
*/
bytes: Uint8Array
}
const ERROR_REQUEST_CANCELLED = 'Request canceled' const ERROR_REQUEST_CANCELLED = 'Request canceled'
/** /**
@ -196,18 +186,18 @@ export async function fetch(
throw new Error(ERROR_REQUEST_CANCELLED) throw new Error(ERROR_REQUEST_CANCELLED)
} }
const streamChannel = new Channel<StreamMessage>() const streamChannel = new Channel<Uint8Array>()
const readableStreamBody = new ReadableStream({ const readableStreamBody = new ReadableStream({
start: (controller) => { start: (controller) => {
streamChannel.onmessage = (res: StreamMessage) => { streamChannel.onmessage = (res: Uint8Array) => {
// close early if aborted // close early if aborted
if (signal?.aborted) { if (signal?.aborted) {
controller.error(ERROR_REQUEST_CANCELLED) controller.error(ERROR_REQUEST_CANCELLED)
return return
} }
if (!res.bytes.length) { if (!res.length) {
controller.close() controller.close()
return return
} }

@ -129,12 +129,6 @@ pub struct BasicAuth {
password: String, password: String,
} }
#[derive(Clone, Serialize)]
pub struct StreamMessage {
#[serde(with = "serde_bytes")]
bytes: Vec<u8>
}
#[inline] #[inline]
fn proxy_creator( fn proxy_creator(
url_or_config: UrlOrConfig, url_or_config: UrlOrConfig,
@ -190,7 +184,7 @@ pub async fn fetch<R: Runtime>(
client_config: ClientConfig, client_config: ClientConfig,
command_scope: CommandScope<Entry>, command_scope: CommandScope<Entry>,
global_scope: GlobalScope<Entry>, global_scope: GlobalScope<Entry>,
stream_channel: Channel<StreamMessage> stream_channel: Channel<tauri::ipc::InvokeResponseBody>
) -> crate::Result<ResourceId> { ) -> crate::Result<ResourceId> {
let ClientConfig { let ClientConfig {
method, method,
@ -329,11 +323,11 @@ pub async fn fetch<R: Runtime>(
// send response through IPC channel // send response through IPC channel
while let Some(chunk) = res.chunk().await? { while let Some(chunk) = res.chunk().await? {
stream_channel.send(StreamMessage{bytes: chunk.to_vec()})?; stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?;
} }
// send empty vector when done // send empty vector when done
stream_channel.send(StreamMessage{bytes: Vec::new()})?; stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?;
// return that response // return that response
Ok(res) Ok(res)

Loading…
Cancel
Save