A full-featured download manager.
chore: vue code format
Dr_rOotb34f3ceb894b
diff --git a/src/renderer/components/About/AppInfo.vue b/src/renderer/components/About/AppInfo.vueindex 1cbf47c0..2d18ddb7 100644--- a/src/renderer/components/About/AppInfo.vue+++ b/src/renderer/components/About/AppInfo.vue@@ -34,9 +34,11 @@},engine: {type: Object,- default: {- version: '',- enabledFeatures: []+ default () {+ return {+ version: '',+ enabledFeatures: []+ }}}},diff --git a/src/renderer/components/Aside/Index.vue b/src/renderer/components/Aside/Index.vueindex 0b7cb6cc..564bf72c 100644--- a/src/renderer/components/Aside/Index.vue+++ b/src/renderer/components/Aside/Index.vue@@ -50,11 +50,7 @@this.$store.dispatch('app/showAddTaskDialog', taskType)},showAboutPanel () {- // if (is.renderer()) {- // this.$electron.ipcRenderer.send('command', 'application:about')- // } else {this.$store.dispatch('app/showAboutPanel')- // }},nav (page) {this.$router.push({diff --git a/src/renderer/components/DragSelect/Index.vue b/src/renderer/components/DragSelect/Index.vueindex 9b48e2e9..5382f4d2 100644--- a/src/renderer/components/DragSelect/Index.vue+++ b/src/renderer/components/DragSelect/Index.vue@@ -8,155 +8,155 @@</template><script>-const getDimensions = (p1, p2) => ({- width: Math.abs(p1.x - p2.x),- height: Math.abs(p1.y - p2.y)-})--const collisionCheck = (node1, node2) =>- node1.left < node2.left + node2.width &&- node1.left + node1.width > node2.left &&- node1.top < node2.top + node2.height &&- node1.top + node1.height > node2.top--export default {- name: 'mo-drag-select',- props: {- attribute: {- type: String,- required: true+ const getDimensions = (p1, p2) => ({+ width: Math.abs(p1.x - p2.x),+ height: Math.abs(p1.y - p2.y)+ })++ const collisionCheck = (node1, node2) =>+ node1.left < node2.left + node2.width &&+ node1.left + node1.width > node2.left &&+ node1.top < node2.top + node2.height &&+ node1.top + node1.height > node2.top++ export default {+ name: 'mo-drag-select',+ props: {+ attribute: {+ type: String,+ required: true+ },+ color: {+ type: String,+ default: '#4299E1'+ },+ opacity: {+ type: Number,+ default: 0.7+ }},- color: {- type: String,- default: '#4299E1'+ data () {+ return {+ intersected: [],+ children: []+ }},- opacity: {- type: Number,- default: 0.7- }- },- data () {- return {- intersected: [],- children: []- }- },- watch: {- intersected (i) {- this.$emit('change', i)- }- },- mounted () {- const { container } = this.$refs- const self = this+ watch: {+ intersected (i) {+ this.$emit('change', i)+ }+ },+ mounted () {+ const { container } = this.$refs+ const self = this- let containerRect = container.getBoundingClientRect()+ let containerRect = container.getBoundingClientRect()- const getCoords = e => ({- x: e.clientX - containerRect.left,- y: e.clientY - containerRect.top- })+ const getCoords = e => ({+ x: e.clientX - containerRect.left,+ y: e.clientY - containerRect.top+ })- let box = this.createBox()- let start = { x: 0, y: 0 }- let end = { x: 0, y: 0 }+ const box = this.createBox()+ let start = { x: 0, y: 0 }+ let end = { x: 0, y: 0 }- function touchStart (e) {- e.preventDefault()- startDrag(e.touches[0])- }+ function touchStart (e) {+ e.preventDefault()+ startDrag(e.touches[0])+ }- function touchMove (e) {- e.preventDefault()- drag(e.touches[0])- }+ function touchMove (e) {+ e.preventDefault()+ drag(e.touches[0])+ }- function startDrag (e) {- containerRect = container.getBoundingClientRect()- self.children = container.childNodes- start = getCoords(e)- end = start- document.addEventListener('mousemove', drag)- document.addEventListener('touchmove', touchMove)+ function startDrag (e) {+ containerRect = container.getBoundingClientRect()+ self.children = container.childNodes+ start = getCoords(e)+ end = start+ document.addEventListener('mousemove', drag)+ document.addEventListener('touchmove', touchMove)- box.style.top = start.y + 'px'- box.style.left = start.x + 'px'+ box.style.top = start.y + 'px'+ box.style.left = start.x + 'px'- container.prepend(box)- self.intersection(box)- }+ container.prepend(box)+ self.intersection(box)+ }- function drag (e) {- end = getCoords(e)- const dimensions = getDimensions(start, end)+ function drag (e) {+ end = getCoords(e)+ const dimensions = getDimensions(start, end)- if (end.x < start.x) {- box.style.left = end.x + 'px'- }- if (end.y < start.y) {- box.style.top = end.y + 'px'+ if (end.x < start.x) {+ box.style.left = end.x + 'px'+ }+ if (end.y < start.y) {+ box.style.top = end.y + 'px'+ }+ box.style.width = dimensions.width + 'px'+ box.style.height = dimensions.height + 'px'++ self.intersection(box)}- box.style.width = dimensions.width + 'px'- box.style.height = dimensions.height + 'px'- self.intersection(box)- }+ function endDrag () {+ start = { x: 0, y: 0 }+ end = { x: 0, y: 0 }- function endDrag () {- start = { x: 0, y: 0 }- end = { x: 0, y: 0 }+ box.style.width = 0+ box.style.height = 0- box.style.width = 0- box.style.height = 0+ document.removeEventListener('mousemove', drag)+ document.removeEventListener('touchmove', touchMove)+ box.remove()+ }- document.removeEventListener('mousemove', drag)- document.removeEventListener('touchmove', touchMove)- box.remove()- }+ container.addEventListener('mousedown', startDrag)+ container.addEventListener('touchstart', touchStart)++ document.addEventListener('mouseup', endDrag)+ document.addEventListener('touchend', endDrag)- container.addEventListener('mousedown', startDrag)- container.addEventListener('touchstart', touchStart)-- document.addEventListener('mouseup', endDrag)- document.addEventListener('touchend', endDrag)-- this.$once('on:destroy', () => {- container.removeEventListener('mousedown', startDrag)- container.removeEventListener('touchstart', touchStart)- document.removeEventListener('mouseup', endDrag)- document.removeEventListener('touchend', endDrag)- })- },- methods: {- createBox () {- const box = document.createElement('div')- box.setAttribute('data-drag-box-component', '')- box.style.position = 'absolute'- box.style.backgroundColor = this.color- box.style.opacity = this.opacity- box.style.zIndex = 1000-- return box+ this.$once('on:destroy', () => {+ container.removeEventListener('mousedown', startDrag)+ container.removeEventListener('touchstart', touchStart)+ document.removeEventListener('mouseup', endDrag)+ document.removeEventListener('touchend', endDrag)+ })},- intersection (box) {- const { children } = this- const rect = box.getBoundingClientRect()- const intersected = []-- for (let i = 0; i < children.length; i++) {- if (collisionCheck(rect, children[i].getBoundingClientRect())) {- const attr = children[i].getAttribute(this.attribute)- if (children[i].hasAttribute(this.attribute)) {- intersected.push(attr)+ methods: {+ createBox () {+ const box = document.createElement('div')+ box.setAttribute('data-drag-box-component', '')+ box.style.position = 'absolute'+ box.style.backgroundColor = this.color+ box.style.opacity = this.opacity+ box.style.zIndex = 1000++ return box+ },+ intersection (box) {+ const { children } = this+ const rect = box.getBoundingClientRect()+ const intersected = []++ for (let i = 0; i < children.length; i++) {+ if (collisionCheck(rect, children[i].getBoundingClientRect())) {+ const attr = children[i].getAttribute(this.attribute)+ if (children[i].hasAttribute(this.attribute)) {+ intersected.push(attr)+ }}}- }- if (- JSON.stringify([...intersected]) !==- JSON.stringify([...this.intersected])- ) { this.intersected = intersected }+ if (+ JSON.stringify([...intersected]) !==+ JSON.stringify([...this.intersected])+ ) { this.intersected = intersected }+ }}}-}</script>diff --git a/src/renderer/components/Dragger/Index.vue b/src/renderer/components/Dragger/Index.vueindex 58e67623..ecfdb9d9 100644--- a/src/renderer/components/Dragger/Index.vue+++ b/src/renderer/components/Dragger/Index.vue@@ -3,48 +3,48 @@</template><script>-import { ADD_TASK_TYPE } from '@shared/constants'+ import { ADD_TASK_TYPE } from '@shared/constants'-export default {- name: 'mo-dragger',- mounted () {- this.preventDefault = ev => ev.preventDefault()- let count = 0- this.onDragEnter = (ev) => {- if (count === 0) {- this.$store.dispatch('app/showAddTaskDialog', ADD_TASK_TYPE.TORRENT)+ export default {+ name: 'mo-dragger',+ mounted () {+ this.preventDefault = ev => ev.preventDefault()+ let count = 0+ this.onDragEnter = (ev) => {+ if (count === 0) {+ this.$store.dispatch('app/showAddTaskDialog', ADD_TASK_TYPE.TORRENT)+ }+ count++}- count++- }- this.onDragLeave = (ev) => {- count--- if (count === 0) {- this.$store.dispatch('app/hideAddTaskDialog')+ this.onDragLeave = (ev) => {+ count--+ if (count === 0) {+ this.$store.dispatch('app/hideAddTaskDialog')+ }}- }- this.onDrop = (ev) => {- count = 0+ this.onDrop = (ev) => {+ count = 0- const fileList = [...ev.dataTransfer.files]- .map(item => ({ raw: item, name: item.name }))- .filter(item => /\.torrent$/.test(item.name))- if (!fileList.length) {- this.$msg.error(this.$t('task.select-torrent'))+ const fileList = [...ev.dataTransfer.files]+ .map(item => ({ raw: item, name: item.name }))+ .filter(item => /\.torrent$/.test(item.name))+ if (!fileList.length) {+ this.$msg.error(this.$t('task.select-torrent'))+ }}- }- document.addEventListener('dragover', this.preventDefault)- document.body.addEventListener('dragenter', this.onDragEnter)- document.body.addEventListener('dragleave', this.onDragLeave)- document.body.addEventListener('drop', this.onDrop)- },- destroyed () {- document.removeEventListener('dragover', this.preventDefault)- document.body.removeEventListener('dragenter', this.onDragEnter)- document.body.removeEventListener('dragleave', this.onDragLeave)- document.body.removeEventListener('drop', this.onDrop)+ document.addEventListener('dragover', this.preventDefault)+ document.body.addEventListener('dragenter', this.onDragEnter)+ document.body.addEventListener('dragleave', this.onDragLeave)+ document.body.addEventListener('drop', this.onDrop)+ },+ destroyed () {+ document.removeEventListener('dragover', this.preventDefault)+ document.body.removeEventListener('dragenter', this.onDragEnter)+ document.body.removeEventListener('dragleave', this.onDragLeave)+ document.body.removeEventListener('drop', this.onDrop)+ }}-}</script>diff --git a/src/renderer/components/Icons/Icon.vue b/src/renderer/components/Icons/Icon.vueindex 2102f762..322037ee 100644--- a/src/renderer/components/Icons/Icon.vue+++ b/src/renderer/components/Icons/Icon.vue@@ -58,171 +58,171 @@</style><script>-let icons = {}--export default {- name: 'fa-icon',- props: {- name: {- type: String,- validator (val) {- if (val && !(val in icons)) {- console.warn(`Invalid prop: prop "name" is referring to an unregistered icon "${val}".` +- `\nPlease make sure you have imported this icon before using it.`)- return false+ const icons = {}++ export default {+ name: 'fa-icon',+ props: {+ name: {+ type: String,+ validator (val) {+ if (val && !(val in icons)) {+ console.warn(`Invalid prop: prop "name" is referring to an unregistered icon "${val}".` ++ '\nPlease make sure you have imported this icon before using it.')+ return false+ }+ return true}- return true- }- },- scale: [Number, String],- spin: Boolean,- inverse: Boolean,- pulse: Boolean,- flip: {- validator (val) {- return val === 'horizontal' || val === 'vertical'- }- },- label: String- },- data () {- return {- x: false,- y: false,- childrenWidth: 0,- childrenHeight: 0,- outerScale: 1- }- },- computed: {- normalizedScale () {- let scale = this.scale- scale = typeof scale === 'undefined' ? 1 : Number(scale)- if (isNaN(scale) || scale <= 0) {- console.warn(`Invalid prop: prop "scale" should be a number over 0.`, this)- return this.outerScale- }- return scale * this.outerScale+ },+ scale: [Number, String],+ spin: Boolean,+ inverse: Boolean,+ pulse: Boolean,+ flip: {+ validator (val) {+ return val === 'horizontal' || val === 'vertical'+ }+ },+ label: String},- klass () {+ data () {return {- 'fa-icon': true,- 'fa-spin': this.spin,- 'fa-flip-horizontal': this.flip === 'horizontal',- 'fa-flip-vertical': this.flip === 'vertical',- 'fa-inverse': this.inverse,- 'fa-pulse': this.pulse,- [this.$options.name]: true+ x: false,+ y: false,+ childrenWidth: 0,+ childrenHeight: 0,+ outerScale: 1}},- icon () {- if (this.name) {- return icons[this.name]- }- return null- },- box () {- if (this.icon) {- return `0 0 ${this.icon.width} ${this.icon.height}`- }- return `0 0 ${this.width} ${this.height}`- },- ratio () {- if (!this.icon) {- return 1+ computed: {+ normalizedScale () {+ let scale = this.scale+ scale = typeof scale === 'undefined' ? 1 : Number(scale)+ if (isNaN(scale) || scale <= 0) {+ console.warn('Invalid prop: prop "scale" should be a number over 0.', this)+ return this.outerScale+ }+ return scale * this.outerScale+ },+ klass () {+ return {+ 'fa-icon': true,+ 'fa-spin': this.spin,+ 'fa-flip-horizontal': this.flip === 'horizontal',+ 'fa-flip-vertical': this.flip === 'vertical',+ 'fa-inverse': this.inverse,+ 'fa-pulse': this.pulse,+ [this.$options.name]: true+ }+ },+ icon () {+ if (this.name) {+ return icons[this.name]+ }+ return null+ },+ box () {+ if (this.icon) {+ return `0 0 ${this.icon.width} ${this.icon.height}`+ }+ return `0 0 ${this.width} ${this.height}`+ },+ ratio () {+ if (!this.icon) {+ return 1+ }+ const { width, height } = this.icon+ return Math.max(width, height) / 16+ },+ width () {+ return this.childrenWidth || (this.icon && this.icon.width / this.ratio * this.normalizedScale) || 0+ },+ height () {+ return this.childrenHeight || (this.icon && this.icon.height / this.ratio * this.normalizedScale) || 0+ },+ style () {+ if (this.normalizedScale === 1) {+ return false+ }+ return {+ fontSize: this.normalizedScale + 'em'+ }+ },+ raw () {+ // generate unique id for each icon's SVG element with ID+ if (!this.icon || !this.icon.raw) {+ return null+ }+ let raw = this.icon.raw+ const ids = {}+ raw = raw.replace(/\s(?:xml:)?id=(["']?)([^"')\s]+)\1/g, (match, quote, id) => {+ const uniqueId = getId()+ ids[id] = uniqueId+ return ` id="${uniqueId}"`+ })+ raw = raw.replace(/#(?:([^'")\s]+)|xpointer\(id\((['"]?)([^')]+)\2\)\))/g, (match, rawId, _, pointerId) => {+ const id = rawId || pointerId+ if (!id || !ids[id]) {+ return match+ }++ return `#${ids[id]}`+ })++ return raw}- let { width, height } = this.icon- return Math.max(width, height) / 16},- width () {- return this.childrenWidth || (this.icon && this.icon.width / this.ratio * this.normalizedScale) || 0- },- height () {- return this.childrenHeight || (this.icon && this.icon.height / this.ratio * this.normalizedScale) || 0- },- style () {- if (this.normalizedScale === 1) {- return false+ mounted () {+ if (!this.name && this.$children.length === 0) {+ console.warn('Invalid prop: prop "name" is required.')+ return}- return {- fontSize: this.normalizedScale + 'em'- }- },- raw () {- // generate unique id for each icon's SVG element with ID- if (!this.icon || !this.icon.raw) {- return null++ if (this.icon) {+ return}- let raw = this.icon.raw- let ids = {}- raw = raw.replace(/\s(?:xml:)?id=(["']?)([^"')\s]+)\1/g, (match, quote, id) => {- let uniqueId = getId()- ids[id] = uniqueId- return ` id="${uniqueId}"`- })- raw = raw.replace(/#(?:([^'")\s]+)|xpointer\(id\((['"]?)([^')]+)\2\)\))/g, (match, rawId, _, pointerId) => {- let id = rawId || pointerId- if (!id || !ids[id]) {- return match- }- return `#${ids[id]}`+ let width = 0+ let height = 0+ this.$children.forEach(child => {+ child.outerScale = this.normalizedScale++ width = Math.max(width, child.width)+ height = Math.max(height, child.height)+ })+ this.childrenWidth = width+ this.childrenHeight = height+ this.$children.forEach(child => {+ child.x = (width - child.width) / 2+ child.y = (height - child.height) / 2})+ },+ register (data) {+ for (const name in data) {+ const icon = data[name]- return raw- }- },- mounted () {- if (!this.name && this.$children.length === 0) {- console.warn(`Invalid prop: prop "name" is required.`)- return- }-- if (this.icon) {- return- }-- let width = 0- let height = 0- this.$children.forEach(child => {- child.outerScale = this.normalizedScale-- width = Math.max(width, child.width)- height = Math.max(height, child.height)- })- this.childrenWidth = width- this.childrenHeight = height- this.$children.forEach(child => {- child.x = (width - child.width) / 2- child.y = (height - child.height) / 2- })- },- register (data) {- for (let name in data) {- let icon = data[name]-- if (!icon.paths) {- icon.paths = []- }- if (icon.d) {- icon.paths.push({ d: icon.d })- }+ if (!icon.paths) {+ icon.paths = []+ }+ if (icon.d) {+ icon.paths.push({ d: icon.d })+ }- if (!icon.polygons) {- icon.polygons = []- }- if (icon.points) {- icon.polygons.push({ points: icon.points })- }+ if (!icon.polygons) {+ icon.polygons = []+ }+ if (icon.points) {+ icon.polygons.push({ points: icon.points })+ }- icons[name] = icon- }- },- icons-}+ icons[name] = icon+ }+ },+ icons+ }-let cursor = 0xd4937-function getId () {- return `fa-${(cursor++).toString(16)}`-}+ let cursor = 0xd4937+ function getId () {+ return `fa-${(cursor++).toString(16)}`+ }</script>diff --git a/src/renderer/components/Native/Ipc.vue b/src/renderer/components/Native/Ipc.vueindex b21c511d..f52eb8d6 100644--- a/src/renderer/components/Native/Ipc.vue+++ b/src/renderer/components/Native/Ipc.vue@@ -31,7 +31,7 @@created: function () {this.bindIpcEvents()// id of the menu item- let visibleStates = {}+ const visibleStates = {}if (is.mas()) {visibleStates['app.check-for-updates'] = falseif (!this.enableEggFeatures) {diff --git a/src/renderer/components/Preference/Advanced.vue b/src/renderer/components/Preference/Advanced.vueindex 4d248ba0..f7be2f2b 100644--- a/src/renderer/components/Preference/Advanced.vue+++ b/src/renderer/components/Preference/Advanced.vue@@ -563,7 +563,7 @@if (this.isRenderer) {this.$electron.ipcRenderer.send('command',- 'application:setup-protocols-client', data.protocols)+ 'application:setup-protocols-client', data.protocols)if (checkIsNeedRestart(data)) {this.$electron.ipcRenderer.send('command', 'application:relaunch')diff --git a/src/renderer/components/Preference/Basic.vue b/src/renderer/components/Preference/Basic.vueindex 4c37e6c8..19a6d09c 100644--- a/src/renderer/components/Preference/Basic.vue+++ b/src/renderer/components/Preference/Basic.vue@@ -354,12 +354,12 @@const lng = getLanguage(locale)getLocaleManager().changeLanguage(lng)this.$electron.ipcRenderer.send('command',- 'application:change-locale', lng)+ 'application:change-locale', lng)},handleThemeChange (theme) {this.form.theme = themethis.$electron.ipcRenderer.send('command',- 'application:change-theme', theme)+ 'application:change-theme', theme)},onDirectorySelected (dir) {this.form.dir = dir@@ -397,17 +397,17 @@if (this.isRenderer) {this.$electron.ipcRenderer.send('command',- 'application:open-at-login', openAtLogin)+ 'application:open-at-login', openAtLogin)this.$electron.ipcRenderer.send('command',- 'application:toggle-dock', runMode === APP_RUN_MODE.STANDARD)+ 'application:toggle-dock', runMode === APP_RUN_MODE.STANDARD)this.$electron.ipcRenderer.send('command',- 'application:auto-hide-window', autoHideWindow)+ 'application:auto-hide-window', autoHideWindow)if (checkIsNeedRestart(data)) {this.$electron.ipcRenderer.send('command',- 'application:relaunch')+ 'application:relaunch')}}})diff --git a/src/renderer/components/Subnav/SubnavSwitcher.vue b/src/renderer/components/Subnav/SubnavSwitcher.vueindex 96ed0d32..b0d94112 100644--- a/src/renderer/components/Subnav/SubnavSwitcher.vue+++ b/src/renderer/components/Subnav/SubnavSwitcher.vue@@ -13,26 +13,26 @@</template><script>-export default {- name: 'mo-subnav-switcher',- props: {- title: {- type: String+ export default {+ name: 'mo-subnav-switcher',+ props: {+ title: {+ type: String+ },+ subnavs: {+ type: Array+ }},- subnavs: {- type: Array- }- },- methods: {- handleRoute (route) {- this.$router.push({- path: route- }).catch(err => {- console.log(err)- })+ methods: {+ handleRoute (route) {+ this.$router.push({+ path: route+ }).catch(err => {+ console.log(err)+ })+ }}}-}</script><style lang='scss'>diff --git a/src/renderer/components/Task/AddTask.vue b/src/renderer/components/Task/AddTask.vueindex c97619f2..59410287 100644--- a/src/renderer/components/Task/AddTask.vue+++ b/src/renderer/components/Task/AddTask.vue@@ -167,275 +167,275 @@</template><script>-import is from 'electron-is'-import { mapState } from 'vuex'-import { isEmpty } from 'lodash'-import SelectDirectory from '@/components/Native/SelectDirectory'-import SelectTorrent from '@/components/Task/SelectTorrent'-import { prettifyDir } from '@/components/Native/utils'-import { ADD_TASK_TYPE, NONE_SELECTED_FILES, SELECTED_ALL_FILES } from '@shared/constants'-import { detectResource, splitTaskLinks } from '@shared/utils'-import { buildOuts } from '@shared/utils/rename'-import '@/components/Icons/inbox'+ import is from 'electron-is'+ import { mapState } from 'vuex'+ import { isEmpty } from 'lodash'+ import SelectDirectory from '@/components/Native/SelectDirectory'+ import SelectTorrent from '@/components/Task/SelectTorrent'+ import { prettifyDir } from '@/components/Native/utils'+ import { ADD_TASK_TYPE, NONE_SELECTED_FILES, SELECTED_ALL_FILES } from '@shared/constants'+ import { detectResource, splitTaskLinks } from '@shared/utils'+ import { buildOuts } from '@shared/utils/rename'+ import '@/components/Icons/inbox'-const initialForm = state => {- const { addTaskUrl, addTaskOptions } = state.app- const {- allProxy,- dir,- engineMaxConnectionPerServer,- maxConnectionPerServer,- newTaskShowDownloading- } = state.preference.config- const result = {- allProxy,- cookie: '',- dir,- engineMaxConnectionPerServer,- maxConnectionPerServer,- newTaskShowDownloading,- out: '',- referer: '',- selectFile: NONE_SELECTED_FILES,- torrent: '',- uris: addTaskUrl,- userAgent: '',- ...addTaskOptions+ const initialForm = state => {+ const { addTaskUrl, addTaskOptions } = state.app+ const {+ allProxy,+ dir,+ engineMaxConnectionPerServer,+ maxConnectionPerServer,+ newTaskShowDownloading+ } = state.preference.config+ const result = {+ allProxy,+ cookie: '',+ dir,+ engineMaxConnectionPerServer,+ maxConnectionPerServer,+ newTaskShowDownloading,+ out: '',+ referer: '',+ selectFile: NONE_SELECTED_FILES,+ torrent: '',+ uris: addTaskUrl,+ userAgent: '',+ ...addTaskOptions+ }+ return result}- return result-}-export default {- name: 'mo-add-task',- components: {- [SelectDirectory.name]: SelectDirectory,- [SelectTorrent.name]: SelectTorrent- },- props: {- visible: {- type: Boolean,- default: false- },- type: {- type: String,- default: ADD_TASK_TYPE.URI- }- },- data () {- return {- formLabelWidth: '100px',- showAdvanced: false,- form: {},- rules: {}- }- },- computed: {- isRenderer () { return is.renderer() },- isMas () { return is.mas() },- taskType: function () {- return this.type+ export default {+ name: 'mo-add-task',+ components: {+ [SelectDirectory.name]: SelectDirectory,+ [SelectTorrent.name]: SelectTorrent},- downloadDir: function () {- return prettifyDir(this.form.dir)- },- ...mapState('app', {- taskList: state => state.taskList- }),- ...mapState('preference', {- config: state => state.config- })- },- watch: {- taskType: function (current, previous) {- if (this.visible && previous === ADD_TASK_TYPE.URI) {- return- }-- if (current === ADD_TASK_TYPE.URI) {- setTimeout(() => {- this.$refs.uri && this.$refs.uri.focus()- }, 50)- }- }- },- methods: {- handleOpen () {- this.form = initialForm(this.$store.state)- if (this.taskType === ADD_TASK_TYPE.URI) {- this.autofillResourceLink()- setTimeout(() => {- this.$refs.uri && this.$refs.uri.focus()- }, 50)+ props: {+ visible: {+ type: Boolean,+ default: false+ },+ type: {+ type: String,+ default: ADD_TASK_TYPE.URI}},- autofillResourceLink () {- const content = this.$electron.clipboard.readText()- const hasResource = detectResource(content)- if (!hasResource) {- return- }- if (isEmpty(this.form.uris)) {- this.form.uris = content+ data () {+ return {+ formLabelWidth: '100px',+ showAdvanced: false,+ form: {},+ rules: {}}},- handleOpened () {- this.detectThunderResource(this.form.uris)- },- handleClose (done) {- this.$store.dispatch('app/hideAddTaskDialog')- this.$store.dispatch('app/updateAddTaskOptions', {})- },- handleClosed () {- this.reset()- },- handleTabClick (tab, event) {- this.$store.dispatch('app/changeAddTaskType', tab.name)- },- handleUriPaste () {- setImmediate(() => {- const uris = this.$refs.uri.value- this.detectThunderResource(uris)+ computed: {+ isRenderer () { return is.renderer() },+ isMas () { return is.mas() },+ taskType: function () {+ return this.type+ },+ downloadDir: function () {+ return prettifyDir(this.form.dir)+ },+ ...mapState('app', {+ taskList: state => state.taskList+ }),+ ...mapState('preference', {+ config: state => state.config})},- detectThunderResource (uris = '') {- if (uris.includes('thunder://')) {- this.$msg({- type: 'warning',- message: this.$t('task.thunder-link-tips'),- duration: 6000- })- }- },- handleTorrentChange (torrent, selectedFileIndex) {- this.form.torrent = torrent- this.form.selectFile = selectedFileIndex- },- onDirectorySelected (dir) {- this.form.dir = dir- },- reset () {- this.showAdvanced = false- this.form = initialForm(this.$store.state)- },- handleCancel (formName) {- this.$store.dispatch('app/hideAddTaskDialog')- },- buildHeader (form) {- const { userAgent, referer, cookie } = form- const result = []+ watch: {+ taskType: function (current, previous) {+ if (this.visible && previous === ADD_TASK_TYPE.URI) {+ return+ }- if (!isEmpty(userAgent)) {- result.push(`User-Agent: ${userAgent}`)- }- if (!isEmpty(referer)) {- result.push(`Referer: ${referer}`)- }- if (!isEmpty(cookie)) {- result.push(`Cookie: ${cookie}`)+ if (current === ADD_TASK_TYPE.URI) {+ setTimeout(() => {+ this.$refs.uri && this.$refs.uri.focus()+ }, 50)+ }}- return result},- buildOption (type, form) {- const { allProxy, dir, out, selectFile } = form- const result = {}+ methods: {+ handleOpen () {+ this.form = initialForm(this.$store.state)+ if (this.taskType === ADD_TASK_TYPE.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+ }+ if (isEmpty(this.form.uris)) {+ this.form.uris = content+ }+ },+ handleOpened () {+ this.detectThunderResource(this.form.uris)+ },+ handleClose (done) {+ this.$store.dispatch('app/hideAddTaskDialog')+ this.$store.dispatch('app/updateAddTaskOptions', {})+ },+ handleClosed () {+ this.reset()+ },+ handleTabClick (tab, event) {+ this.$store.dispatch('app/changeAddTaskType', tab.name)+ },+ handleUriPaste () {+ setImmediate(() => {+ const uris = this.$refs.uri.value+ this.detectThunderResource(uris)+ })+ },+ detectThunderResource (uris = '') {+ if (uris.includes('thunder://')) {+ this.$msg({+ type: 'warning',+ message: this.$t('task.thunder-link-tips'),+ duration: 6000+ })+ }+ },+ handleTorrentChange (torrent, selectedFileIndex) {+ this.form.torrent = torrent+ this.form.selectFile = selectedFileIndex+ },+ onDirectorySelected (dir) {+ this.form.dir = dir+ },+ reset () {+ this.showAdvanced = false+ this.form = initialForm(this.$store.state)+ },+ handleCancel (formName) {+ this.$store.dispatch('app/hideAddTaskDialog')+ },+ buildHeader (form) {+ const { userAgent, referer, cookie } = form+ const result = []- if (!isEmpty(allProxy)) {- result.allProxy = allProxy- }+ if (!isEmpty(userAgent)) {+ result.push(`User-Agent: ${userAgent}`)+ }+ if (!isEmpty(referer)) {+ result.push(`Referer: ${referer}`)+ }+ if (!isEmpty(cookie)) {+ result.push(`Cookie: ${cookie}`)+ }+ return result+ },+ buildOption (type, form) {+ const { allProxy, dir, out, selectFile } = form+ const result = {}- if (!isEmpty(dir)) {- result.dir = dir- }+ if (!isEmpty(allProxy)) {+ result.allProxy = allProxy+ }- if (!isEmpty(out)) {- result.out = out- }+ if (!isEmpty(dir)) {+ result.dir = dir+ }- if (type === ADD_TASK_TYPE.TORRENT) {- if (- selectFile !== SELECTED_ALL_FILES &&- selectFile !== NONE_SELECTED_FILES- ) {- result.selectFile = selectFile+ if (!isEmpty(out)) {+ result.out = out}- }- const header = this.buildHeader(form)- if (!isEmpty(header)) {- result.header = header- }- return result- },- buildUriPayload (form) {- let { uris, out } = form- if (isEmpty(uris)) {- throw new Error(this.$t('task.new-task-uris-required'))- }- uris = splitTaskLinks(uris)- const outs = buildOuts(uris, out)+ if (type === ADD_TASK_TYPE.TORRENT) {+ if (+ selectFile !== SELECTED_ALL_FILES &&+ selectFile !== NONE_SELECTED_FILES+ ) {+ result.selectFile = selectFile+ }+ }- const options = this.buildOption(ADD_TASK_TYPE.URI, form)- const result = {- uris,- outs,- options- }- return result- },- buildTorrentPayload (form) {- const { torrent } = form- if (isEmpty(torrent)) {- throw new Error(this.$t('task.new-task-torrent-required'))- }- const options = this.buildOption(ADD_TASK_TYPE.TORRENT, form)- const result = {- torrent,- options- }- return result- },- addTask (type, form) {- let payload = null- if (type === ADD_TASK_TYPE.URI) {- payload = this.buildUriPayload(form)- this.$store.dispatch('task/addUri', payload).catch(err => {- this.$msg.error(err.message)- })- } else if (type === ADD_TASK_TYPE.TORRENT) {- payload = this.buildTorrentPayload(form)- this.$store.dispatch('task/addTorrent', payload).catch(err => {- this.$msg.error(err.message)- })- } else if (type === 'metalink') {+ const header = this.buildHeader(form)+ if (!isEmpty(header)) {+ result.header = header+ }+ return result+ },+ buildUriPayload (form) {+ let { uris, out } = form+ if (isEmpty(uris)) {+ throw new Error(this.$t('task.new-task-uris-required'))+ }+ uris = splitTaskLinks(uris)+ const outs = buildOuts(uris, out)++ const options = this.buildOption(ADD_TASK_TYPE.URI, form)+ const result = {+ uris,+ outs,+ options+ }+ return result+ },+ buildTorrentPayload (form) {+ const { torrent } = form+ if (isEmpty(torrent)) {+ throw new Error(this.$t('task.new-task-torrent-required'))+ }+ const options = this.buildOption(ADD_TASK_TYPE.TORRENT, form)+ const result = {+ torrent,+ options+ }+ return result+ },+ addTask (type, form) {+ let payload = null+ if (type === ADD_TASK_TYPE.URI) {+ payload = this.buildUriPayload(form)+ this.$store.dispatch('task/addUri', payload).catch(err => {+ this.$msg.error(err.message)+ })+ } else if (type === ADD_TASK_TYPE.TORRENT) {+ payload = this.buildTorrentPayload(form)+ this.$store.dispatch('task/addTorrent', payload).catch(err => {+ this.$msg.error(err.message)+ })+ } else if (type === 'metalink') {// @TODO addMetalink- } else {- console.error('addTask fail', form)- }- },- submitForm (formName) {- this.$refs[formName].validate(valid => {- if (!valid) {- return false+ } else {+ console.error('addTask fail', form)}+ },+ submitForm (formName) {+ this.$refs[formName].validate(valid => {+ if (!valid) {+ return false+ }- try {- this.addTask(this.type, this.form)+ try {+ this.addTask(this.type, this.form)- this.$store.dispatch('app/hideAddTaskDialog')- if (this.form.newTaskShowDownloading) {- this.$router.push({- path: '/task/active'- }).catch(err => {- console.log(err)- })+ this.$store.dispatch('app/hideAddTaskDialog')+ if (this.form.newTaskShowDownloading) {+ this.$router.push({+ path: '/task/active'+ }).catch(err => {+ console.log(err)+ })+ }+ } catch (err) {+ this.$msg.error(err.message)}- } catch (err) {- this.$msg.error(err.message)- }- })+ })+ }}}-}</script><style lang="scss">diff --git a/src/renderer/components/Task/Index.vue b/src/renderer/components/Task/Index.vueindex 5500cddd..f4fd1c3a 100644--- a/src/renderer/components/Task/Index.vue+++ b/src/renderer/components/Task/Index.vue@@ -33,65 +33,65 @@</template><script>-import TaskSubnav from '@/components/Subnav/TaskSubnav'-import TaskActions from '@/components/Task/TaskActions'-import TaskList from '@/components/Task/TaskList'-import SubnavSwitcher from '@/components/Subnav/SubnavSwitcher'+ import TaskSubnav from '@/components/Subnav/TaskSubnav'+ import TaskActions from '@/components/Task/TaskActions'+ import TaskList from '@/components/Task/TaskList'+ import SubnavSwitcher from '@/components/Subnav/SubnavSwitcher'-export default {- name: 'mo-content-task',- components: {- [TaskSubnav.name]: TaskSubnav,- [TaskActions.name]: TaskActions,- [TaskList.name]: TaskList,- [SubnavSwitcher.name]: SubnavSwitcher- },- props: {- status: {- type: String,- default: 'active'- }- },- computed: {- subnavs: function () {- return [- {- key: 'active',- title: this.$t('task.active'),- route: '/task/active'- },- {- key: 'waiting',- title: this.$t('task.waiting'),- route: '/task/waiting'- },- {- key: 'stopped',- title: this.$t('task.stopped'),- route: '/task/stopped'- }- ]+ export default {+ name: 'mo-content-task',+ components: {+ [TaskSubnav.name]: TaskSubnav,+ [TaskActions.name]: TaskActions,+ [TaskList.name]: TaskList,+ [SubnavSwitcher.name]: SubnavSwitcher},- title: function () {- const subnav = this.subnavs.find((item) => item.key === this.status)- return subnav.title- }- },- watch: {- status: 'onStatusChange'- },- methods: {- onStatusChange () {- this.changeCurrentList()+ props: {+ status: {+ type: String,+ default: 'active'+ }+ },+ computed: {+ subnavs: function () {+ return [+ {+ key: 'active',+ title: this.$t('task.active'),+ route: '/task/active'+ },+ {+ key: 'waiting',+ title: this.$t('task.waiting'),+ route: '/task/waiting'+ },+ {+ key: 'stopped',+ title: this.$t('task.stopped'),+ route: '/task/stopped'+ }+ ]+ },+ title: function () {+ const subnav = this.subnavs.find((item) => item.key === this.status)+ return subnav.title+ }},- changeCurrentList () {- this.$store.dispatch('task/changeCurrentList', this.status)+ watch: {+ status: 'onStatusChange'+ },+ methods: {+ onStatusChange () {+ this.changeCurrentList()+ },+ changeCurrentList () {+ this.$store.dispatch('task/changeCurrentList', this.status)+ }+ },+ created: function () {+ this.changeCurrentList()}- },- created: function () {- this.changeCurrentList()}-}</script><style lang="scss">