mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix dialog close and add API.
This commit is contained in:
parent
2b3bb6e21a
commit
8f60041b2d
@ -69,7 +69,8 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
|
||||
r.With(h.uploadMiddleware).Route("/upload", func(r chi.Router) {
|
||||
r.Post("/drop", h.uploadDrop)
|
||||
r.Post("/dialog", h.uploadDialog)
|
||||
r.Post("/dialog", h.uploadDialogPost)
|
||||
r.Delete("/dialog", h.uploadDialogClose)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,7 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
|
||||
func (h *RoomHandler) uploadDialog(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseMultipartForm(MAX_UPLOAD_SIZE)
|
||||
|
||||
if r.MultipartForm == nil {
|
||||
@ -148,3 +147,17 @@ func (h *RoomHandler) uploadDialog(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -27,20 +27,24 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) CloseFileChooserDialog() error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
func (manager *DesktopManagerCtx) CloseFileChooserDialog() bool {
|
||||
for i := 0; i < 5; i++ {
|
||||
// TOOD: Use native API.
|
||||
cmd := exec.Command(
|
||||
mu.Lock()
|
||||
exec.Command(
|
||||
"xdotool",
|
||||
"search", "--name", "Open", "windowfocus",
|
||||
"sleep", "0.2",
|
||||
"key", "--clearmodifiers", "alt+f4",
|
||||
)
|
||||
"key", "--clearmodifiers", "alt+F4",
|
||||
).Output()
|
||||
mu.Unlock()
|
||||
|
||||
_, err := cmd.Output()
|
||||
return err
|
||||
if !manager.IsFileChooserDialogOpen() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) IsFileChooserDialogOpen() bool {
|
||||
|
@ -69,6 +69,6 @@ type DesktopManager interface {
|
||||
|
||||
// filechooser
|
||||
HandleFileChooserDialog(uri string) error
|
||||
CloseFileChooserDialog() error
|
||||
CloseFileChooserDialog() bool
|
||||
IsFileChooserDialogOpen() bool
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user