add context menu item to show song in file manager (#1397)

This commit is contained in:
jeffvli
2026-01-02 01:32:51 -08:00
parent 6aeec1e89c
commit e696c0c636
4 changed files with 59 additions and 0 deletions
@@ -0,0 +1,53 @@
import isElectron from 'is-electron';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { ContextMenu } from '/@/shared/components/context-menu/context-menu';
import { toast } from '/@/shared/components/toast/toast';
import { QueueSong, Song } from '/@/shared/types/domain-types';
interface ShowInFileExplorerActionProps {
items: QueueSong[] | Song[];
}
const utils = isElectron() ? window.api.utils : null;
export const ShowInFileExplorerAction = ({ items }: ShowInFileExplorerActionProps) => {
const { t } = useTranslation();
const onSelect = useCallback(async () => {
if (!utils) {
return;
}
const firstItem = items[0];
if (!firstItem?.path) {
return;
}
try {
await utils.openItem(firstItem.path);
} catch (error) {
toast.error({
message: (error as Error).message,
title: t('error.openError', {
postProcess: 'sentenceCase',
}),
});
}
}, [items, t]);
if (!utils) {
return null;
}
const firstItem = items[0];
const hasPath = firstItem?.path !== null;
const isDisabled = items.length > 1 || !hasPath;
return (
<ContextMenu.Item disabled={isDisabled} leftIcon="folder" onSelect={onSelect}>
{t('page.itemDetail.openFile', { postProcess: 'sentenceCase' })}
</ContextMenu.Item>
);
};