From 13c7dd311226b4ca6ebb9e7e7acb9018966c1df1 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Tue, 6 Dec 2022 18:24:37 +0000 Subject: [PATCH] Fixes focus issues, see #40. --- date_darwin.go | 3 --- internal/zenutil/osa_generated.go | 13 ++++++++----- internal/zenutil/osascripts/common.gojs | 17 +++++++++-------- internal/zenutil/osascripts/date.gojs | 2 ++ progress_darwin.go | 3 --- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/date_darwin.go b/date_darwin.go index 03da0d5..2c9954e 100644 --- a/date_darwin.go +++ b/date_darwin.go @@ -25,9 +25,6 @@ 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/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index a3081d2..ddb84f9 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -23,23 +23,26 @@ $.exit(-1)} {'rgb('+res.map(x=>Math.round(x*255))+')'} {{- end}} {{define "common" -}} +{{if .WindowIcon}}{ObjC.import('Cocoa') +let nsapp=$.NSApplication.sharedApplication +let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) +nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) +nsapp.setApplicationIconImage(nsimg)}{{end}} {{- if .Application}} try{var app=Application({{json .Application}})}catch{var app=Application.currentApplication()} {{- else}} var app=Application.currentApplication() {{- end}} app.includeStandardAdditions=true -{{if .WindowIcon}}{ObjC.import('Cocoa') -let nsapp=$.NSApplication.sharedApplication -let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) -nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) -nsapp.setApplicationIconImage(nsimg)}{{end}} +app.activate() {{- end}} {{define "date" -}} ObjC.import('Cocoa') ObjC.import('stdio') ObjC.import('stdlib') {{template "common" .}} +var nsapp=$.NSApplication.sharedApplication +nsapp.setActivationPolicy($.NSApplicationActivationPolicyAccessory) var date=$.NSDatePicker.alloc.init date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar) date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay) diff --git a/internal/zenutil/osascripts/common.gojs b/internal/zenutil/osascripts/common.gojs index 4593fdb..12034ad 100644 --- a/internal/zenutil/osascripts/common.gojs +++ b/internal/zenutil/osascripts/common.gojs @@ -1,3 +1,11 @@ +{{if .WindowIcon}}{ + ObjC.import('Cocoa') + let nsapp = $.NSApplication.sharedApplication + let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) + nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) + nsapp.setApplicationIconImage(nsimg) +}{{end}} + {{- if .Application}} try { var app = Application({{json .Application}}) @@ -8,11 +16,4 @@ var app = Application.currentApplication() {{- end}} app.includeStandardAdditions = true - -{{if .WindowIcon}}{ - ObjC.import('Cocoa') - let nsapp = $.NSApplication.sharedApplication - let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) - nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) - nsapp.setApplicationIconImage(nsimg) -}{{end}} \ No newline at end of file +app.activate() \ No newline at end of file diff --git a/internal/zenutil/osascripts/date.gojs b/internal/zenutil/osascripts/date.gojs index 4cf2f5a..c457c8c 100644 --- a/internal/zenutil/osascripts/date.gojs +++ b/internal/zenutil/osascripts/date.gojs @@ -1,6 +1,8 @@ ObjC.import('Cocoa') ObjC.import('stdio') ObjC.import('stdlib') +var nsapp = $.NSApplication.sharedApplication +nsapp.setActivationPolicy($.NSApplicationActivationPolicyAccessory) {{template "common" .}} var date = $.NSDatePicker.alloc.init diff --git a/progress_darwin.go b/progress_darwin.go index eb520a2..0c16700 100644 --- a/progress_darwin.go +++ b/progress_darwin.go @@ -19,9 +19,6 @@ 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 }