Fix hidden dialogs.

This commit is contained in:
Nuno Cruces 2021-01-05 15:20:42 +00:00
parent 4a39a18f0a
commit 3770f9924a
5 changed files with 39 additions and 9 deletions

View file

@ -54,6 +54,7 @@ func selectColor(options []Option) (color.Color, error) {
defer unhook()
}
activate()
s, _, _ := chooseColor.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil {
return nil, opts.ctx.Err()

View file

@ -54,6 +54,7 @@ func selectFile(options []Option) (string, error) {
defer unhook()
}
activate()
s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil {
return "", opts.ctx.Err()
@ -101,6 +102,7 @@ func selectFileMutiple(options []Option) ([]string, error) {
defer unhook()
}
activate()
s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil {
return nil, opts.ctx.Err()
@ -179,6 +181,7 @@ func selectFileSave(options []Option) (string, error) {
defer unhook()
}
activate()
s, _, _ := getSaveFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil {
return "", opts.ctx.Err()
@ -253,6 +256,7 @@ func pickFolders(opts options, multi bool) (str string, lst []string, err error)
defer unhook()
}
activate()
hr, _, _ = dialog.Call(dialog.vtbl.Show, 0)
if opts.ctx != nil && opts.ctx.Err() != nil {
return "", nil, opts.ctx.Err()
@ -335,6 +339,7 @@ func browseForFolder(opts options) (string, []string, error) {
defer unhook()
}
activate()
ptr, _, _ := shBrowseForFolder.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil {
return "", nil, opts.ctx.Err()

View file

@ -1,6 +1,5 @@
var app = Application.currentApplication()
app.includeStandardAdditions = true
app.activate()
var opts = {}

View file

@ -53,6 +53,7 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
defer unhook()
}
activate()
s, _, err := messageBox.Call(0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(opts.title))), flags)

View file

@ -3,6 +3,7 @@ package zenity
import (
"context"
"fmt"
"os"
"sync"
"syscall"
"unsafe"
@ -19,22 +20,45 @@ var (
commDlgExtendedError = comdlg32.NewProc("CommDlgExtendedError")
getCurrentThreadId = kernel32.NewProc("GetCurrentThreadId")
getConsoleWindow = kernel32.NewProc("GetConsoleWindow")
coInitializeEx = ole32.NewProc("CoInitializeEx")
coUninitialize = ole32.NewProc("CoUninitialize")
coCreateInstance = ole32.NewProc("CoCreateInstance")
coTaskMemFree = ole32.NewProc("CoTaskMemFree")
sendMessage = user32.NewProc("SendMessageW")
getClassName = user32.NewProc("GetClassNameW")
setWindowsHookEx = user32.NewProc("SetWindowsHookExW")
unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx")
callNextHookEx = user32.NewProc("CallNextHookEx")
enumChildWindows = user32.NewProc("EnumChildWindows")
getDlgCtrlID = user32.NewProc("GetDlgCtrlID")
setWindowText = user32.NewProc("SetWindowTextW")
sendMessage = user32.NewProc("SendMessageW")
getClassName = user32.NewProc("GetClassNameW")
setWindowsHookEx = user32.NewProc("SetWindowsHookExW")
unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx")
callNextHookEx = user32.NewProc("CallNextHookEx")
enumWindows = user32.NewProc("EnumWindows")
enumChildWindows = user32.NewProc("EnumChildWindows")
getDlgCtrlID = user32.NewProc("GetDlgCtrlID")
setWindowText = user32.NewProc("SetWindowTextW")
setForegroundWindow = user32.NewProc("SetForegroundWindow")
getWindowThreadProcessId = user32.NewProc("GetWindowThreadProcessId")
)
func activate() {
var hwnd uintptr
enumWindows.Call(syscall.NewCallback(func(wnd, lparam uintptr) uintptr {
var pid uintptr
getWindowThreadProcessId.Call(wnd, uintptr(unsafe.Pointer(&pid)))
if int(pid) == os.Getpid() {
hwnd = wnd
return 0
}
return 1
}), 0)
if hwnd == 0 {
hwnd, _, _ = getConsoleWindow.Call()
}
if hwnd != 0 {
setForegroundWindow.Call(hwnd)
}
}
func commDlgError() error {
s, _, _ := commDlgExtendedError.Call()
if s == 0 {