Add session stats to desktop app

This commit is contained in:
Igor Katson 2024-08-21 13:22:22 +01:00
parent 857db0caf4
commit 93c53b4285
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 17 additions and 3 deletions

View file

@ -20,7 +20,7 @@ devserver:
echo -n '' > /tmp/rqbit-log && cargo run -- \
--log-file /tmp/rqbit-log \
--log-file-rust-log=debug,librqbit=trace \
server start --fastresume /tmp/scratch/
server start /tmp/scratch/
@PHONY: devserver
devserver-postgres:

View file

@ -57,7 +57,7 @@ mod peer_info_reader;
mod read_buf;
mod session;
mod session_persistence;
mod session_stats;
pub mod session_stats;
mod spawn_utils;
pub mod storage;
mod stream_connect;

View file

@ -1,5 +1,5 @@
import { createContext } from "react";
import { RqbitAPI } from "./api-types";
import { RqbitAPI, SessionStats } from "./api-types";
export const APIContext = createContext<RqbitAPI>({
listTorrents: () => {
@ -38,5 +38,8 @@ export const APIContext = createContext<RqbitAPI>({
getPlaylistUrl: function (index: number): string | null {
throw new Error("Function not implemented.");
},
stats: function (): Promise<SessionStats> {
throw new Error("Function not implemented.");
},
});
export const RefreshTorrentStatsContext = createContext({ refresh: () => {} });

View file

@ -19,6 +19,7 @@ use librqbit::{
TorrentListResponse, TorrentStats,
},
dht::PersistentDhtConfig,
session_stats::snapshot::SessionStatsSnapshot,
tracing_subscriber_config_utils::{init_logging, InitLoggingOptions, InitLoggingResult},
AddTorrent, AddTorrentOptions, Api, ApiError, PeerConnectionOptions, Session, SessionOptions,
SessionPersistenceConfig,
@ -318,6 +319,11 @@ async fn torrent_action_configure(
.await
}
#[tauri::command]
async fn stats(state: tauri::State<'_, State>) -> Result<SessionStatsSnapshot, ApiError> {
Ok(state.api()?.api_session_stats())
}
#[tauri::command]
fn get_version() -> &'static str {
env!("CARGO_PKG_VERSION")
@ -352,6 +358,7 @@ async fn start() {
torrent_action_start,
torrent_action_configure,
torrent_create_from_base64_file,
stats,
get_version,
config_default,
config_current,

View file

@ -6,6 +6,7 @@ import {
TorrentDetails,
TorrentStats,
ErrorDetails,
SessionStats,
} from "rqbit-webui/src/api-types";
import { InvokeArgs, invoke } from "@tauri-apps/api/tauri";
@ -141,5 +142,8 @@ export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
}
return `${httpBase}/torrents/${index}/playlist`;
},
stats: () => {
return invokeAPI<SessionStats>("stats");
},
};
};