From c1ae1876fe4964d8ea706c15fcb8177ebeb022d8 Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Tue, 22 Jun 2021 14:04:30 +0200 Subject: [PATCH] Alive Message to Mixpanel with flag (#1637) --- src/js/lib/content/src/index.ts | 10 -------- src/rust/ide/src/ide.rs | 41 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/js/lib/content/src/index.ts b/src/js/lib/content/src/index.ts index 378ac64c84..8b9fca13d4 100644 --- a/src/js/lib/content/src/index.ts +++ b/src/js/lib/content/src/index.ts @@ -13,12 +13,6 @@ import cfg from '../../../config' // @ts-ignore import assert from 'assert' -// ================= -// === Constants === -// ================= - -const ALIVE_LOG_INTERVAL = 1000 * 60 - // ================== // === Global API === // ================== @@ -587,10 +581,6 @@ API.main = async function (inputConfig: any) { API.initLogging(config) - window.setInterval(() => { - API.remoteLog('alive') - }, ALIVE_LOG_INTERVAL) - // Build data injected during the build process. See `webpack.config.js` for the source. // @ts-ignore const hash = GIT_HASH diff --git a/src/rust/ide/src/ide.rs b/src/rust/ide/src/ide.rs index e84c0a2e83..8a46e31bbc 100644 --- a/src/rust/ide/src/ide.rs +++ b/src/rust/ide/src/ide.rs @@ -7,7 +7,11 @@ use crate::prelude::*; use crate::controller::project::INITIAL_MODULE_NAME; use crate::ide::integration::Integration; +use analytics::AnonymousData; +use enso_frp as frp; use ensogl::application::Application; +use ensogl::system::web::sleep; +use std::time::Duration; pub use initializer::Initializer; @@ -21,6 +25,8 @@ pub use initializer::Initializer; pub const BACKEND_DISCONNECTED_MESSAGE:&str = "Connection to the backend has been lost. Please try restarting IDE."; +const ALIVE_LOG_INTERVAL_SEC:u64 = 60; + // =========== @@ -35,6 +41,7 @@ pub const BACKEND_DISCONNECTED_MESSAGE:&str = pub struct Ide { application : Application, integration : Integration, + network : frp::Network, } impl Ide { @@ -43,7 +50,39 @@ impl Ide { (application:Application, view:ide_view::project::View, controller:controller::Ide) -> Self { let integration = integration::Integration::new(controller,view); - Ide {application,integration} + let network = frp::Network::new("Ide"); + Ide {application,integration,network} . init() + } + + fn init(self) -> Self { + executor::global::spawn(self.alive_log_sending_loop()); + self + } + + fn alive_log_sending_loop(&self) -> impl Future + 'static { + let network = &self.network; + let scene = self.application.display.scene(); + let mouse = &scene.mouse.frp; + let keyboard = &scene.keyboard.frp; + + enso_frp::extend! { TRACE_ALL network + on_log_sent <- source::<()>(); + mouse_moved <- mouse.position.constant(()); + any_mouse_press <- any(mouse.up,mouse.down).constant(()); + any_mouse_event <- any(any_mouse_press,mouse_moved,mouse.wheel); + any_keyboard_event <- any(keyboard.down,keyboard.up).constant(()); + any_input_event <- any(any_mouse_event,any_keyboard_event); + // True if any input event was captured since the last "alive" log sending. + input_event_received <- bool(&on_log_sent,&any_input_event).sampler(); + } + async move { + loop { + let value = AnonymousData(input_event_received.value()); + analytics::remote_log_value("alive", "input_event_received",value); + on_log_sent.emit(()); + sleep(Duration::from_secs(ALIVE_LOG_INTERVAL_SEC)).await; + } + } } }