2021-01-14 19:53:58 +01:00
|
|
|
package desktop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-07-14 00:58:22 +02:00
|
|
|
"github.com/demodesk/neko/pkg/drop"
|
2021-01-14 19:53:58 +01:00
|
|
|
)
|
|
|
|
|
2021-09-02 21:37:24 +02:00
|
|
|
// repeat move event multiple times
|
|
|
|
const dropMoveRepeat = 4
|
|
|
|
|
|
|
|
// wait after each repeated move event
|
|
|
|
const dropMoveDelay = 100 * time.Millisecond
|
2021-01-14 19:53:58 +01:00
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
|
|
|
|
drop.Emmiter.Clear()
|
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
drop.Emmiter.Once("create", func(payload ...any) {
|
2021-01-14 19:53:58 +01:00
|
|
|
manager.Move(0, 0)
|
|
|
|
})
|
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
drop.Emmiter.Once("cursor-enter", func(payload ...any) {
|
2021-01-25 17:33:29 +01:00
|
|
|
//nolint
|
2021-01-14 19:53:58 +01:00
|
|
|
manager.ButtonDown(1)
|
|
|
|
})
|
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
drop.Emmiter.Once("button-press", func(payload ...any) {
|
2021-01-14 19:53:58 +01:00
|
|
|
manager.Move(x, y)
|
|
|
|
})
|
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
drop.Emmiter.Once("begin", func(payload ...any) {
|
2021-09-02 21:37:24 +02:00
|
|
|
for i := 0; i < dropMoveRepeat; i++ {
|
2021-01-15 18:00:04 +01:00
|
|
|
manager.Move(x, y)
|
2021-09-02 21:37:24 +02:00
|
|
|
time.Sleep(dropMoveDelay)
|
2021-01-15 18:00:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-25 17:33:29 +01:00
|
|
|
//nolint
|
2021-01-14 19:53:58 +01:00
|
|
|
manager.ButtonUp(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
finished := make(chan bool)
|
2022-07-28 12:20:20 +02:00
|
|
|
drop.Emmiter.Once("finish", func(payload ...any) {
|
2022-09-11 22:48:55 +02:00
|
|
|
b, ok := payload[0].(bool)
|
|
|
|
// workaround until https://github.com/kataras/go-events/pull/8 is merged
|
|
|
|
if !ok {
|
|
|
|
b = (payload[0].([]any))[0].(bool)
|
|
|
|
}
|
|
|
|
finished <- b
|
2021-01-14 19:53:58 +01:00
|
|
|
})
|
|
|
|
|
2021-01-25 17:33:29 +01:00
|
|
|
manager.ResetKeys()
|
2021-01-14 19:53:58 +01:00
|
|
|
go drop.OpenWindow(files)
|
|
|
|
|
|
|
|
select {
|
2021-02-14 14:40:17 +01:00
|
|
|
case succeeded := <-finished:
|
2021-01-14 19:53:58 +01:00
|
|
|
return succeeded
|
|
|
|
case <-time.After(1 * time.Second):
|
2021-02-14 14:40:17 +01:00
|
|
|
drop.CloseWindow()
|
2021-01-14 19:53:58 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|