@@ -7,7 +7,11 @@ use crate::prelude::*;
7
7
use crate :: controller:: project:: INITIAL_MODULE_NAME ;
8
8
use crate :: ide:: integration:: Integration ;
9
9
10
+ use analytics:: AnonymousData ;
11
+ use enso_frp as frp;
10
12
use ensogl:: application:: Application ;
13
+ use ensogl:: system:: web:: sleep;
14
+ use std:: time:: Duration ;
11
15
12
16
pub use initializer:: Initializer ;
13
17
@@ -21,6 +25,8 @@ pub use initializer::Initializer;
21
25
pub const BACKEND_DISCONNECTED_MESSAGE : & str =
22
26
"Connection to the backend has been lost. Please try restarting IDE." ;
23
27
28
+ const ALIVE_LOG_INTERVAL_SEC : u64 = 60 ;
29
+
24
30
25
31
26
32
// ===========
@@ -35,6 +41,7 @@ pub const BACKEND_DISCONNECTED_MESSAGE:&str =
35
41
pub struct Ide {
36
42
application : Application ,
37
43
integration : Integration ,
44
+ network : frp:: Network ,
38
45
}
39
46
40
47
impl Ide {
@@ -43,7 +50,39 @@ impl Ide {
43
50
( application : Application , view : ide_view:: project:: View , controller : controller:: Ide )
44
51
-> Self {
45
52
let integration = integration:: Integration :: new ( controller, view) ;
46
- Ide { application, integration}
53
+ let network = frp:: Network :: new ( "Ide" ) ;
54
+ Ide { application, integration, network} . init ( )
55
+ }
56
+
57
+ fn init ( self ) -> Self {
58
+ executor:: global:: spawn ( self . alive_log_sending_loop ( ) ) ;
59
+ self
60
+ }
61
+
62
+ fn alive_log_sending_loop ( & self ) -> impl Future < Output =( ) > + ' static {
63
+ let network = & self . network ;
64
+ let scene = self . application . display . scene ( ) ;
65
+ let mouse = & scene. mouse . frp ;
66
+ let keyboard = & scene. keyboard . frp ;
67
+
68
+ enso_frp:: extend! { TRACE_ALL network
69
+ on_log_sent <- source:: <( ) >( ) ;
70
+ mouse_moved <- mouse. position. constant( ( ) ) ;
71
+ any_mouse_press <- any( mouse. up, mouse. down) . constant( ( ) ) ;
72
+ any_mouse_event <- any( any_mouse_press, mouse_moved, mouse. wheel) ;
73
+ any_keyboard_event <- any( keyboard. down, keyboard. up) . constant( ( ) ) ;
74
+ any_input_event <- any( any_mouse_event, any_keyboard_event) ;
75
+ // True if any input event was captured since the last "alive" log sending.
76
+ input_event_received <- bool ( & on_log_sent, & any_input_event) . sampler( ) ;
77
+ }
78
+ async move {
79
+ loop {
80
+ let value = AnonymousData ( input_event_received. value ( ) ) ;
81
+ analytics:: remote_log_value ( "alive" , "input_event_received" , value) ;
82
+ on_log_sent. emit ( ( ) ) ;
83
+ sleep ( Duration :: from_secs ( ALIVE_LOG_INTERVAL_SEC ) ) . await ;
84
+ }
85
+ }
47
86
}
48
87
}
49
88
0 commit comments