Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit c1ae187

Browse files
committed
Alive Message to Mixpanel with flag (#1637)
1 parent 0eb64c8 commit c1ae187

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

src/js/lib/content/src/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import cfg from '../../../config'
1313
// @ts-ignore
1414
import assert from 'assert'
1515

16-
// =================
17-
// === Constants ===
18-
// =================
19-
20-
const ALIVE_LOG_INTERVAL = 1000 * 60
21-
2216
// ==================
2317
// === Global API ===
2418
// ==================
@@ -587,10 +581,6 @@ API.main = async function (inputConfig: any) {
587581

588582
API.initLogging(config)
589583

590-
window.setInterval(() => {
591-
API.remoteLog('alive')
592-
}, ALIVE_LOG_INTERVAL)
593-
594584
// Build data injected during the build process. See `webpack.config.js` for the source.
595585
// @ts-ignore
596586
const hash = GIT_HASH

src/rust/ide/src/ide.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use crate::prelude::*;
77
use crate::controller::project::INITIAL_MODULE_NAME;
88
use crate::ide::integration::Integration;
99

10+
use analytics::AnonymousData;
11+
use enso_frp as frp;
1012
use ensogl::application::Application;
13+
use ensogl::system::web::sleep;
14+
use std::time::Duration;
1115

1216
pub use initializer::Initializer;
1317

@@ -21,6 +25,8 @@ pub use initializer::Initializer;
2125
pub const BACKEND_DISCONNECTED_MESSAGE:&str =
2226
"Connection to the backend has been lost. Please try restarting IDE.";
2327

28+
const ALIVE_LOG_INTERVAL_SEC:u64 = 60;
29+
2430

2531

2632
// ===========
@@ -35,6 +41,7 @@ pub const BACKEND_DISCONNECTED_MESSAGE:&str =
3541
pub struct Ide {
3642
application : Application,
3743
integration : Integration,
44+
network : frp::Network,
3845
}
3946

4047
impl Ide {
@@ -43,7 +50,39 @@ impl Ide {
4350
(application:Application, view:ide_view::project::View, controller:controller::Ide)
4451
-> Self {
4552
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+
}
4786
}
4887
}
4988

0 commit comments

Comments
 (0)