Skip to content

Commit

Permalink
refactor(tauri): into macros
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Nov 20, 2023
1 parent 3350239 commit 3eef3ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions cspell.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"splitn",
"stperson",
"struct",
"subsec",
"tauri",
"thiserror",
"Unhide",
Expand Down
26 changes: 19 additions & 7 deletions src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
use crate::convert_option::{AsyncFrom, GuiConverterOptions};
use dar2oar_core::{convert_dar_to_oar, remove_oar, unhide_dar, Closure, ConvertOptions};
use std::time::Instant;
use tauri::Window;

macro_rules! dar2oar {
($options:ident, $closure:expr) => {{
let start = Instant::now();
tracing::debug!("options: {:?}", &$options);
let config = ConvertOptions::async_from($options).await;
let res = response!(convert_dar_to_oar(config, $closure).await);
let elapsed = start.elapsed();
tracing::info!(
"Conversion time: {}.{}secs.",
elapsed.as_secs(),
elapsed.subsec_millis()
);
res
}};
}

/// logger hook or bail!
macro_rules! response {
($res:expr) => {
Expand All @@ -25,18 +42,14 @@ macro_rules! bail {

#[tauri::command]
pub(crate) async fn convert_dar2oar(options: GuiConverterOptions<'_>) -> Result<String, String> {
tracing::debug!("options: {:?}", &options);
let config = ConvertOptions::async_from(options).await;
response!(convert_dar_to_oar(config, Closure::default).await)
dar2oar!(options, Closure::default)
}

#[tauri::command]
pub(crate) async fn convert_dar2oar_with_progress(
window: Window,
options: GuiConverterOptions<'_>,
) -> Result<String, String> {
tracing::debug!("options: {:?}", &options);

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct Payload {
index: usize,
Expand All @@ -46,9 +59,8 @@ pub(crate) async fn convert_dar2oar_with_progress(
tracing::error!("{}", err);
};
};
let config = ConvertOptions::async_from(options).await;

response!(convert_dar_to_oar(config, sender).await)
dar2oar!(options, sender)
}

#[tauri::command]
Expand Down

0 comments on commit 3eef3ab

Please sign in to comment.