Skip to content

Commit

Permalink
✨ Feature: support dragging any type of file to upload
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #1052
  • Loading branch information
Molunerfinn committed Jan 11, 2023
1 parent 911e34e commit 520d6d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
27 changes: 16 additions & 11 deletions src/renderer/pages/MiniPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ watch(progress, (val) => {
function onDrop (e: DragEvent) {
dragover.value = false
const items = e.dataTransfer!.items
if (items.length === 2 && items[0].type === 'text/uri-list') {
handleURLDrag(items, e.dataTransfer!)
} else if (items[0].type === 'text/plain') {
const str = e.dataTransfer!.getData(items[0].type)
if (isUrl(str)) {
sendToMain('uploadChoosedFiles', [{ path: str }])
} else {
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
}
const items = e.dataTransfer?.items!
const files = e.dataTransfer?.files!
// send files first
if (files?.length) {
ipcSendFiles(e.dataTransfer?.files!)
} else {
ipcSendFiles(e.dataTransfer!.files)
if (items.length === 2 && items[0].type === 'text/uri-list') {
handleURLDrag(items, e.dataTransfer!)
} else if (items[0].type === 'text/plain') {
const str = e.dataTransfer!.getData(items[0].type)
if (isUrl(str)) {
sendToMain('uploadChoosedFiles', [{ path: str }])
} else {
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
}
}
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/renderer/pages/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,23 @@ onBeforeUnmount(() => {
function onDrop (e: DragEvent) {
dragover.value = false
const items = e.dataTransfer!.items
if (items.length === 2 && items[0].type === 'text/uri-list') {
handleURLDrag(items, e.dataTransfer!)
} else if (items[0].type === 'text/plain') {
const str = e.dataTransfer!.getData(items[0].type)
if (isUrl(str)) {
sendToMain('uploadChoosedFiles', [{ path: str }])
} else {
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
}
const items = e.dataTransfer?.items!
const files = e.dataTransfer?.files!
// send files first
if (files?.length) {
ipcSendFiles(e.dataTransfer?.files!)
} else {
ipcSendFiles(e.dataTransfer!.files)
if (items.length === 2 && items[0].type === 'text/uri-list') {
handleURLDrag(items, e.dataTransfer!)
} else if (items[0].type === 'text/plain') {
const str = e.dataTransfer!.getData(items[0].type)
if (isUrl(str)) {
sendToMain('uploadChoosedFiles', [{ path: str }])
} else {
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
}
}
}
}
Expand Down

0 comments on commit 520d6d3

Please sign in to comment.