2020-06-25 00:24:46 +03:00
|
|
|
//! This module contains the IDE object implementation.
|
2021-12-15 13:40:14 +03:00
|
|
|
|
2020-06-25 00:24:46 +03:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2021-12-15 13:40:14 +03:00
|
|
|
use crate::presenter::Presenter;
|
2020-06-25 00:24:46 +03:00
|
|
|
|
2021-06-22 15:04:30 +03:00
|
|
|
use analytics::AnonymousData;
|
|
|
|
use enso_frp as frp;
|
|
|
|
use ensogl::system::web::sleep;
|
|
|
|
use std::time::Duration;
|
2020-12-22 18:57:24 +03:00
|
|
|
|
2020-12-08 15:19:31 +03:00
|
|
|
|
2022-03-10 07:32:33 +03:00
|
|
|
// ==============
|
|
|
|
// === Export ===
|
|
|
|
// ==============
|
|
|
|
|
|
|
|
pub mod initializer;
|
|
|
|
|
|
|
|
pub use initializer::Initializer;
|
|
|
|
|
|
|
|
|
2020-12-08 15:19:31 +03:00
|
|
|
|
|
|
|
// =================
|
|
|
|
// === Constants ===
|
|
|
|
// =================
|
|
|
|
|
2021-03-12 14:56:33 +03:00
|
|
|
/// Text that shows up in the statusbar when any of the backend connections is lost.
|
2021-11-02 16:05:43 +03:00
|
|
|
pub const BACKEND_DISCONNECTED_MESSAGE: &str =
|
2021-03-12 14:56:33 +03:00
|
|
|
"Connection to the backend has been lost. Please try restarting IDE.";
|
|
|
|
|
2021-11-02 16:05:43 +03:00
|
|
|
const ALIVE_LOG_INTERVAL_SEC: u64 = 60;
|
2021-06-22 15:04:30 +03:00
|
|
|
|
2020-06-25 00:24:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// === Ide ===
|
|
|
|
// ===========
|
|
|
|
|
2020-12-22 18:57:24 +03:00
|
|
|
/// The main Ide structure.
|
|
|
|
///
|
|
|
|
/// This structure is a root of all objects in our application. It includes both layers:
|
|
|
|
/// Controllers and Views, and an integration between them.
|
2022-02-11 15:19:02 +03:00
|
|
|
#[allow(missing_docs)]
|
2020-06-25 00:24:46 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Ide {
|
2022-02-11 15:19:02 +03:00
|
|
|
pub ensogl_app: ensogl::application::Application,
|
|
|
|
pub presenter: Presenter,
|
|
|
|
network: frp::Network,
|
2020-06-25 00:24:46 +03:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:57:24 +03:00
|
|
|
impl Ide {
|
|
|
|
/// Constructor.
|
2022-02-11 15:19:02 +03:00
|
|
|
pub fn new(
|
|
|
|
ensogl_app: ensogl::application::Application,
|
2021-11-30 18:23:46 +03:00
|
|
|
view: ide_view::root::View,
|
2021-11-02 16:05:43 +03:00
|
|
|
controller: controller::Ide,
|
|
|
|
) -> Self {
|
2021-12-29 15:44:13 +03:00
|
|
|
let presenter = Presenter::new(controller, view);
|
2021-11-02 16:05:43 +03:00
|
|
|
let network = frp::Network::new("Ide");
|
2022-02-11 15:19:02 +03:00
|
|
|
Ide { ensogl_app, presenter, network }.init()
|
2021-06-22 15:04:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn init(self) -> Self {
|
|
|
|
executor::global::spawn(self.alive_log_sending_loop());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-11-02 16:05:43 +03:00
|
|
|
fn alive_log_sending_loop(&self) -> impl Future<Output = ()> + 'static {
|
|
|
|
let network = &self.network;
|
2022-03-04 17:13:23 +03:00
|
|
|
let scene = &self.ensogl_app.display.default_scene;
|
2021-11-02 16:05:43 +03:00
|
|
|
let mouse = &scene.mouse.frp;
|
2021-06-22 15:04:30 +03:00
|
|
|
let keyboard = &scene.keyboard.frp;
|
|
|
|
|
2021-07-06 10:42:08 +03:00
|
|
|
enso_frp::extend! { network
|
2021-06-22 15:04:30 +03:00
|
|
|
on_log_sent <- source::<()>();
|
2022-05-16 15:28:50 +03:00
|
|
|
mouse_moved <- mouse.position.constant(()).profile();
|
|
|
|
any_mouse_press <- any(mouse.up,mouse.down).constant(()).profile();
|
|
|
|
any_mouse_event <- any(any_mouse_press,mouse_moved,mouse.wheel).profile();
|
|
|
|
any_keyboard_event <- any(keyboard.down,keyboard.up).constant(()).profile();
|
|
|
|
any_input_event <- any(any_mouse_event,any_keyboard_event).profile();
|
2021-06-22 15:04:30 +03:00
|
|
|
// True if any input event was captured since the last "alive" log sending.
|
2022-05-16 15:28:50 +03:00
|
|
|
input_event_received <- bool(&on_log_sent,&any_input_event).profile().sampler();
|
2021-06-22 15:04:30 +03:00
|
|
|
}
|
|
|
|
async move {
|
|
|
|
loop {
|
|
|
|
let value = AnonymousData(input_event_received.value());
|
2021-11-02 16:05:43 +03:00
|
|
|
analytics::remote_log_value("alive", "input_event_received", value);
|
2021-06-22 15:04:30 +03:00
|
|
|
on_log_sent.emit(());
|
|
|
|
sleep(Duration::from_secs(ALIVE_LOG_INTERVAL_SEC)).await;
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 00:24:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-11 15:19:02 +03:00
|
|
|
/// A reduced version of [`Ide`] structure, representing an application which failed to initialize.
|
|
|
|
///
|
|
|
|
/// It contains only the view displaying the error. No connection to the backend is maintained.
|
|
|
|
#[allow(missing_docs)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct FailedIde {
|
|
|
|
pub view: ide_view::root::View,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-21 16:24:17 +03:00
|
|
|
/// The Path of the module initially opened after opening project in IDE.
|
2022-10-03 13:54:09 +03:00
|
|
|
pub fn initial_module_path(project: &model::Project) -> model::module::Path {
|
|
|
|
project.main_module_path()
|
2020-12-22 18:57:24 +03:00
|
|
|
}
|