2021-01-15 07:53:58 +13:00
|
|
|
package desktop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-07-14 10:58:22 +12:00
|
|
|
"github.com/demodesk/neko/pkg/drop"
|
2021-01-15 07:53:58 +13:00
|
|
|
)
|
|
|
|
|
2021-09-03 07:37:24 +12:00
|
|
|
// repeat move event multiple times
|
|
|
|
const dropMoveRepeat = 4
|
|
|
|
|
|
|
|
// wait after each repeated move event
|
|
|
|
const dropMoveDelay = 100 * time.Millisecond
|
2021-01-15 07:53:58 +13:00
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
|
|
|
|
drop.Emmiter.Clear()
|
|
|
|
|
|
|
|
drop.Emmiter.Once("create", func(payload ...interface{}) {
|
|
|
|
manager.Move(0, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
drop.Emmiter.Once("cursor-enter", func(payload ...interface{}) {
|
2021-01-26 05:33:29 +13:00
|
|
|
//nolint
|
2021-01-15 07:53:58 +13:00
|
|
|
manager.ButtonDown(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
drop.Emmiter.Once("button-press", func(payload ...interface{}) {
|
|
|
|
manager.Move(x, y)
|
|
|
|
})
|
|
|
|
|
|
|
|
drop.Emmiter.Once("begin", func(payload ...interface{}) {
|
2021-09-03 07:37:24 +12:00
|
|
|
for i := 0; i < dropMoveRepeat; i++ {
|
2021-01-16 06:00:04 +13:00
|
|
|
manager.Move(x, y)
|
2021-09-03 07:37:24 +12:00
|
|
|
time.Sleep(dropMoveDelay)
|
2021-01-16 06:00:04 +13:00
|
|
|
}
|
|
|
|
|
2021-01-26 05:33:29 +13:00
|
|
|
//nolint
|
2021-01-15 07:53:58 +13:00
|
|
|
manager.ButtonUp(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
finished := make(chan bool)
|
|
|
|
drop.Emmiter.Once("finish", func(payload ...interface{}) {
|
|
|
|
finished <- payload[0].(bool)
|
|
|
|
})
|
|
|
|
|
2021-01-26 05:33:29 +13:00
|
|
|
manager.ResetKeys()
|
2021-01-15 07:53:58 +13:00
|
|
|
go drop.OpenWindow(files)
|
|
|
|
|
|
|
|
select {
|
2021-02-15 02:40:17 +13:00
|
|
|
case succeeded := <-finished:
|
2021-01-15 07:53:58 +13:00
|
|
|
return succeeded
|
|
|
|
case <-time.After(1 * time.Second):
|
2021-02-15 02:40:17 +13:00
|
|
|
drop.CloseWindow()
|
2021-01-15 07:53:58 +13:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|