Skip to content

Commit

Permalink
fix: issues around telemetry_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
BalazsSevecsek committed Aug 29, 2024
1 parent 88a50d9 commit 598b528
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 166 deletions.
29 changes: 0 additions & 29 deletions src-tauri/src/analytics.rs

This file was deleted.

49 changes: 12 additions & 37 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ pub struct AppConfigFromFile {
pub auto_mining: bool,
pub user_inactivity_timeout: Duration,
pub last_binaries_update_timestamp: SystemTime,
pub allow_analytics: bool,
pub allow_telemetry: bool,
pub anon_id: String,
pub telemetry_collection: bool,
pub airdrop_user_refresh_token: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -55,10 +53,8 @@ pub struct AppConfig {
pub auto_mining: bool,
pub user_inactivity_timeout: Duration,
pub last_binaries_update_timestamp: SystemTime,
pub allow_analytics: bool,
pub allow_telemetry: bool,
pub anon_id: String,
pub telemetry_collection: bool,
pub airdrop_user_refresh_token: Option<String>,
}

impl AppConfig {
Expand All @@ -70,10 +66,8 @@ impl AppConfig {
auto_mining: false,
user_inactivity_timeout: Duration::from_secs(60),
last_binaries_update_timestamp: SystemTime::now(),
allow_analytics: true,
allow_telemetry: true,
anon_id: generate_password(20),
telemetry_collection: true,
airdrop_user_refresh_token: None,
}
}

Expand All @@ -90,17 +84,15 @@ impl AppConfig {
self.auto_mining = config.auto_mining;
self.user_inactivity_timeout = config.user_inactivity_timeout;
self.last_binaries_update_timestamp = config.last_binaries_update_timestamp;
self.allow_analytics = config.allow_analytics;
self.allow_telemetry = config.allow_telemetry;
self.anon_id = config.anon_id;
self.version = config.version;
if self.version == 0 {
// migrate
self.version = 1;
self.allow_analytics = true;
self.allow_telemetry = true;
self.anon_id = generate_password(20);
}
self.telemetry_collection = config.telemetry_collection;
self.airdrop_user_refresh_token = config.airdrop_user_refresh_token;
}
Err(e) => {
warn!(target: LOG_TARGET, "Failed to parse app config: {}", e.to_string());
Expand All @@ -114,10 +106,8 @@ impl AppConfig {
user_inactivity_timeout: self.user_inactivity_timeout,
last_binaries_update_timestamp: self.last_binaries_update_timestamp,
version: self.version,
allow_analytics: self.allow_analytics,
allow_telemetry: self.allow_telemetry,
anon_id: self.anon_id.clone(),
telemetry_collection: true,
airdrop_user_refresh_token: None,
};
let config = serde_json::to_string(&config)?;
fs::write(file, config).await?;
Expand Down Expand Up @@ -149,30 +139,17 @@ impl AppConfig {
self.auto_mining
}

pub async fn set_telemetry_collection(
pub async fn set_allow_telemetry(
&mut self,
telemetry_collection: bool,
allow_telemetry: bool,
) -> Result<(), anyhow::Error> {
self.telemetry_collection = telemetry_collection;
self.allow_telemetry = allow_telemetry;
self.update_config_file().await?;
Ok(())
}

pub fn get_telemetry_collection(&self) -> bool {
self.telemetry_collection
}

pub async fn set_airdrop_user_refresh_token(
&mut self,
airdrop_user_refresh_token: Option<String>,
) -> Result<(), anyhow::Error> {
self.airdrop_user_refresh_token = airdrop_user_refresh_token;
self.update_config_file().await?;
Ok(())
}

pub fn get_airdrop_user_refresh_token(&self) -> Option<String> {
self.airdrop_user_refresh_token.clone()
pub fn get_allow_telemetry(&self) -> bool {
self.allow_telemetry
}

pub fn get_user_inactivity_timeout(&self) -> Duration {
Expand Down Expand Up @@ -209,10 +186,8 @@ impl AppConfig {
user_inactivity_timeout: self.user_inactivity_timeout,
last_binaries_update_timestamp: self.last_binaries_update_timestamp,
version: self.version,
allow_analytics: self.allow_analytics,
allow_telemetry: self.allow_telemetry,
anon_id: self.anon_id.clone(),
telemetry_collection: self.telemetry_collection,
airdrop_user_refresh_token: self.airdrop_user_refresh_token.clone(),
};
let config = serde_json::to_string(config)?;
info!(target: LOG_TARGET, "Updating config file: {:?} {:?}", file, self.clone());
Expand Down
21 changes: 11 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod analytics;
mod app_config;
mod binary_resolver;
mod consts;
Expand Down Expand Up @@ -36,7 +35,6 @@ use crate::user_listener::UserListener;
use crate::wallet_adapter::WalletBalance;
use crate::wallet_manager::WalletManager;
use crate::xmrig_adapter::XmrigAdapter;
use analytics::AnalyticsManager;
use app_config::{AppConfig, MiningMode};
use binary_resolver::{Binaries, BinaryResolver};
use hardware_monitor::{HardwareMonitor, HardwareStatus};
Expand Down Expand Up @@ -110,7 +108,7 @@ async fn set_telemetry_mode<'r>(
.config
.write()
.await
.set_telemetry_collection(telemetry_mode)
.set_allow_telemetry(telemetry_mode)
.await
.map_err(|e| e.to_string());
Ok(())
Expand Down Expand Up @@ -278,18 +276,24 @@ async fn setup_inner<'r>(

let base_node_grpc_port = state.node_manager.get_grpc_port().await?;

let mut analytics_id = state.analytics_manager.get_unique_string().await;
if analytics_id.is_empty() {
analytics_id = "unknown_miner_tari_universe".to_string();
let mut telemetry_id = state
.telemetry_manager
.read()
.await
.get_unique_string()
.await;
if telemetry_id.is_empty() {
telemetry_id = "unknown_miner_tari_universe".to_string();
}

mm_proxy_manager
.start(
state.shutdown.to_signal().clone(),
app.path_resolver().app_local_data_dir().unwrap().clone(),
app.path_resolver().app_log_dir().unwrap().clone(),
cpu_miner_config.tari_address.clone(),
base_node_grpc_port,
analytics_id,
telemetry_id,
)
.await?;
mm_proxy_manager.wait_ready().await?;
Expand Down Expand Up @@ -606,7 +610,6 @@ struct UniverseAppState {
mm_proxy_manager: MmProxyManager,
node_manager: NodeManager,
wallet_manager: WalletManager,
analytics_manager: AnalyticsManager,
telemetry_manager: Arc<RwLock<TelemetryManager>>,
airdrop_access_token: Arc<RwLock<Option<String>>>,
}
Expand Down Expand Up @@ -638,7 +641,6 @@ fn main() {
}));

let app_config = Arc::new(RwLock::new(AppConfig::new()));
let analytics = AnalyticsManager::new(app_config.clone());

let cpu_miner: Arc<RwLock<CpuMiner>> = Arc::new(CpuMiner::new().into());
let gpu_miner: Arc<RwLock<GpuMiner>> = Arc::new(GpuMiner::new().into());
Expand All @@ -661,7 +663,6 @@ fn main() {
mm_proxy_manager: mm_proxy_manager.clone(),
node_manager,
wallet_manager,
analytics_manager: analytics,
telemetry_manager: Arc::new(RwLock::new(telemetry_manager)),
airdrop_access_token: Arc::new(RwLock::new(None)),
};
Expand Down
8 changes: 1 addition & 7 deletions src-tauri/src/mm_proxy_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::binary_resolver::{Binaries, BinaryResolver};
use crate::consts::PROCESS_CREATION_NO_WINDOW;
use crate::process_adapter::{ProcessAdapter, ProcessInstance, StatusMonitor};
use crate::process_utils;
use anyhow::Error;
Expand Down Expand Up @@ -71,12 +70,7 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
.resolve_path(Binaries::MergeMiningProxy)
.await?;
crate::download_utils::set_permissions(&file_path).await?;
let mut child = tokio::process::Command::new(file_path)
.args(args)
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.kill_on_drop(true)
.spawn()?;
let mut child = process_utils::launch_child_process(&file_path, &args)?;

if let Some(id) = child.id() {
fs::write(data_dir.join("mmproxy_pid"), id.to_string())?;
Expand Down
7 changes: 1 addition & 6 deletions src-tauri/src/node_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ impl ProcessAdapter for MinotariNodeAdapter {
.resolve_path(Binaries::MinotariNode)
.await?;
crate::download_utils::set_permissions(&file_path).await?;
let mut child = tokio::process::Command::new(file_path)
.args(args)
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.kill_on_drop(true)
.spawn()?;
let mut child = process_utils::launch_child_process(&file_path, &args)?;

if let Some(id) = child.id() {
fs::write(data_dir.join("node_pid"), id.to_string())?;
Expand Down
Loading

0 comments on commit 598b528

Please sign in to comment.