mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
implement file drop API.
This commit is contained in:
parent
64187964d4
commit
62ba53dc46
23
internal/api/room/drop.go
Normal file
23
internal/api/room/drop.go
Normal file
@ -0,0 +1,23 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
type DropPayload struct {
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
Files []string `json:"files"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) dropFiles(w http.ResponseWriter, r *http.Request) {
|
||||
data := &DropPayload{}
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
return
|
||||
}
|
||||
|
||||
h.desktop.DropFiles(data.X, data.Y, data.Files)
|
||||
utils.HttpSuccess(w)
|
||||
}
|
@ -60,4 +60,8 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
r.With(auth.AdminsOnly).Post("/", h.screenConfigurationChange)
|
||||
r.With(auth.AdminsOnly).Get("/configurations", h.screenConfigurationsList)
|
||||
})
|
||||
|
||||
r.Route("/drop", func(r chi.Router) {
|
||||
r.With(auth.AdminsOnly).Post("/", h.dropFiles)
|
||||
})
|
||||
}
|
||||
|
24
internal/desktop/drop.go
Normal file
24
internal/desktop/drop.go
Normal file
@ -0,0 +1,24 @@
|
||||
package desktop
|
||||
|
||||
import (
|
||||
"time"
|
||||
"demodesk/neko/internal/desktop/drop"
|
||||
)
|
||||
|
||||
const (
|
||||
DELAY = 100 * time.Millisecond
|
||||
)
|
||||
|
||||
func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) {
|
||||
go drop.DragWindow(files)
|
||||
|
||||
// TODO: Find a bettter way.
|
||||
time.Sleep(DELAY)
|
||||
manager.Move(10, 10)
|
||||
manager.ButtonDown(1)
|
||||
manager.Move(x, y)
|
||||
time.Sleep(DELAY)
|
||||
manager.Move(x, y)
|
||||
time.Sleep(DELAY)
|
||||
manager.ButtonUp(1)
|
||||
}
|
@ -35,4 +35,7 @@ type DesktopManager interface {
|
||||
// clipboard
|
||||
ReadClipboard() string
|
||||
WriteClipboard(data string)
|
||||
|
||||
// drop
|
||||
DropFiles(x int, y int, files []string)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user