Skip to content

Commit bf3a254

Browse files
committed
🛠️ • fix rust format check
1 parent 04262f3 commit bf3a254

2 files changed

Lines changed: 79 additions & 20 deletions

File tree

src-tauri/src/commands.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,7 @@ pub async fn set_macro_speed_multiplier(
17811781
}
17821782

17831783
#[tauri::command]
1784-
pub async fn get_macro_speed_multiplier(
1785-
state: State<'_, Arc<AppState>>,
1786-
) -> Result<f64, String> {
1784+
pub async fn get_macro_speed_multiplier(state: State<'_, Arc<AppState>>) -> Result<f64, String> {
17871785
Ok(*state.macro_engine.speed_multiplier.lock().await)
17881786
}
17891787

src-tauri/src/engine/macro_engine/playback.rs

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use super::types::{
1414
MacroPlayerState,
1515
};
1616

17-
async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64) -> Result<(), String> {
17+
async fn execute_action(
18+
enigo: &mut Enigo,
19+
action: &MacroAction,
20+
multiplier: f64,
21+
) -> Result<(), String> {
1822
match &action.config {
1923
MacroActionConfig::Mouse {
2024
button,
@@ -26,7 +30,10 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
2630
.move_mouse(*x, *y, Coordinate::Abs)
2731
.map_err(|e| format!("Could not move the mouse. Details: {}", e))?;
2832

29-
sleep(Duration::from_millis((10.0 / multiplier).round().max(1.0) as u64)).await;
33+
sleep(Duration::from_millis(
34+
(10.0 / multiplier).round().max(1.0) as u64
35+
))
36+
.await;
3037
}
3138

3239
match mouse_action {
@@ -35,7 +42,10 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
3542
enigo
3643
.button(btn, enigo::Direction::Press)
3744
.map_err(|e| format!("Could not press the mouse button. Details: {}", e))?;
38-
sleep(Duration::from_millis((50.0 / multiplier).round().max(1.0) as u64)).await;
45+
sleep(Duration::from_millis(
46+
(50.0 / multiplier).round().max(1.0) as u64
47+
))
48+
.await;
3949
enigo.button(btn, enigo::Direction::Release).map_err(|e| {
4050
format!("Could not release the mouse button. Details: {}", e)
4151
})?;
@@ -45,7 +55,10 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
4555
enigo
4656
.button(btn, enigo::Direction::Press)
4757
.map_err(|e| format!("Could not press the mouse button. Details: {}", e))?;
48-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
58+
sleep(Duration::from_millis(
59+
(*duration_ms as f64 / multiplier).round() as u64,
60+
))
61+
.await;
4962
enigo.button(btn, enigo::Direction::Release).map_err(|e| {
5063
format!("Could not release the mouse button. Details: {}", e)
5164
})?;
@@ -71,10 +84,21 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
7184
.map_err(|e| format!("Could not move the mouse. Details: {}", e))?;
7285
}
7386
MacroMoveStyle::Linear { duration_ms } => {
74-
linear_move_to(enigo, *x, *y, (*duration_ms as f64 / multiplier).round() as u32).await?;
87+
linear_move_to(
88+
enigo,
89+
*x,
90+
*y,
91+
(*duration_ms as f64 / multiplier).round() as u32,
92+
)
93+
.await?;
7594
}
7695
MacroMoveStyle::Smooth { path, duration_ms } => {
77-
play_smooth_path(enigo, path, (*duration_ms as f64 / multiplier).round() as u32).await?;
96+
play_smooth_path(
97+
enigo,
98+
path,
99+
(*duration_ms as f64 / multiplier).round() as u32,
100+
)
101+
.await?;
78102
}
79103
},
80104
MacroActionConfig::Keyboard {
@@ -116,7 +140,10 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
116140
enigo
117141
.key(key_code, enigo::Direction::Press)
118142
.map_err(|e| format!("Could not press the key. Details: {}", e))?;
119-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
143+
sleep(Duration::from_millis(
144+
(*duration_ms as f64 / multiplier).round() as u64,
145+
))
146+
.await;
120147
enigo
121148
.key(key_code, enigo::Direction::Release)
122149
.map_err(|e| format!("Could not release the key. Details: {}", e))?;
@@ -142,7 +169,10 @@ async fn execute_action(enigo: &mut Enigo, action: &MacroAction, multiplier: f64
142169
}
143170
}
144171
MacroActionConfig::Sleep { duration_ms } => {
145-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
172+
sleep(Duration::from_millis(
173+
(*duration_ms as f64 / multiplier).round() as u64,
174+
))
175+
.await;
146176
}
147177
MacroActionConfig::Scroll { clicks } => {
148178
enigo
@@ -203,12 +233,18 @@ impl LinuxPlaybackBackend {
203233
match action {
204234
MacroMouseAction::Press => {
205235
Self::emit_key(&mut self.mouse, key, true)?;
206-
sleep(Duration::from_millis((50.0 / multiplier).round().max(1.0) as u64)).await;
236+
sleep(Duration::from_millis(
237+
(50.0 / multiplier).round().max(1.0) as u64
238+
))
239+
.await;
207240
Self::emit_key(&mut self.mouse, key, false)
208241
}
209242
MacroMouseAction::Hold { duration_ms } => {
210243
Self::emit_key(&mut self.mouse, key, true)?;
211-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
244+
sleep(Duration::from_millis(
245+
(*duration_ms as f64 / multiplier).round() as u64,
246+
))
247+
.await;
212248
Self::emit_key(&mut self.mouse, key, false)
213249
}
214250
MacroMouseAction::Down => Self::emit_key(&mut self.mouse, key, true),
@@ -250,18 +286,34 @@ async fn execute_action(
250286
} => {
251287
if let Some((x, y)) = position {
252288
backend.move_mouse(*x, *y)?;
253-
sleep(Duration::from_millis((10.0 / multiplier).round().max(1.0) as u64)).await;
289+
sleep(Duration::from_millis(
290+
(10.0 / multiplier).round().max(1.0) as u64
291+
))
292+
.await;
254293
}
255294

256-
backend.click_mouse(button, mouse_action, multiplier).await?;
295+
backend
296+
.click_mouse(button, mouse_action, multiplier)
297+
.await?;
257298
}
258299
MacroActionConfig::Move { x, y, style } => match style {
259300
MacroMoveStyle::Instant => backend.move_mouse(*x, *y)?,
260301
MacroMoveStyle::Linear { duration_ms } => {
261-
linear_move_to(backend, *x, *y, (*duration_ms as f64 / multiplier).round() as u32).await?;
302+
linear_move_to(
303+
backend,
304+
*x,
305+
*y,
306+
(*duration_ms as f64 / multiplier).round() as u32,
307+
)
308+
.await?;
262309
}
263310
MacroMoveStyle::Smooth { path, duration_ms } => {
264-
play_smooth_path(backend, path, (*duration_ms as f64 / multiplier).round() as u32).await?;
311+
play_smooth_path(
312+
backend,
313+
path,
314+
(*duration_ms as f64 / multiplier).round() as u32,
315+
)
316+
.await?;
265317
}
266318
},
267319
MacroActionConfig::Keyboard {
@@ -292,7 +344,10 @@ async fn execute_action(
292344
}
293345
MacroKeyboardAction::Hold { duration_ms } => {
294346
LinuxPlaybackBackend::emit_key(&mut backend.keyboard, key_code, true)?;
295-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
347+
sleep(Duration::from_millis(
348+
(*duration_ms as f64 / multiplier).round() as u64,
349+
))
350+
.await;
296351
LinuxPlaybackBackend::emit_key(&mut backend.keyboard, key_code, false)?;
297352
}
298353
MacroKeyboardAction::Down => {
@@ -308,7 +363,10 @@ async fn execute_action(
308363
}
309364
}
310365
MacroActionConfig::Sleep { duration_ms } => {
311-
sleep(Duration::from_millis((*duration_ms as f64 / multiplier).round() as u64)).await;
366+
sleep(Duration::from_millis(
367+
(*duration_ms as f64 / multiplier).round() as u64,
368+
))
369+
.await;
312370
}
313371
MacroActionConfig::Scroll { clicks } => {
314372
backend.scroll_mouse(*clicks)?;
@@ -958,7 +1016,10 @@ async fn playback_loop(
9581016
break;
9591017
}
9601018

961-
sleep(Duration::from_millis(((5.0 / speed_multiplier).round() as u64).max(1))).await;
1019+
sleep(Duration::from_millis(
1020+
((5.0 / speed_multiplier).round() as u64).max(1),
1021+
))
1022+
.await;
9621023
}
9631024

9641025
iteration += 1;

0 commit comments

Comments
 (0)