Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Aug 6, 2024
2 parents 2946f94 + c8506e1 commit d12ab94
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 64 deletions.
16 changes: 15 additions & 1 deletion src-tauri/src/xmrig/latest_release.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use log::info;
use serde::Deserialize;

const LOG_TARGET: &str = "tari::universe::xmrig::latest_release";
#[derive(Debug, Deserialize)]
pub struct Asset {
os: Option<String>,
Expand All @@ -21,7 +23,19 @@ pub struct XmrigRelease {

impl XmrigRelease {
pub fn get_asset(&self, os: &str) -> Option<&Asset> {
self.assets.iter().find(|a| a.os.as_deref() == Some(os))
for asset in &self.assets {
info!(target: LOG_TARGET, "Checking asset {:?}", asset);
// macos-arm64 doesn't have an os field for some reason
if asset.os.is_none() {
if asset.id == os {
return Some(asset);
}
}
if asset.os.as_deref() == Some(os) {
return Some(asset);
}
}
return None;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/xmrig_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ use crate::download_utils::{download_file, extract};
use crate::xmrig::http_api::XmrigHttpApiClient;
use crate::xmrig::latest_release::fetch_latest_release;
use anyhow::Error;
use log::info;
use std::path::PathBuf;
use tari_shutdown::Shutdown;
use tokio::fs;
use tokio::runtime::Handle;
use tokio::sync::mpsc::Receiver;
use tokio::task::JoinHandle;

const LOG_TARGET: &str = "tari::universe::xmrig_adapter";

pub enum XmrigNodeConnection {
LocalMmproxy { host_name: String, port: u16 },
}
Expand Down Expand Up @@ -153,8 +156,10 @@ impl XmrigAdapter {
}
}

let os_string = get_os_string();
info!(target: LOG_TARGET, "Downloading xmrig for {}", &os_string);
let platform = latest_release
.get_asset(&get_os_string())
.get_asset(&os_string)
.ok_or(anyhow::anyhow!("Failed to get platform asset"))?;
println!("Downloading file");
println!("Downloading file from {}", &platform.url);
Expand Down Expand Up @@ -220,6 +225,8 @@ fn get_os_string() -> String {
#[cfg(target_arch = "aarch64")]
{
return "macos-arm64".to_string();
// TODO: confirm whether to use the macos-x64 or macos-arm64
// return "macos-x64".to_string();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Tari Universe",
"version": "0.1.19"
"version": "0.1.20"
},
"tauri": {
"updater": {
Expand Down
39 changes: 37 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './theme/theme.css';
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
import { invoke } from '@tauri-apps/api/tauri';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
Expand All @@ -12,13 +12,48 @@ import { AppBackground } from './containers/AppBackground';
import ErrorSnackbar from './containers/Error/ErrorSnackbar';
import { useUIStore } from './store/useUIStore.ts';
import { useGetStatus } from './hooks/useGetStatus.ts';
import { listen } from '@tauri-apps/api/event';
import { TauriEvent } from './types.ts';
import useAppStateStore from './store/appStateStore.ts';

function App() {
const background = useUIStore((s) => s.background);
const view = useUIStore((s) => s.view);
const startupInitiated = useRef(false);
const setSetupDetails = useAppStateStore((s) => s.setSetupDetails);
const settingUpFinished = useAppStateStore((s) => s.settingUpFinished);

useEffect(() => {
invoke('setup_application');
const unlistenPromise = listen(
'message',
({ event, payload }: TauriEvent) => {
console.log('Event:', event, payload);
switch (payload.event_type) {
case 'setup_status':
setSetupDetails(payload.title, payload.progress);
if (payload.progress >= 1.0) {
settingUpFinished();
}
break;
default:
console.log('Unknown tauri event: ', {
event,
payload,
});
break;
}
}
);
if (!startupInitiated.current) {
invoke('setup_application').then((r) => {
console.log(r);
startupInitiated.current = true;
});
}

return () => {
unlistenPromise.then((unlisten) => unlisten());
};
}, []);

useGetStatus();
Expand Down
6 changes: 4 additions & 2 deletions src/containers/SideBar/Miner/components/ModeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { IoCode } from 'react-icons/io5';
import { Typography } from '@mui/material';
import { TileItem } from '../styles';
import { useAppStatusStore } from '../../../../store/useAppStatusStore.ts';
import { useTheme } from '@mui/material/styles';

const CustomSelect = styled(Select)(({ theme }) => ({
const CustomSelect = styled(Select)(({ theme }: { theme: any }) => ({
'& .MuiSelect-select': {
padding: 0,
textTransform: 'uppercase',
Expand All @@ -28,14 +29,15 @@ function ModeSelect() {
const handleChange = (event: SelectChangeEvent<unknown>) => {
setMode(event.target.value as modeType);
};

const theme = useTheme();
return (
<TileItem>
<Typography variant="body2">Mode</Typography>
<FormControl fullWidth>
<CustomSelect
labelId="select-mode-label"
id="select-mode"
theme={theme}
value={mode}
onChange={handleChange}
IconComponent={IoCode}
Expand Down
87 changes: 30 additions & 57 deletions src/hooks/useGetStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { listen } from '@tauri-apps/api/event';
import { TauriEvent } from '../types.ts';
import useAppStateStore from '../store/appStateStore.ts';
import { useEffect } from 'react';
import { invoke } from '@tauri-apps/api/tauri';
Expand All @@ -12,63 +10,38 @@ const INTERVAL = 1000;
export function useGetStatus() {
const setBalance = useWalletStore((state) => state.setBalance);
const setAppStatus = useAppStatusStore((s) => s.setAppStatus);
const setSetupDetails = useAppStateStore((s) => s.setSetupDetails);
const setError = useAppStateStore((s) => s.setError);
const settingUpFinished = useAppStateStore((s) => s.settingUpFinished);
const isSettingUp = useAppStateStore((s) => s.isSettingUp);

const unlistenPromise = listen(
'message',
({ event, payload }: TauriEvent) => {
console.log('some kind of event', event, payload);

switch (payload.event_type) {
case 'setup_status':
setSetupDetails(payload.title, payload.progress);
if (payload.progress >= 1.0) {
settingUpFinished();
}
break;
default:
console.log('Unknown tauri event: ', { event, payload });
break;
}
}
);

useEffect(() => {
if (!isSettingUp) {
const intervalId = setInterval(() => {
invoke<AppStatus>('status', {})
.then((status: AppStatus) => {
console.debug('Status', status);
if (status) {
setAppStatus(status);
const wallet_balance = status.wallet_balance;
const {
available_balance = 0,
timelocked_balance = 0,
pending_incoming_balance = 0,
} = wallet_balance || {};
const intervalId = setInterval(() => {
invoke<AppStatus>('status', {})
.then((status: AppStatus) => {
console.debug('Status', status);
if (status) {
setAppStatus(status);
const wallet_balance = status.wallet_balance;
const {
available_balance = 0,
timelocked_balance = 0,
pending_incoming_balance = 0,
} = wallet_balance || {};

setBalance(
available_balance +
timelocked_balance +
pending_incoming_balance
);
} else {
console.error('Could not get status');
}
})
.catch((e) => {
console.error('Could not get status', e);
setError(e.toString());
});
}, INTERVAL);
return () => {
unlistenPromise.then((unlisten) => unlisten());
clearInterval(intervalId);
};
}
}, [isSettingUp]);
setBalance(
available_balance +
timelocked_balance +
pending_incoming_balance
);
} else {
console.error('Could not get status');
}
})
.catch((e) => {
console.error('Could not get status', e);
setError(e.toString());
});
}, INTERVAL);
return () => {
clearInterval(intervalId);
};
}, []);
}

0 comments on commit d12ab94

Please sign in to comment.