1
1
#![ cfg_attr( not( debug_assertions) , windows_subsystem = "windows" ) ]
2
2
3
+ use reqwest:: multipart:: { Form , Part } ;
3
4
use sentry_tracing:: EventFilter ;
4
5
use specta_typescript:: Typescript ;
5
- use std:: path :: PathBuf ;
6
+ use std:: sync :: atomic :: Ordering ;
6
7
use std:: sync:: Arc ;
8
+ use std:: time:: Instant ;
7
9
use std:: vec;
10
+ use std:: { path:: PathBuf , sync:: atomic:: AtomicBool } ;
11
+ use atomic_float:: AtomicF64 ;
12
+
8
13
use tauri:: {
9
14
tray:: { MouseButton , MouseButtonState } ,
10
15
Emitter , Manager ,
@@ -34,6 +39,9 @@ use ffmpeg_sidecar::{
34
39
35
40
use winit:: monitor:: { MonitorHandle , VideoMode } ;
36
41
42
+ static UPLOAD_SPEED : AtomicF64 = AtomicF64 :: new ( 0.0 ) ;
43
+ static HEALTH_CHECK : AtomicBool = AtomicBool :: new ( false ) ;
44
+
37
45
fn main ( ) {
38
46
let _ = fix_path_env:: fix ( ) ;
39
47
@@ -101,6 +109,37 @@ fn main() {
101
109
Ok ( ( ) )
102
110
}
103
111
112
+ async fn perform_health_check_and_calculate_upload_speed ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
113
+ let client = reqwest:: Client :: new ( ) ;
114
+ let sample_screen_recording = vec ! [ 0u8 ; 1_000_000 ] ;
115
+
116
+ let health_check_url_base: & ' static str = dotenvy_macro:: dotenv!( "NEXT_PUBLIC_URL" ) ;
117
+ let health_check_url = format ! ( "{}/api/health-check" , health_check_url_base) ;
118
+
119
+ let form = Form :: new ( ) . part (
120
+ "file" ,
121
+ Part :: bytes ( sample_screen_recording. clone ( ) )
122
+ . file_name ( "sample_screen_recording.webm" )
123
+ . mime_str ( "video/webm" ) ?,
124
+ ) ;
125
+ let start_time = Instant :: now ( ) ;
126
+ let resp = client. post ( health_check_url) . multipart ( form) . send ( ) . await ?;
127
+ let time_elapsed = start_time. elapsed ( ) ;
128
+
129
+ let is_success = resp. status ( ) . is_success ( ) ;
130
+ HEALTH_CHECK . store ( is_success, Ordering :: Relaxed ) ;
131
+
132
+ if is_success {
133
+ let upload_speed = ( sample_screen_recording. len ( ) as f64 / time_elapsed. as_secs_f64 ( ) ) / 1250000.0 ;
134
+ UPLOAD_SPEED . store ( upload_speed, Ordering :: Relaxed ) ;
135
+ tracing:: debug!( "Health check successful. Upload speed: {} Mbps" , upload_speed) ;
136
+ } else {
137
+ tracing:: debug!( "Health check failed." ) ;
138
+ }
139
+
140
+ Ok ( ( ) )
141
+ }
142
+
104
143
if let Err ( error) = handle_ffmpeg_installation ( ) {
105
144
tracing:: error!( error) ;
106
145
// TODO: UI message instead
@@ -141,7 +180,9 @@ fn main() {
141
180
reset_microphone_permissions,
142
181
reset_camera_permissions,
143
182
close_webview,
144
- make_webview_transparent
183
+ make_webview_transparent,
184
+ get_health_check_status,
185
+ get_upload_speed
145
186
] ) ;
146
187
147
188
#[ cfg( debug_assertions) ] // <- Only export on non-release builds
@@ -156,6 +197,14 @@ fn main() {
156
197
. plugin ( tauri_plugin_global_shortcut:: Builder :: new ( ) . build ( ) )
157
198
. invoke_handler ( specta_builder. invoke_handler ( ) )
158
199
. setup ( move |app| {
200
+ tracing:: info!( "Setting up application..." ) ;
201
+
202
+ tauri:: async_runtime:: spawn ( async {
203
+ if let Err ( error) = perform_health_check_and_calculate_upload_speed ( ) . await {
204
+ tracing:: error!( "Health check and upload speed calculation failed: {}" , error) ;
205
+ }
206
+ } ) ;
207
+
159
208
let handle = app. handle ( ) ;
160
209
161
210
if let Some ( main_window) = app. get_webview_window ( "main" ) {
0 commit comments