Skip to content

Commit 28eca60

Browse files
committed
Add tracker download count column to torrents table
Issue #281
1 parent 4c58b85 commit 28eca60

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/components/modals/daemon.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,10 @@ export function DaemonSettingsModal(props: ModalState) {
607607
color: "green",
608608
});
609609
props.close();
610-
// clear client cache to make sure new interface settings are applied
611-
queryClient.clear();
610+
if (!TAURI) {
611+
// clear client cache to make sure new interface settings are applied
612+
queryClient.clear();
613+
}
612614
},
613615
onError: (error) => {
614616
notifications.show({

src/components/tables/torrenttable.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ const AllFields: readonly TableField[] = [
137137
columnId: "trackerStatus",
138138
accessorFn: (t) => t.cachedTrackerStatus,
139139
},
140+
{
141+
name: "trackerStats",
142+
label: "Tracker downloads",
143+
component: TrackerDownloadsField,
144+
columnId: "trackerDownloads",
145+
accessorFn: (t) => t.cachedTrackerDlCount,
146+
},
140147
{
141148
name: "errorString",
142149
label: "Error",
@@ -279,6 +286,12 @@ function TrackerStatusField(props: TableFieldProps) {
279286
return <div>{props.torrent.cachedTrackerStatus}</div>;
280287
}
281288

289+
function TrackerDownloadsField(props: TableFieldProps) {
290+
return <div style={{ width: "100%", textAlign: "right" }}>
291+
{props.torrent.cachedTrackerDlCount >= 0 ? props.torrent.cachedTrackerDlCount : ""}
292+
</div>;
293+
}
294+
282295
function ErrorField(props: TableFieldProps) {
283296
return <div>{props.torrent.cachedError}</div>;
284297
}

src/rpc/torrent.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type TorrentFile = Record<TorrentFileFieldsType, any>;
3131
export interface Torrent extends TorrentBase {
3232
cachedError: string,
3333
cachedTrackerStatus: string,
34+
cachedTrackerDlCount: number,
3435
cachedMainTracker: string,
3536
cachedPeersTotal: number,
3637
cachedSeedsTotal: number,
@@ -82,6 +83,12 @@ function getTrackerStatus(torrent: TorrentBase): string {
8283
return getTrackerAnnounceState(trackers[0]);
8384
}
8485

86+
function getTrackerDlCount(torrent: TorrentBase): number {
87+
const trackers = torrent.trackerStats as TrackerStats[];
88+
if (torrent.status === Status.stopped || trackers.length === 0) return -1;
89+
return trackers.map((t) => t.downloadCount as number).reduce((total, current) => total + current, 0) as number;
90+
}
91+
8592
const portRe = /:\d+$/;
8693
const httpRe = /^https?:\/\//;
8794

@@ -121,6 +128,7 @@ export async function processTorrent(t: TorrentBase, lookupIps: boolean, ignored
121128
downloadDir: (t.downloadDir as string).replaceAll("\\", "/"),
122129
cachedError: getTorrentError(t),
123130
cachedTrackerStatus: getTrackerStatus(t),
131+
cachedTrackerDlCount: getTrackerDlCount(t),
124132
cachedMainTracker: getTorrentMainTracker(t, ignoredPrefixesRe),
125133
cachedSeedsTotal: getSeedsTotal(t),
126134
cachedPeersTotal: getPeersTotal(t),

0 commit comments

Comments
 (0)