Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): warnings and clippy errors #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- name: created empty dist dir
run: "mkdir dist"
- name: install dependencies (linux)
if: startsWith(runner.os,'Linux')
run: |
Expand Down
1 change: 0 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ sysinfo = "0.31.2"
log4rs = "1.3.0"


# static bind lzma
lzma-sys = { version = "0.1.0", features = ["static"] }
log = "0.4.22"


[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

[package.metadata.cargo-machete]
ignored = ["log4rs"]
9 changes: 3 additions & 6 deletions src-tauri/src/binary_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::download_utils::{download_file, extract};
use crate::github;
use crate::xmrig::latest_release::fetch_latest_release;
use anyhow::{anyhow, Error};
use async_trait::async_trait;
use semver::Version;
Expand Down Expand Up @@ -74,9 +73,7 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter {
let version = releases
.iter()
.filter_map(|v| {

if v.version.pre.starts_with(network) {

Some(&v.version)
} else {
None
Expand Down Expand Up @@ -104,9 +101,11 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter {
// TODO: add platform specific logic
#[cfg(target_os = "windows")]
let name_suffix = "windows-x64.exe.zip";

#[cfg(target_os = "macos")]
let name_suffix = "macos-arm64.zip";
#[cfg(target_os = "linux")]
let name_suffix = "linux-x86_64.zip";

let platform = version
.assets
.iter()
Expand Down Expand Up @@ -227,8 +226,6 @@ impl BinaryResolver {
Ok(latest_release.version)
}



fn get_os_string() -> String {
#[cfg(target_os = "windows")]
{
Expand Down
25 changes: 12 additions & 13 deletions src-tauri/src/cpu_miner.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use std::path::PathBuf;
use log::warn;
use sysinfo::{CpuRefreshKind, RefreshKind, System};
use crate::mm_proxy_manager::MmProxyManager;
use crate::xmrig::http_api::XmrigHttpApiClient;
use crate::xmrig_adapter::{XmrigAdapter, XmrigNodeConnection};
use crate::{CpuMinerConfig, CpuMinerConnection, CpuMinerConnectionStatus, CpuMinerStatus};
use log::warn;
use std::path::PathBuf;
use sysinfo::{CpuRefreshKind, RefreshKind, System};
use tari_shutdown::{Shutdown, ShutdownSignal};
use tauri::async_runtime::JoinHandle;
use tauri::Manager;
use tokio::select;
use tokio::time::MissedTickBehavior;


const LOG_TARGET: &str = "tari::universe::cpu_miner";
pub enum CpuMinerEvent {
Stdout(String),
Expand Down Expand Up @@ -39,7 +37,7 @@ impl CpuMiner {
mut app_shutdown: ShutdownSignal,
cpu_miner_config: &CpuMinerConfig,
local_mm_proxy: &MmProxyManager,
base_path: PathBuf
base_path: PathBuf,
) -> Result<(), anyhow::Error> {
if self.watcher_task.is_some() {
warn!(target: LOG_TARGET, "Tried to start mining twice");
Expand All @@ -50,7 +48,9 @@ impl CpuMiner {

let xmrig_node_connection = match cpu_miner_config.node_connection {
CpuMinerConnection::BuiltInProxy => {
local_mm_proxy.start(app_shutdown.clone(),base_path).await?;
local_mm_proxy
.start(app_shutdown.clone(), base_path)
.await?;
local_mm_proxy.wait_ready().await?;
XmrigNodeConnection::LocalMmproxy {
host_name: "127.0.0.1".to_string(),
Expand All @@ -61,7 +61,7 @@ impl CpuMiner {
}
};
let xmrig = XmrigAdapter::new(xmrig_node_connection, "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A".to_string() );
let (mut rx, mut xmrig_child, client) = xmrig.spawn()?;
let (mut _rx, mut xmrig_child, client) = xmrig.spawn()?;
self.api_client = Some(client);

self.watcher_task = Some(tauri::async_runtime::spawn(async move {
Expand Down Expand Up @@ -133,13 +133,12 @@ impl CpuMiner {
}

pub async fn status(&self) -> Result<CpuMinerStatus, anyhow::Error> {
let mut s = System::new_with_specifics(
RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
let mut s =
System::new_with_specifics(RefreshKind::new().with_cpu(CpuRefreshKind::everything()));

// Wait a bit because CPU usage is based on diff.
// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again.
// Refresh CPUs again.
s.refresh_cpu_all();

// let cpu_brand = s.get_global_processor_info().unwrap().brand().to_string();
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/download_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub async fn extract_gz(gz_path: &Path, dest_dir: &Path) -> std::io::Result<()>
Ok(())
}

use crate::xmrig::http_api::XmrigHttpApiClient;
use anyhow::anyhow;
use async_zip::base::read::seek::ZipFileReader;
use flate2::read::GzDecoder;
Expand Down
57 changes: 34 additions & 23 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,42 @@ mod process_adapter;
use crate::cpu_miner::CpuMiner;
use crate::mm_proxy_manager::MmProxyManager;
use crate::node_manager::NodeManager;
use log::{debug, error, info};
use serde::Serialize;
use std::sync::Arc;
use std::thread::sleep;
use std::{panic, process};
use tari_shutdown::Shutdown;
use tauri::{RunEvent, UpdaterEvent};
use tokio::sync::RwLock;
use log::{debug, error, info};
use tauri::{api, RunEvent, UpdaterEvent};

#[tauri::command]
async fn start_mining<'r>(
window: tauri::Window,
_window: tauri::Window,
state: tauri::State<'r, UniverseAppState>,
app: tauri::AppHandle,
) -> Result<(), String> {
let config = state.cpu_miner_config.read().await;
state
.node_manager
.ensure_started(state.shutdown.to_signal(), app.path_resolver().app_local_data_dir().unwrap())
.ensure_started(
state.shutdown.to_signal(),
app.path_resolver().app_local_data_dir().unwrap(),
)
.await
.map_err(|e| e.to_string())?;
let mm_proxy_manager = state.mm_proxy_manager.read().await;
state
.cpu_miner
.write()
.await
.start(state.shutdown.to_signal(), &config, &mm_proxy_manager, app.path_resolver().app_local_data_dir().unwrap()).await
.start(
state.shutdown.to_signal(),
&config,
&mm_proxy_manager,
app.path_resolver().app_local_data_dir().unwrap(),
)
.await
.map_err(|e| {
dbg!(e.to_string());
e.to_string()
Expand Down Expand Up @@ -86,7 +95,6 @@ async fn status(state: tauri::State<'_, UniverseAppState>) -> Result<AppStatus,
eprintln!("Error getting cpu miner status: {:?}", e);
return Err(e);
}

};
Ok(AppStatus { cpu })
}
Expand All @@ -101,7 +109,7 @@ pub struct AppStatus {
pub struct CpuMinerStatus {
pub is_mining: bool,
pub hash_rate: f64,
pub cpu_usage : u32,
pub cpu_usage: u32,
pub cpu_brand: String,
pub estimated_earnings: u64,
pub connection: CpuMinerConnectionStatus,
Expand Down Expand Up @@ -129,7 +137,7 @@ struct UniverseAppState {
node_manager: NodeManager,
}

pub const LOG_TARGET : &str = "tari::universe::main";
pub const LOG_TARGET: &str = "tari::universe::main";

fn main() {
let default_hook = panic::take_hook();
Expand All @@ -156,30 +164,33 @@ fn main() {
.build(tauri::generate_context!())
.expect("error while running tauri application");


tari_common::initialize_logging(
&app.path_resolver().app_config_dir().unwrap().join("log4rs_config.yml"),
&app.path_resolver()
.app_config_dir()
.unwrap()
.join("log4rs_config.yml"),
&app.path_resolver().app_log_dir().unwrap(),
include_str!("../log4rs_sample.yml"),
).expect("Could not set up logging");
include_str!("../log4rs_sample.yml"),
)
.expect("Could not set up logging");
info!(
target: LOG_TARGET,
"Starting Tari Universe version: {}",
app.package_info().version
);


println!("Logs stored at {:?}", app.path_resolver().app_log_dir().unwrap());
println!(
"Logs stored at {:?}",
app.path_resolver().app_log_dir().unwrap()
);

app.run(move |_app_handle, event| match event {
tauri::RunEvent::Updater(updater_event) => {
match updater_event {
UpdaterEvent::Error(e) => {
error!(target: LOG_TARGET, "Updater error: {:?}", e);
},
_ => {
info!(target: LOG_TARGET, "Updater event: {:?}", updater_event);
}
tauri::RunEvent::Updater(updater_event) => match updater_event {
UpdaterEvent::Error(e) => {
error!(target: LOG_TARGET, "Updater error: {:?}", e);
}
_ => {
info!(target: LOG_TARGET, "Updater event: {:?}", updater_event);
}
},
tauri::RunEvent::ExitRequested { api: _, .. } => {
Expand All @@ -190,7 +201,7 @@ fn main() {
sleep(std::time::Duration::from_secs(3));
info!(target: LOG_TARGET, "App shutdown complete");
}
RunEvent::MainEventsCleared=> {
RunEvent::MainEventsCleared => {
// no need to handle
}
_ => {
Expand Down
24 changes: 12 additions & 12 deletions src-tauri/src/merge_mining_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::path::PathBuf;
use crate::binary_resolver::{Binaries, BinaryResolver};
use crate::process_adapter::{ProcessAdapter, ProcessInstance, StatusMonitor};
use crate::xmrig_adapter::XmrigInstance;
use anyhow::Error;
use async_trait::async_trait;
use dirs_next::{cache_dir, data_dir, data_local_dir};
use dirs_next::data_local_dir;
use std::path::PathBuf;
use tari_shutdown::Shutdown;
use tokio::select;
use tokio::task::JoinHandle;
Expand All @@ -25,7 +24,10 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
type Instance = MergeMiningProxyInstance;
type StatusMonitor = MergeMiningProxyStatusMonitor;

fn spawn_inner(&self, log_folder: PathBuf) -> Result<(Self::Instance, Self::StatusMonitor), Error> {
fn spawn_inner(
&self,
log_folder: PathBuf,
) -> Result<(Self::Instance, Self::StatusMonitor), Error> {
let inner_shutdown = Shutdown::new();
let mut shutdown_signal = inner_shutdown.to_signal();

Expand Down Expand Up @@ -58,14 +60,12 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
let file_path = BinaryResolver::current()
.resolve_path(Binaries::MergeMiningProxy, &version)?;
crate::download_utils::set_permissions(&file_path).await?;
let mut child = tokio::process::Command::new(
file_path
)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;
let mut child = tokio::process::Command::new(file_path)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;

select! {
res = shutdown_signal =>{
Expand Down
Loading