Skip to content

Commit 71a3859

Browse files
committed
Add "Open folder" item in torrent/file row menu
Issue #92
1 parent 2149c75 commit 71a3859

5 files changed

Lines changed: 54 additions & 17 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tokio = { version = "^1.28", features = ["net"] }
2525
serde = { version = "^1.0", features = ["derive"] }
2626
tauri = { version = "^1.4", features = [ "clipboard-write-text", "cli", "devtools", "dialog-all", "fs-read-file", "fs-write-file", "notification", "path-all", "shell-open", "system-tray", "window-center", "window-close", "window-create", "window-hide", "window-set-focus", "window-set-position", "window-set-size", "window-set-title", "window-show", "window-unminimize"] }
2727
tauri-utils = "^1.4"
28-
opener = "0.6"
28+
opener = { version = "0.6", features = ["reveal"] }
2929
rodio = { version = "0.17.1", features = ["mp3"], default-features = false }
3030
hyper-tls = "0.5.0"
3131
notify-rust = "4.8.0"

src-tauri/src/commands.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub async fn read_file(path: String) -> Result<TorrentReadResult, String> {
5959
return Err(format!("Failed to read file {:?}", path));
6060
}
6161

62-
6362
match Torrent::read_from_bytes(&read_result.as_ref().unwrap()[..]) {
6463
Err(_) => Err(format!("Failed to parse torrent {:?}", path)),
6564
Ok(torrent) => {
@@ -105,12 +104,14 @@ pub async fn remove_file(path: String) {
105104
}
106105

107106
#[tauri::command]
108-
pub async fn shell_open(path: String) -> Result<(), String> {
107+
pub async fn shell_open(path: String, reveal: bool) -> Result<(), String> {
109108
#[cfg(target_os = "windows")]
110109
let path = path.replace('/', "\\");
111110

112-
if let Err(e) = opener::open(path) {
113-
return Err(e.to_string());
111+
if reveal {
112+
opener::reveal(path).map_err(|e| e.to_string())?
113+
} else {
114+
opener::open(path).map_err(|e| e.to_string())?
114115
}
115116
Ok(())
116117
}

src/components/tables/filetreetable.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export function FileTreeTable(props: FileTreeTableProps) {
287287
selectedReducer({ verb: "set", ids: [], isReset: true });
288288
}, [props.fileTree.torrenthash, selectedReducer]);
289289

290-
const onRowDoubleClick = useCallback((row: FileDirEntry) => {
290+
const onRowDoubleClick = useCallback((row: FileDirEntry, reveal: boolean = false) => {
291291
if (TAURI) {
292292
if (props.downloadDir === undefined || props.downloadDir === "") return;
293293
let path = props.downloadDir;
@@ -296,7 +296,7 @@ export function FileTreeTable(props: FileTreeTableProps) {
296296
}
297297
path = path + row.fullpath + (isDirEntry(row) ? "/" : "");
298298
path = pathMapFromServer(path, serverConfig);
299-
invoke("shell_open", { path }).catch((e) => {
299+
invoke("shell_open", { path, reveal }).catch((e) => {
300300
notifications.show({
301301
title: "Error opening path",
302302
message: path,
@@ -389,16 +389,16 @@ function FiletreeContextMenu(props: {
389389
setContextMenuInfo: (i: ContextMenuInfo) => void,
390390
fileTree: CachedFileTree,
391391
selected: string[],
392-
onRowDoubleClick: (row: FileDirEntry) => void,
392+
onRowDoubleClick: (row: FileDirEntry, reveal: boolean) => void,
393393
setExpanded?: (state: boolean) => void,
394394
toggleFileSearchBox: () => void,
395395
}) {
396396
const { onRowDoubleClick } = props;
397-
const onOpen = useCallback(() => {
397+
const onOpen = useCallback((reveal: boolean) => {
398398
const [path] = [...props.selected];
399399
const entry = props.fileTree.findEntry(path);
400400
if (entry === undefined) return;
401-
onRowDoubleClick(entry);
401+
onRowDoubleClick(entry, reveal);
402402
}, [onRowDoubleClick, props.fileTree, props.selected]);
403403

404404
const mutation = useMutateTorrent();
@@ -459,11 +459,17 @@ function FiletreeContextMenu(props: {
459459
<ContextMenu contextMenuInfo={props.contextMenuInfo} setContextMenuInfo={props.setContextMenuInfo}>
460460
{TAURI && <>
461461
<Menu.Item
462-
onClick={onOpen}
462+
onClick={() => { onOpen(false); }}
463463
icon={<Icon.BoxArrowUpRight size="1.1rem" />}
464464
disabled={props.selected.length !== 1}>
465465
<Text weight="bold">Open</Text>
466466
</Menu.Item>
467+
<Menu.Item
468+
onClick={() => { onOpen(true); }}
469+
icon={<Icon.Folder2Open size="1.1rem" />}
470+
disabled={props.selected.length !== 1}>
471+
<Text>Open folder</Text>
472+
</Menu.Item>
467473
<Menu.Divider />
468474
</>}
469475
<Menu.Item

src/components/tables/torrenttable.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export function TorrentTable(props: {
401401
[onColumnVisibilityChange],
402402
);
403403

404-
const onRowDoubleClick = useCallback((torrent: Torrent) => {
404+
const onRowDoubleClick = useCallback((torrent: Torrent, reveal: boolean = false) => {
405405
if (TAURI) {
406406
if (torrent.downloadDir === undefined || torrent.downloadDir === "") return;
407407
let path = torrent.downloadDir as string;
@@ -410,7 +410,7 @@ export function TorrentTable(props: {
410410
}
411411
path = path + fileSystemSafeName(torrent.name);
412412
path = pathMapFromServer(path, serverConfig);
413-
invoke("shell_open", { path }).catch((e) => {
413+
invoke("shell_open", { path, reveal }).catch((e) => {
414414
notifications.show({
415415
title: "Error opening path",
416416
message: path,
@@ -454,17 +454,17 @@ function TorrentContextMenu(props: {
454454
contextMenuInfo: ContextMenuInfo,
455455
setContextMenuInfo: (i: ContextMenuInfo) => void,
456456
modals: React.RefObject<ModalCallbacks>,
457-
onRowDoubleClick: (t: Torrent) => void,
457+
onRowDoubleClick: (t: Torrent, reveal: boolean) => void,
458458
}) {
459459
const serverData = useServerTorrentData();
460460
const serverSelected = useServerSelectedTorrents();
461461

462462
const { onRowDoubleClick } = props;
463-
const onOpen = useCallback(() => {
463+
const onOpen = useCallback((reveal: boolean) => {
464464
const [id] = [...serverSelected];
465465
const torrent = serverData.torrents.find((t) => t.id === id);
466466
if (torrent === undefined) return;
467-
onRowDoubleClick(torrent);
467+
onRowDoubleClick(torrent, reveal);
468468
}, [onRowDoubleClick, serverData.torrents, serverSelected]);
469469

470470
const mutation = useTorrentAction();
@@ -587,12 +587,19 @@ function TorrentContextMenu(props: {
587587
<Box miw="14rem">
588588
{TAURI && <>
589589
<Menu.Item
590-
onClick={onOpen}
590+
onClick={() => { onOpen(false); }}
591591
onMouseEnter={closeQueueSubmenu}
592592
icon={<Icon.BoxArrowUpRight size="1.1rem" />}
593593
disabled={serverSelected.size !== 1}>
594594
<Text weight="bold">Open</Text>
595595
</Menu.Item>
596+
<Menu.Item
597+
onClick={() => { onOpen(true); }}
598+
onMouseEnter={closeQueueSubmenu}
599+
icon={<Icon.Folder2Open size="1.1rem" />}
600+
disabled={serverSelected.size !== 1}>
601+
<Text>Open folder</Text>
602+
</Menu.Item>
596603
<Menu.Divider />
597604
</>}
598605
<Menu.Item

0 commit comments

Comments
 (0)