mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
fix: run connect on main thread, use tauri async_runtime
fixes an overflow issue on Windows
This commit is contained in:
+5
-6
@@ -76,20 +76,19 @@ enum WebSocketMessage {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn connect<R: Runtime>(
|
||||
fn connect<R: Runtime>(
|
||||
window: Window<R>,
|
||||
manager: State<'_, ConnectionManager>,
|
||||
url: String,
|
||||
callback_function: String,
|
||||
config: Option<ConnectionConfig>,
|
||||
) -> Result<Id> {
|
||||
let (ws_stream, _) = connect_async_with_config(url, config.map(Into::into)).await?;
|
||||
let (write, read) = ws_stream.split();
|
||||
|
||||
let id = rand::random();
|
||||
manager.0.lock().await.insert(id, write);
|
||||
let (ws_stream, _) = tauri::async_runtime::block_on(connect_async_with_config(url, config.map(Into::into)))?;
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let (write, read) = ws_stream.split();
|
||||
let manager = window.state::<ConnectionManager>();
|
||||
manager.0.lock().await.insert(id, write);
|
||||
read.for_each(move |message| {
|
||||
let window_ = window.clone();
|
||||
let callback_function_ = callback_function.clone();
|
||||
|
||||
Reference in New Issue
Block a user