neko/internal/desktop/filechooser.go

61 lines
1.2 KiB
Go
Raw Normal View History

2021-01-18 11:50:03 +13:00
package desktop
import (
"os/exec"
)
func (manager *DesktopManagerCtx) HandleFileChooserDialog(uri string) error {
mu.Lock()
defer mu.Unlock()
// TOOD: Use native API.
2021-01-19 03:31:00 +13:00
cmd := exec.Command(
2021-01-18 11:50:03 +13:00
"xdotool",
"search", "--name", "Open File", "windowfocus",
2021-01-18 11:50:03 +13:00
"sleep", "0.2",
"key", "--clearmodifiers", "ctrl+l",
"type", "--args", "1", uri + "//",
"key", "--clearmodifiers", "Return",
"sleep", "1",
"key", "--clearmodifiers", "Down",
"key", "--clearmodifiers", "ctrl+a",
"key", "--clearmodifiers", "Return",
"sleep", "0.3",
)
_, err := cmd.Output()
return err
}
func (manager *DesktopManagerCtx) CloseFileChooserDialog() {
2021-01-18 22:34:33 +13:00
for i := 0; i < 5; i++ {
if !manager.IsFileChooserDialogOpened() {
return
}
2021-01-18 22:34:33 +13:00
// TOOD: Use native API.
mu.Lock()
exec.Command(
"xdotool",
"search", "--name", "Open File", "windowfocus",
2021-01-18 22:34:33 +13:00
"sleep", "0.2",
"key", "--clearmodifiers", "alt+F4",
).Output()
mu.Unlock()
}
2021-01-18 11:50:03 +13:00
}
func (manager *DesktopManagerCtx) IsFileChooserDialogOpened() bool {
2021-01-18 11:50:03 +13:00
mu.Lock()
defer mu.Unlock()
// TOOD: Use native API.
2021-01-19 03:31:00 +13:00
cmd := exec.Command(
2021-01-18 11:50:03 +13:00
"xdotool",
"search", "--name", "Open File",
2021-01-18 11:50:03 +13:00
)
_, err := cmd.Output()
return err == nil
}