@@ -3,6 +3,7 @@ use std::path::Path;
3
3
use futures:: future:: join_all;
4
4
use reqwest:: Client ;
5
5
use tauri:: api:: dialog:: blocking:: FileDialogBuilder ;
6
+ use tauri:: Manager ;
6
7
use tokio:: fs;
7
8
use tokio:: fs:: create_dir;
8
9
use crate :: aggregator:: aggregate;
@@ -14,35 +15,35 @@ use crate::processor::process_file;
14
15
use crate :: serializer:: { serialize, serialize_calculations} ;
15
16
use tokio:: task:: { JoinHandle , JoinSet } ;
16
17
18
+ pub enum ProgressUpdate {
19
+ Set {
20
+ iterations : usize ,
21
+ total_iterations : Option < usize > ,
22
+ } ,
23
+ Increment {
24
+ iterations : usize ,
25
+ } ,
26
+ }
17
27
18
- #[ tauri:: command]
19
- pub async fn install_dependencies ( app_handle : tauri:: AppHandle ) -> Result < ( ) , String > {
20
- let dependencies_dir = app_handle
21
- . path_resolver ( )
22
- . app_local_data_dir ( )
23
- . unwrap ( )
24
- . join ( "dependencies" ) ;
25
-
26
- if fs:: try_exists ( & dependencies_dir) . await . unwrap ( ) == true {
27
- fs:: remove_dir_all ( & dependencies_dir)
28
- . await
29
- . map_err ( |err| format ! ( "Failed to remove existing dependencies: {err}" ) ) ?;
30
- }
28
+ pub type ProgressCallback = Box < dyn Fn ( ProgressUpdate ) + Send + Sync > ;
31
29
32
- let client = Client :: new ( ) ;
33
- let response = client
34
- . get ( "https://github.com/rgsadygov/SRM_executables/archive/refs/heads/main.zip" )
35
- . send ( )
36
- . await
37
- . map_err ( |err| format ! ( "Failed to download dependencies: {err}" ) ) ?
38
- . bytes ( )
39
- . await
40
- . unwrap ( ) ;
30
+ #[ derive( Clone , serde:: Serialize ) ]
31
+ struct ProgressSetPayload {
32
+ uuid : String ,
33
+ iterations : usize ,
34
+ total_iterations : Option < usize > ,
35
+ }
41
36
42
- zip_extract:: extract ( Cursor :: new ( response) , & dependencies_dir, true )
43
- . map_err ( |err| format ! ( "Failed to extract dependencies: {err}" ) ) ?;
37
+ #[ derive( Clone , serde:: Serialize ) ]
38
+ struct ProgressIncrementPayload {
39
+ uuid : String ,
40
+ iterations : usize ,
41
+ }
44
42
45
- Ok ( ( ) )
43
+ #[ derive( Clone , serde:: Serialize ) ]
44
+ struct ErrorPayload {
45
+ uuid : String ,
46
+ message : String ,
46
47
}
47
48
48
49
#[ tauri:: command]
@@ -54,7 +55,8 @@ pub async fn process_data(
54
55
input_files : Vec < InputFile > ,
55
56
) -> Result < ( ) , String > {
56
57
// TODO: https://tauri.app/v1/guides/features/events/
57
- dbg ! ( "is this running?" ) ;
58
+ dbg ! ( "Run" ) ;
59
+ dbg ! ( & input_files) ;
58
60
59
61
let deps_path = match engine_type {
60
62
EngineType :: Single =>
@@ -64,26 +66,63 @@ pub async fn process_data(
64
66
. resolve_resource ( "assets" ) . unwrap ( ) . join ( "multi-timepoint-engine" ) ,
65
67
} ;
66
68
69
+ let window = app. get_window ( "main" ) . unwrap ( ) ;
67
70
let mut tasks: Vec < JoinHandle < anyhow:: Result < ( ) > > > = vec ! [ ] ;
68
- dbg ! ( "wtf" ) ;
69
-
70
71
71
72
for input_file in input_files {
73
+ dbg ! ( "hellno" ) ;
72
74
let deps_path = deps_path. clone ( ) ;
75
+ let window = window. clone ( ) ;
76
+ let input_uuid = input_file. uuid . clone ( ) ;
73
77
74
78
let task = tokio:: spawn ( async move {
75
- process_file (
79
+ let window2 = window. clone ( ) ;
80
+ let progress_callback: ProgressCallback = Box :: new ( move |update| {
81
+ match update {
82
+ ProgressUpdate :: Set { iterations, total_iterations } => {
83
+ let payload = ProgressSetPayload {
84
+ uuid : input_uuid. clone ( ) ,
85
+ iterations,
86
+ total_iterations,
87
+ } ;
88
+
89
+ window2. emit ( "progress-set" , payload) . unwrap ( ) ;
90
+ }
91
+ ProgressUpdate :: Increment { iterations } => {
92
+ let payload = ProgressIncrementPayload {
93
+ uuid : input_uuid. clone ( ) ,
94
+ iterations,
95
+ } ;
96
+
97
+ window2. emit ( "progress-update" , payload) . unwrap ( ) ;
98
+ }
99
+ }
100
+ } ) ;
101
+
102
+ let input_uuid = input_file. uuid . clone ( ) ;
103
+
104
+ match process_file (
76
105
& deps_path,
77
106
should_remove_na_calculations,
78
107
tolerance_multiplier,
79
108
input_file,
80
- ) . await ?;
81
-
82
- dbg ! ( "hello?" ) ;
83
-
84
- Ok ( ( ) )
109
+ progress_callback,
110
+ ) . await {
111
+ Ok ( ( ) ) => Ok ( ( ) ) ,
112
+ Err ( err) => {
113
+ dbg ! ( & err) ;
114
+ let payload = ErrorPayload {
115
+ uuid : input_uuid,
116
+ message : err. to_string ( ) ,
117
+ } ;
118
+ window. emit ( "process-error" , payload) . unwrap ( ) ;
119
+ Err ( err)
120
+ }
121
+ }
85
122
} ) ;
86
123
124
+ dbg ! ( "hello yes" ) ;
125
+
87
126
tasks. push ( task) ;
88
127
}
89
128
0 commit comments