feat(client): detect magnet and torrent links from clipboard (#690)

This commit is contained in:
Harry Merritt
2023-12-06 11:29:54 +00:00
committed by GitHub
parent 5a0d2bec84
commit 6d059544b6
@@ -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';
@@ -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;
}
@@ -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;