Parse drag data manually to avoid GetURIs crashes

This commit is contained in:
Stu 2025-12-13 22:46:46 -05:00
parent 20c4b5d177
commit 29bc1ac19c

View File

@ -5,6 +5,7 @@ import (
"log"
"path/filepath"
"time"
"strings"
"git.leaktechnologies.dev/stu/VT_Player/player/mpvembed"
@ -288,19 +289,28 @@ func setupDragDest(p *pane, win *gtk.Window) {
if data == nil {
return
}
var path string
if uris := data.GetURIs(); len(uris) > 0 {
path = uriToPath(uris[0])
}
if path == "" {
raw := data.GetData()
if len(raw) == 0 {
// try text fallback
if txt := data.GetText(); txt != "" {
path = uriToPath(txt)
raw = []byte(txt)
}
}
if path == "" {
if len(raw) == 0 {
return
}
loadIntoPane(p, path)
// text/uri-list: newline or CRLF separated
lines := strings.Split(string(raw), "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if ln == "" {
continue
}
if path := uriToPath(ln); path != "" {
loadIntoPane(p, path)
break
}
}
})
}