From 3adf86dd3987bea360a5d33c8285082488fc3521 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 8 Jun 2022 23:52:44 +0100 Subject: [PATCH] Fix window icons (macOS). --- color_darwin.go | 3 ++- date_darwin.go | 3 +++ entry_darwin.go | 3 ++- file_darwin.go | 9 ++++++--- internal/zenutil/osa_generated.go | 4 ++-- internal/zenutil/osascripts/common.gojs | 4 ++-- list_darwin.go | 3 ++- msg_darwin.go | 3 ++- progress_darwin.go | 3 +++ pwd_darwin.go | 3 ++- 10 files changed, 26 insertions(+), 12 deletions(-) diff --git a/color_darwin.go b/color_darwin.go index 810d2d1..6523587 100644 --- a/color_darwin.go +++ b/color_darwin.go @@ -10,7 +10,8 @@ func selectColor(opts options) (color.Color, error) { var data zenutil.Color if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/date_darwin.go b/date_darwin.go index 2c9954e..03da0d5 100644 --- a/date_darwin.go +++ b/date_darwin.go @@ -25,6 +25,9 @@ func calendar(text string, opts options) (t time.Time, err error) { } else { data.Text = text } + if opts.attach != nil { + data.Application = opts.attach + } if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/entry_darwin.go b/entry_darwin.go index 5d4dddd..233f944 100644 --- a/entry_darwin.go +++ b/entry_darwin.go @@ -16,7 +16,8 @@ func entry(text string, opts options) (string, error) { data.Options.Timeout = zenutil.Timeout if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } switch i := opts.icon.(type) { diff --git a/file_darwin.go b/file_darwin.go index e8d5c64..2f11bab 100644 --- a/file_darwin.go +++ b/file_darwin.go @@ -9,7 +9,8 @@ func selectFile(opts options) (string, error) { data.Options.Location, _ = splitDirAndName(opts.filename) if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } @@ -33,7 +34,8 @@ func selectFileMultiple(opts options) ([]string, error) { data.Separator = zenutil.Separator if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } @@ -55,7 +57,8 @@ func selectFileSave(opts options) (string, error) { data.Options.Location, data.Options.Name = splitDirAndName(opts.filename) if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index d7b5c4f..2e1d1ad 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -27,11 +27,11 @@ var app=Application({{json .Application}}) {{- else}} var app=Application.currentApplication() {{- end}} -{{- if .WindowIcon}}{ObjC.import('Cocoa') +{{if .WindowIcon}}{ObjC.import('Cocoa') let nsapp=$.NSApplication.sharedApplication let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) -nsapp.setApplicationIconImage(nsimg)}{{- end}} +nsapp.setApplicationIconImage(nsimg)}{{end}} app.includeStandardAdditions=true app.activate() {{- end}} diff --git a/internal/zenutil/osascripts/common.gojs b/internal/zenutil/osascripts/common.gojs index 08928e8..3b0de34 100644 --- a/internal/zenutil/osascripts/common.gojs +++ b/internal/zenutil/osascripts/common.gojs @@ -4,13 +4,13 @@ var app = Application.currentApplication() {{- end}} -{{- if .WindowIcon}}{ +{{if .WindowIcon}}{ ObjC.import('Cocoa') let nsapp = $.NSApplication.sharedApplication let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) nsapp.setApplicationIconImage(nsimg) -}{{- end}} +}{{end}} app.includeStandardAdditions = true app.activate() \ No newline at end of file diff --git a/list_darwin.go b/list_darwin.go index f1a15d1..b0df3ac 100644 --- a/list_darwin.go +++ b/list_darwin.go @@ -24,7 +24,8 @@ func list(text string, items []string, opts options) (string, error) { data.Options.Empty = !opts.disallowEmpty if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/msg_darwin.go b/msg_darwin.go index d5980fa..7a177d1 100644 --- a/msg_darwin.go +++ b/msg_darwin.go @@ -12,7 +12,8 @@ func message(kind messageKind, text string, opts options) error { data.Options.Timeout = zenutil.Timeout if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/progress_darwin.go b/progress_darwin.go index 0c16700..eb520a2 100644 --- a/progress_darwin.go +++ b/progress_darwin.go @@ -19,6 +19,9 @@ func progress(opts options) (ProgressDialog, error) { if opts.maxValue >= 0 { data.Total = &opts.maxValue } + if opts.attach != nil { + data.Application = opts.attach + } if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/pwd_darwin.go b/pwd_darwin.go index 6fcb03c..0713c5d 100644 --- a/pwd_darwin.go +++ b/pwd_darwin.go @@ -20,7 +20,8 @@ func password(opts options) (string, string, error) { data.Options.Timeout = zenutil.Timeout if opts.attach != nil { data.Application = opts.attach - } else if i, ok := opts.windowIcon.(string); ok { + } + if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } switch i := opts.icon.(type) {