Skip to content

Commit

Permalink
feat(client): detect magnet and torrent links from clipboard (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmerritt authored Dec 6, 2023
1 parent 5a0d2be commit 6d05954
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion client/src/javascript/components/torrent-list/TorrentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SettingStore from '@client/stores/SettingStore';
import TorrentFilterStore from '@client/stores/TorrentFilterStore';
import TorrentStore from '@client/stores/TorrentStore';
import SortDirections from '@client/constants/SortDirections';
import UIStore from '@client/stores/UIStore';

import type {TorrentListColumn} from '@client/constants/TorrentListColumns';

Expand Down Expand Up @@ -50,7 +51,7 @@ const TorrentList: FC = observer(() => {
useEvent('keydown', (e: KeyboardEvent) => {
const {ctrlKey, key, metaKey, repeat, target} = e;

const tagName = (target as HTMLElement)?.tagName.toUpperCase();
const tagName = (target as HTMLElement)?.tagName?.toUpperCase();
if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
return;
}
Expand All @@ -63,6 +64,18 @@ const TorrentList: FC = observer(() => {
e.preventDefault();
TorrentStore.selectAllTorrents();
}

if ((metaKey || ctrlKey) && key === 'v') {
(async () => {
const text = await navigator?.clipboard?.readText();
const isMagnetLink = text?.startsWith('magnet:?');
const isTorrentLink = text?.startsWith('http') && text?.endsWith('.torrent');
if (isMagnetLink || isTorrentLink) {
e.preventDefault();
UIStore.setActiveModal({id: 'add-torrents', tab: 'by-url', urls: [{id: 0, value: text}]});
}
})();
}
});

const torrents = TorrentStore.filteredTorrents;
Expand Down

0 comments on commit 6d05954

Please sign in to comment.