From e240d5f1ad2391e586f25e70ff2838a309ab6bd8 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 17 Nov 2021 20:56:14 +0100 Subject: [PATCH] Change scheme runtimes to use one shared runtime instead of creating a new one Signed-off-by: trivernis --- mediarepo-api/src/tauri_plugin/custom_schemes.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mediarepo-api/src/tauri_plugin/custom_schemes.rs b/mediarepo-api/src/tauri_plugin/custom_schemes.rs index af553a1..2e9f154 100644 --- a/mediarepo-api/src/tauri_plugin/custom_schemes.rs +++ b/mediarepo-api/src/tauri_plugin/custom_schemes.rs @@ -3,6 +3,7 @@ use crate::tauri_plugin::state::{ApiState, BufferState}; use crate::types::identifier::FileIdentifier; use std::borrow::Cow; use std::collections::HashMap; +use std::sync::Arc; use tauri::http::{Request, Response, ResponseBuilder}; use tauri::{AppHandle, Builder, Manager, Runtime}; use tokio::runtime::{Builder as TokioRuntimeBuilder, Runtime as TokioRuntime}; @@ -11,21 +12,21 @@ use url::Url; type Result = std::result::Result>; pub fn register_custom_uri_schemes(builder: Builder) -> Builder { + let runtime = + Arc::new(build_uri_runtime().expect("Failed to build async runtime for custom schemes")); builder .register_uri_scheme_protocol("once", once_scheme) - .register_uri_scheme_protocol("content", |a, r| { - build_uri_runtime()?.block_on(content_scheme(a, r)) - }) - .register_uri_scheme_protocol("thumb", |a, r| { - build_uri_runtime()?.block_on(thumb_scheme(a, r)) + .register_uri_scheme_protocol("content", { + let runtime = Arc::clone(&runtime); + move |a, r| runtime.block_on(content_scheme(a, r)) }) + .register_uri_scheme_protocol("thumb", move |a, r| runtime.block_on(thumb_scheme(a, r))) } fn build_uri_runtime() -> PluginResult { let runtime = TokioRuntimeBuilder::new_current_thread() .thread_name("custom-scheme") .enable_all() - .max_blocking_threads(1) .build()?; Ok(runtime)