HandleFileChooserDialog: fix auocomplete bug.

This commit is contained in:
Miroslav Šedivý 2021-01-25 20:23:40 +01:00
parent 7cbee94a80
commit c27658d54c

View File

@ -1,13 +1,15 @@
package desktop package desktop
import ( import (
"fmt"
"time" "time"
"os/exec" "os/exec"
) )
const ( const (
FILE_CHOOSER_DIALOG_NAME = "Open File" FILE_CHOOSER_DIALOG_NAME = "Open File"
FILE_CHOOSER_DIALOG_SLEEP = "0.2" FILE_CHOOSER_DIALOG_SHORT_SLEEP = "0.2"
FILE_CHOOSER_DIALOG_LONG_SLEEP = "0.4"
) )
func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error { func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
@ -15,28 +17,39 @@ func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
defer mu.Unlock() defer mu.Unlock()
// TODO: Use native API. // TODO: Use native API.
err := exec.Command( err1 := exec.Command(
"xdotool", "xdotool",
"search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus", "search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus",
"sleep", FILE_CHOOSER_DIALOG_SLEEP, "sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
"key", "--clearmodifiers", "ctrl+l", "key", "--clearmodifiers", "ctrl+l",
"type", "--args", "1", uri + "//", "type", "--args", "1", uri + "//",
"sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
"key", "Delete", // remove autocomplete results
"sleep", FILE_CHOOSER_DIALOG_SHORT_SLEEP,
"key", "Return", "key", "Return",
"sleep", FILE_CHOOSER_DIALOG_SLEEP, "sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP,
).Run()
//nolint
exec.Command(
"xdotool",
"search", "--name", FILE_CHOOSER_DIALOG_NAME, "windowfocus",
"sleep", FILE_CHOOSER_DIALOG_SLEEP,
"key", "Down", "key", "Down",
"key", "--clearmodifiers", "ctrl+a", "key", "--clearmodifiers", "ctrl+a",
"key", "Return", "key", "Return",
"sleep", FILE_CHOOSER_DIALOG_SLEEP, "sleep", FILE_CHOOSER_DIALOG_LONG_SLEEP,
).Run() ).Run()
return err if err1 != nil {
return err1
}
// TODO: Use native API.
err2 := exec.Command(
"xdotool",
"search", "--name", FILE_CHOOSER_DIALOG_NAME,
).Run()
// if last command didn't return error, consider dialog as still open
if err2 == nil {
return fmt.Errorf("unable to select files in dialog")
}
return nil
} }
func (manager *DesktopManagerCtx) CloseFileChooserDialog() { func (manager *DesktopManagerCtx) CloseFileChooserDialog() {