wip: Tauri event system

This commit is contained in:
binarybaron 2024-08-12 00:13:31 +02:00
parent 9b369a042c
commit 62ad10ac9c
No known key found for this signature in database
GPG Key ID: 99B75D3E1476A26E
6 changed files with 47 additions and 42 deletions

1
Cargo.lock generated
View File

@ -6396,6 +6396,7 @@ dependencies = [
"sqlx",
"structopt",
"strum",
"tauri",
"tempfile",
"testcontainers",
"thiserror",

View File

@ -1,7 +1,7 @@
[package]
name = "unstoppableswap-gui-rs"
version = "0.0.0"
authors = [ "binarybaron", "einliterflasche", "unstoppableswap" ]
authors = ["binarybaron", "einliterflasche", "unstoppableswap"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -9,15 +9,15 @@ description = "GUI for XMR<>BTC Atomic Swaps written in Rust"
[lib]
name = "unstoppableswap_gui_rs_lib"
crate-type = [ "lib", "cdylib", "staticlib" ]
crate-type = ["lib", "cdylib", "staticlib"]
[build-dependencies]
tauri-build = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
tauri-build = { version = "2.0.0-rc.1", features = ["config-json5"] }
[dependencies]
anyhow = "1"
once_cell = "1"
serde = { version = "1", features = [ "derive" ] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
swap = { path = "../swap" }
tauri = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
tauri = { version = "2.0.0-rc.1", features = ["config-json5"] }

View File

@ -89,7 +89,8 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
true,
None,
)
.await?
.await
.unwrap()
.with_tauri_handle(app.app_handle().to_owned());
app.manage(Arc::new(context));

View File

@ -9,36 +9,7 @@ description = "XMR/BTC trustless atomic swaps."
name = "swap"
[dependencies]
tauri = { version = "2.0.0-rc.1" }
[target.'cfg(not(windows))'.dependencies]
tokio-tar = "0.3"
[target.'cfg(windows)'.dependencies]
zip = "0.5"
[dev-dependencies]
bitcoin-harness = { git = "https://github.com/delta1/bitcoin-harness-rs.git", rev = "80cc8d05db2610d8531011be505b7bee2b5cdf9f" }
get-port = "3"
hyper = "1.3"
jsonrpsee = { version = "0.16.2", features = ["ws-client"] }
mockito = "1.4"
monero-harness = { path = "../monero-harness" }
port_check = "0.2"
proptest = "1"
sequential-test = "0.2.4"
serde_cbor = "0.11"
serial_test = "3.1"
tempfile = "3"
testcontainers = "0.15"
[build-dependencies]
anyhow = "1"
vergen = { version = "8.3", default-features = false, features = [
"build",
"git",
"git2",
] }
async-compression = { version = "0.3", features = ["bzip2", "tokio"] }
async-trait = "0.1"
atty = "0.2"
@ -150,3 +121,33 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
url = { version = "2", features = ["serde"] }
uuid = { version = "1.9", features = ["serde", "v4"] }
void = "1"
tauri = { version = "2.0.0-rc.1", features = ["config-json5"] }
[target.'cfg(not(windows))'.dependencies]
tokio-tar = "0.3"
[target.'cfg(windows)'.dependencies]
zip = "0.5"
[dev-dependencies]
bitcoin-harness = { git = "https://github.com/delta1/bitcoin-harness-rs.git", rev = "80cc8d05db2610d8531011be505b7bee2b5cdf9f" }
get-port = "3"
hyper = "1.3"
jsonrpsee = { version = "0.16.2", features = ["ws-client"] }
mockito = "1.4"
monero-harness = { path = "../monero-harness" }
port_check = "0.2"
proptest = "1"
sequential-test = "0.2.4"
serde_cbor = "0.11"
serial_test = "3.1"
tempfile = "3"
testcontainers = "0.15"
[build-dependencies]
anyhow = "1"
vergen = { version = "8.3", default-features = false, features = [
"build",
"git",
"git2",
] }

View File

@ -7,14 +7,15 @@ use crate::network::rendezvous::XmrBtcNamespace;
use crate::protocol::Database;
use crate::seed::Seed;
use crate::{bitcoin, cli, monero};
use anyhow::{bail, Context as AnyContext, Error, Result};
use anyhow::{anyhow, bail, Context as AnyContext, Error, Result};
use futures::future::try_join_all;
use serde::Serialize;
use std::fmt;
use std::future::Future;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::{Arc, Once};
use tauri::AppHandle;
use tauri::{AppHandle, Emitter};
use tokio::sync::{broadcast, broadcast::Sender, Mutex, RwLock};
use tokio::task::JoinHandle;
use url::Url;
@ -250,14 +251,15 @@ impl Context {
Ok(context)
}
pub fn with_tauri_handle(mut self, tauri_handle: Arc<AppHandle>) -> Self {
self.tauri_handle = Some(tauri_handle);
pub fn with_tauri_handle(mut self, tauri_handle: AppHandle) -> Self {
self.tauri_handle = Some(Arc::new(tauri_handle));
self
}
pub fn emit_tauri_event<S: Serialize + Clone>(mut self, event: &str, payload: S) -> Result<()> {
pub fn emit_tauri_event<S: Serialize + Clone>(self, event: &str, payload: S) -> Result<()> {
self.tauri_handle
.ok_or_else(|| anyhow!("Tauri handle not set"))?
.ok_or(anyhow!("Tauri handle not set"))?
.as_ref()
.emit(event, payload)?;
Ok(())

View File

@ -1,7 +1,7 @@
use crate::api::request::{
buy_xmr, cancel_and_refund, get_balance, get_current_swap, get_history, get_raw_states,
get_swap_info, list_sellers, monero_recovery, resume_swap, suspend_current_swap, withdraw_btc,
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, GetSwapInfoArgs, ListSellersArgs, Method,
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, GetSwapInfoArgs, ListSellersArgs,
MoneroRecoveryArgs, ResumeArgs, WithdrawBtcArgs,
};
use crate::api::Context;