From 649da2441de431b12e2deee9140eb89c03c98c5f Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 23 Feb 2024 13:07:06 +0000 Subject: [PATCH] Optimize contexts that never cancel. --- date_windows.go | 2 +- entry_windows.go | 2 +- list_windows.go | 2 +- notify_windows.go | 2 +- progress_windows.go | 2 +- pwd_windows.go | 2 +- util_windows.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/date_windows.go b/date_windows.go index 40fdf06..33b84a6 100644 --- a/date_windows.go +++ b/date_windows.go @@ -102,7 +102,7 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) { win.SetFocus(dlg.dateCtl) win.ShowWindow(dlg.wnd, win.SW_NORMAL) - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { wait := make(chan struct{}) defer close(wait) go func() { diff --git a/entry_windows.go b/entry_windows.go index 6b10dc2..ee81193 100644 --- a/entry_windows.go +++ b/entry_windows.go @@ -97,7 +97,7 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) { win.ShowWindow(dlg.wnd, win.SW_NORMAL) win.SendMessage(dlg.editCtl, win.EM_SETSEL, 0, intptr(-1)) - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { wait := make(chan struct{}) defer close(wait) go func() { diff --git a/list_windows.go b/list_windows.go index 605b426..70fcad3 100644 --- a/list_windows.go +++ b/list_windows.go @@ -128,7 +128,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) { win.SetFocus(dlg.listCtl) win.ShowWindow(dlg.wnd, win.SW_NORMAL) - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { wait := make(chan struct{}) defer close(wait) go func() { diff --git a/notify_windows.go b/notify_windows.go index 39e40f8..808f20b 100644 --- a/notify_windows.go +++ b/notify_windows.go @@ -121,7 +121,7 @@ func shellNotify(text string, opts options) error { major, minor, _ := win.RtlGetNtVersionNumbers() // On Windows 7 (6.1) and lower, wait up to 10 seconds to clean up. if major < 6 || major == 6 && minor < 2 { - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { select { case <-opts.ctx.Done(): case <-time.After(10 * time.Second): diff --git a/progress_windows.go b/progress_windows.go index c9d3fa1..e67dea6 100644 --- a/progress_windows.go +++ b/progress_windows.go @@ -190,7 +190,7 @@ func (dlg *progressDialog) setup(opts options) error { } once.Do(dlg.init.Done) - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { wait := make(chan struct{}) defer close(wait) go func() { diff --git a/pwd_windows.go b/pwd_windows.go index 58b7d6c..d4fe3c2 100644 --- a/pwd_windows.go +++ b/pwd_windows.go @@ -113,7 +113,7 @@ func (dlg *passwordDialog) setup(opts options) (string, string, error) { win.ShowWindow(dlg.wnd, win.SW_NORMAL) win.SendMessage(dlg.uEditCtl, win.EM_SETSEL, 0, intptr(-1)) - if opts.ctx != nil { + if opts.ctx != nil && opts.ctx.Done() != nil { wait := make(chan struct{}) defer close(wait) go func() { diff --git a/util_windows.go b/util_windows.go index 7f609af..8ee8870 100644 --- a/util_windows.go +++ b/util_windows.go @@ -118,7 +118,7 @@ func newDialogHook(ctx context.Context, icon any, title *string, init func(wnd w title: title, init: init, } - if ctx != nil { + if ctx != nil && ctx.Done() != nil { hook.done = make(chan struct{}) go hook.wait() }