feat: file drop

This commit is contained in:
TaurusXin 2025-02-01 12:11:13 +08:00
parent 36fd04f975
commit 7402e35d66
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC
2 changed files with 14 additions and 2 deletions

View File

@ -40,7 +40,7 @@ import {
import { Status, Item, SaveTo } from './types' import { Status, Item, SaveTo } from './types'
import { SelectFiles, SelectFolder, ProcessFiles } from '../wailsjs/go/main/App' import { SelectFiles, SelectFolder, ProcessFiles } from '../wailsjs/go/main/App'
import { main } from '../wailsjs/go/models' import { main } from '../wailsjs/go/models'
import { EventsOn } from '../wailsjs/runtime/runtime' import { EventsOn, OnFileDrop } from '../wailsjs/runtime/runtime'
const columnsDef: TableColumnDefinition<Item>[] = [ const columnsDef: TableColumnDefinition<Item>[] = [
createTableColumn<Item>({ createTableColumn<Item>({
@ -135,7 +135,7 @@ export const App = () => {
for (const file of files) { for (const file of files) {
setItems(prev => [...prev, { file, status: 'pending' }]) setItems(prev => [...prev, { file, status: 'pending' }])
} }
setTotalFilesNeedToProcess(files.length) setTotalFilesNeedToProcess(prev => prev + files.length)
}) })
} }
@ -194,6 +194,14 @@ export const App = () => {
} }
}, [finishedCount]) }, [finishedCount])
OnFileDrop((_x, _y, paths) => {
for (const path of paths) {
setItems(prev => [...prev, { file: path, status: 'pending' }])
}
console.log(paths.length, paths)
setTotalFilesNeedToProcess(prev => prev + paths.length)
}, false)
return ( return (
<div className="p-3"> <div className="p-3">
<Dialog <Dialog

View File

@ -28,6 +28,10 @@ func main() {
Bind: []interface{}{ Bind: []interface{}{
app, app,
}, },
DragAndDrop: &options.DragAndDrop{
EnableFileDrop: true,
DisableWebViewDrop: true,
},
}) })
if err != nil { if err != nil {