Skip to content

Context cancellation does not close file selection dialogs immediately on Windows #119

@gz-95

Description

@gz-95

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions