From 1c43756a6c1bea24a782d02f76ad020616ee7784 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 27 Jun 2022 16:56:24 +0100 Subject: [PATCH] Handle invalid window ids (macOS). --- go.mod | 2 +- go.sum | 4 ++-- internal/zenutil/osa_generated.go | 5 ++--- internal/zenutil/osascripts/common.gojs | 12 +++++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 2a1b91b..3681b04 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 go.uber.org/goleak v1.1.12 // test golang.org/x/image v0.0.0-20220617043117-41969df76e82 - golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c + golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b ) require ( diff --git a/go.sum b/go.sum index fdef053..f77b678 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8= +golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index 10f0798..a3081d2 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -24,17 +24,16 @@ $.exit(-1)} {{- end}} {{define "common" -}} {{- if .Application}} -var app=Application({{json .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.includeStandardAdditions=true -app.activate() {{- end}} {{define "date" -}} ObjC.import('Cocoa') diff --git a/internal/zenutil/osascripts/common.gojs b/internal/zenutil/osascripts/common.gojs index 3b0de34..4593fdb 100644 --- a/internal/zenutil/osascripts/common.gojs +++ b/internal/zenutil/osascripts/common.gojs @@ -1,8 +1,13 @@ {{- if .Application}} - var app = Application({{json .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') @@ -10,7 +15,4 @@ let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) nsapp.setApplicationIconImage(nsimg) -}{{end}} - -app.includeStandardAdditions = true -app.activate() \ No newline at end of file +}{{end}} \ No newline at end of file