zenity icon indicating copy to clipboard operation
zenity copied to clipboard

Context cancellation does not close file selection dialogs immediately on Windows

Open gz-95 opened this issue 5 months ago • 5 comments

Thanks for this really helpful library! Just having some trouble with closing the dialogs programmatically.

It seems that when the context is canceled, the dialog remains open until the user interacts with it e.g. navigating different directories etc. Here's an example code that reproduces the issue on Windows 10.0.19045 Build 19045

package main

import (
	"context"
	"fmt"

	"github.com/ncruces/zenity"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	stop := context.AfterFunc(ctx, func() {
		fmt.Println("canceled!")
	})

	defer stop()

	file, err := zenity.SelectFile(
		zenity.Context(ctx),
	)

	if err != nil {
		panic(err)
	}

	fmt.Println("select", file)
}

Basically, the call to zenity.SelectFile is blocked with no way of returning even if the context has expired unless the user is actively interacting with the underlying dialog.

gz-95 avatar Sep 11 '24 06:09 gz-95