Skip to content

A full-featured download manager.

feat: autofill resource uri when open add task

Dr_rOot7011160587b1
diff --git a/src/renderer/components/Task/AddTask.vue b/src/renderer/components/Task/AddTask.vue
index c6496a85..f1bca93c 100644
--- a/src/renderer/components/Task/AddTask.vue
+++ b/src/renderer/components/Task/AddTask.vue
@@ -116,7 +116,11 @@
import SelectTorrent from '@/components/Task/SelectTorrent'
import { prettifyDir } from '@/components/Native/utils'
import '@/components/Icons/inbox'
- import { splitTaskLinks, needCheckCopyright } from '@shared/utils'
+ import {
+ detectResource,
+ splitTaskLinks,
+ needCheckCopyright
+ } from '@shared/utils'
const initialForm = (state) => {
const { dir, split, newTaskShowDownloading } = state.preference.config
@@ -196,11 +200,20 @@
handleOpen () {
this.form = initialForm(this.$store.state)
if (this.taskType === 'uri') {
+ this.autofillResourceLink()
setTimeout(() => {
this.$refs.uri && this.$refs.uri.focus()
}, 50)
}
},
+ autofillResourceLink () {
+ const content = this.$electron.clipboard.readText()
+ const hasResource = detectResource(content)
+ if (!hasResource) {
+ return
+ }
+ this.form.uris = content
+ },
handleClose (done) {
this.$store.dispatch('app/hideAddTaskDialog')
},
diff --git a/src/shared/utils.js b/src/shared/utils.js
index b3f0a5c5..a1dc242a 100644
--- a/src/shared/utils.js
+++ b/src/shared/utils.js
@@ -297,3 +297,10 @@ export function splitTaskLinks (links = '') {
})
return result
}
+
+const resourceTag = ['http://', 'https://', 'ftp://', 'magnet:', 'thunder://']
+export function detectResource (content) {
+ return resourceTag.some((type) => {
+ return content.includes(type)
+ })
+}