fix dialog close and add API.

This commit is contained in:
Miroslav Šedivý 2021-01-18 10:34:33 +01:00
parent 2b3bb6e21a
commit 8f60041b2d
4 changed files with 34 additions and 16 deletions

View File

@ -69,7 +69,8 @@ func (h *RoomHandler) Route(r chi.Router) {
r.With(h.uploadMiddleware).Route("/upload", func(r chi.Router) { r.With(h.uploadMiddleware).Route("/upload", func(r chi.Router) {
r.Post("/drop", h.uploadDrop) r.Post("/drop", h.uploadDrop)
r.Post("/dialog", h.uploadDialog) r.Post("/dialog", h.uploadDialogPost)
r.Delete("/dialog", h.uploadDialogClose)
}) })
} }

View File

@ -87,8 +87,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w) utils.HttpSuccess(w)
} }
func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) {
func (h *RoomHandler) uploadDialog(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(MAX_UPLOAD_SIZE) r.ParseMultipartForm(MAX_UPLOAD_SIZE)
if r.MultipartForm == nil { if r.MultipartForm == nil {
@ -148,3 +147,17 @@ func (h *RoomHandler) uploadDialog(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w) utils.HttpSuccess(w)
} }
func (h *RoomHandler) uploadDialogClose(w http.ResponseWriter, r *http.Request) {
if !h.desktop.IsFileChooserDialogOpen() {
utils.HttpBadRequest(w, "File chooser dialog is not open.")
return
}
if !h.desktop.CloseFileChooserDialog() {
utils.HttpInternalServerError(w, "Unable to close file chooser dialog.")
return
}
utils.HttpSuccess(w)
}

View File

@ -27,20 +27,24 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
return err return err
} }
func (manager *DesktopManagerCtx) CloseFileChooserDialog() error { func (manager *DesktopManagerCtx) CloseFileChooserDialog() bool {
mu.Lock() for i := 0; i < 5; i++ {
defer mu.Unlock() // TOOD: Use native API.
mu.Lock()
exec.Command(
"xdotool",
"search", "--name", "Open", "windowfocus",
"sleep", "0.2",
"key", "--clearmodifiers", "alt+F4",
).Output()
mu.Unlock()
// TOOD: Use native API. if !manager.IsFileChooserDialogOpen() {
cmd := exec.Command( return true
"xdotool", }
"search", "--name", "Open", "windowfocus", }
"sleep", "0.2",
"key", "--clearmodifiers", "alt+f4",
)
_, err := cmd.Output() return false
return err
} }
func (manager *DesktopManagerCtx) IsFileChooserDialogOpen() bool { func (manager *DesktopManagerCtx) IsFileChooserDialogOpen() bool {

View File

@ -69,6 +69,6 @@ type DesktopManager interface {
// filechooser // filechooser
HandleFileChooserDialog(uri string) error HandleFileChooserDialog(uri string) error
CloseFileChooserDialog() error CloseFileChooserDialog() bool
IsFileChooserDialogOpen() bool IsFileChooserDialogOpen() bool
} }