2020-01-10 20:41:13 -05:00
|
|
|
// Code generated by zenity; DO NOT EDIT.
|
2022-06-18 07:37:39 -04:00
|
|
|
|
2022-03-24 10:37:37 -04:00
|
|
|
//go:build darwin
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
package zenutil
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2021-04-08 12:23:17 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"text/template"
|
|
|
|
)
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2022-06-02 07:49:31 -04:00
|
|
|
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v any) (string, error) {
|
2020-01-21 07:03:58 -05:00
|
|
|
b, err := json.Marshal(v)
|
|
|
|
return string(b), err
|
|
|
|
}}).Parse(`
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "color" -}}
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
|
|
|
try{var res=app.chooseColor({defaultColor:{{json .Color}}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
2022-05-06 08:48:31 -04:00
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2022-03-26 20:05:52 -04:00
|
|
|
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
2020-01-21 07:03:58 -05:00
|
|
|
{{- end}}
|
2022-06-01 19:00:08 -04:00
|
|
|
{{define "common" -}}
|
2022-12-06 13:24:37 -05:00
|
|
|
{{if .WindowIcon}}{ObjC.import('Cocoa')
|
|
|
|
let nsapp=$.NSApplication.sharedApplication
|
|
|
|
let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}})
|
|
|
|
nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular)
|
|
|
|
nsapp.setApplicationIconImage(nsimg)}{{end}}
|
2022-06-02 07:49:31 -04:00
|
|
|
{{- if .Application}}
|
2022-06-27 11:56:24 -04:00
|
|
|
try{var app=Application({{json .Application}})}catch{var app=Application.currentApplication()}
|
2022-06-02 07:49:31 -04:00
|
|
|
{{- else}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
{{- end}}
|
2022-06-27 11:56:24 -04:00
|
|
|
app.includeStandardAdditions=true
|
2022-12-06 13:24:37 -05:00
|
|
|
app.activate()
|
2022-06-01 19:00:08 -04:00
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
{{define "date" -}}
|
|
|
|
ObjC.import('Cocoa')
|
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
2022-12-06 13:24:37 -05:00
|
|
|
var nsapp=$.NSApplication.sharedApplication
|
|
|
|
nsapp.setActivationPolicy($.NSApplicationActivationPolicyAccessory)
|
2022-12-07 07:49:03 -05:00
|
|
|
{{template "common" .}}
|
2022-03-24 12:15:11 -04:00
|
|
|
var date=$.NSDatePicker.alloc.init
|
|
|
|
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
|
|
|
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
|
|
|
date.setFrameSize(date.fittingSize)
|
2022-03-30 10:36:50 -04:00
|
|
|
{{- if .Date}}
|
|
|
|
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
2022-05-17 10:36:00 -04:00
|
|
|
{{- else}}
|
|
|
|
date.setDateValue($.NSDate.date)
|
2022-03-30 10:36:50 -04:00
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
var alert=$.NSAlert.alloc.init
|
|
|
|
alert.setAccessoryView(date)
|
|
|
|
alert.setMessageText({{json .Text}})
|
2022-03-28 15:22:39 -04:00
|
|
|
alert.addButtonWithTitle({{json .OK}})
|
|
|
|
alert.addButtonWithTitle({{json .Cancel}}).keyEquivalent='\033'
|
|
|
|
{{- if .Info}}
|
|
|
|
alert.setInformativeText({{json .Info}})
|
|
|
|
{{- end}}
|
|
|
|
{{- if .Extra}}
|
|
|
|
alert.addButtonWithTitle({{json .Extra}})
|
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
var res=alert.runModal
|
2022-03-28 15:22:39 -04:00
|
|
|
switch(res){case $.NSAlertThirdButtonReturn:$.puts({{json .Extra}})
|
2022-03-24 12:15:11 -04:00
|
|
|
case $.NSAlertSecondButtonReturn:$.exit(1)}
|
|
|
|
var fmt=$.NSDateFormatter.alloc.init
|
2022-05-11 12:49:15 -04:00
|
|
|
fmt.locale=$.NSLocale.localeWithLocaleIdentifier('en_US_POSIX')
|
2022-05-06 08:48:31 -04:00
|
|
|
fmt.dateFormat={{json .Format}}
|
2022-03-24 12:15:11 -04:00
|
|
|
fmt.stringFromDate(date.dateValue)
|
|
|
|
{{- end}}
|
2021-03-04 21:01:59 -05:00
|
|
|
{{define "dialog" -}}
|
2022-05-05 08:03:53 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
2022-05-05 08:03:53 -04:00
|
|
|
var opts={{json .Options}}
|
2021-10-06 18:39:36 -04:00
|
|
|
{{- if .IconPath}}
|
2022-05-05 08:03:53 -04:00
|
|
|
opts.withIcon=Path({{json .IconPath}})
|
2021-10-06 18:39:36 -04:00
|
|
|
{{- end}}
|
2022-05-06 08:48:31 -04:00
|
|
|
try{var res=app.{{.Operation}}({{json .Text}},opts)}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2021-03-03 21:52:05 -05:00
|
|
|
if(res.gaveUp){$.exit(5)}
|
2022-05-11 12:49:15 -04:00
|
|
|
if(res.buttonReturned==={{json .Extra}}){$.puts({{json .Extra}})
|
2021-03-03 21:52:05 -05:00
|
|
|
$.exit(1)}
|
2021-03-04 21:01:59 -05:00
|
|
|
res.textReturned
|
|
|
|
{{- end}}
|
|
|
|
{{define "file" -}}
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
try{var res=app.{{.Operation}}({{json .Options}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2021-03-04 21:01:59 -05:00
|
|
|
if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
|
2020-01-26 11:04:49 -05:00
|
|
|
{{- end}}
|
2021-04-07 09:16:35 -04:00
|
|
|
{{define "list" -}}
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
try{var res=app.chooseFromList({{json .Items}},{{json .Options}})}catch(e){$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
|
|
|
if(res===false)$.exit(1)
|
2021-07-08 13:56:28 -04:00
|
|
|
if(res.length!==0)res.join({{json .Separator}})
|
2021-04-07 09:16:35 -04:00
|
|
|
{{- end}}
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "notify" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
void app.displayNotification({{json .Text}},{{json .Options}})
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- end}}
|
|
|
|
{{define "progress" -}}
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
2021-04-22 10:03:08 -04:00
|
|
|
ObjC.import('stdlib')
|
|
|
|
ObjC.import('readline')
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- if .Total}}
|
|
|
|
Progress.totalUnitCount={{.Total}}
|
|
|
|
{{- end}}
|
|
|
|
{{- if .Description}}
|
|
|
|
Progress.description={{json .Description}}
|
|
|
|
{{- end}}
|
2022-05-06 08:48:31 -04:00
|
|
|
while(true){try{var s=$.readline('')}catch(e){if(e.errorNumber===-128)$.exit(1)
|
2021-04-22 10:03:08 -04:00
|
|
|
break}
|
2021-04-25 13:34:56 -04:00
|
|
|
if(s.indexOf('#')===0){Progress.additionalDescription=s.slice(1)
|
2021-04-22 10:03:08 -04:00
|
|
|
continue}
|
|
|
|
var i=parseInt(s)
|
2022-05-06 08:48:31 -04:00
|
|
|
if(i>=0&&Progress.totalUnitCount>0){Progress.completedUnitCount=i}}
|
2022-05-11 12:49:15 -04:00
|
|
|
{{- end}}
|
|
|
|
{{define "pwd" -}}
|
2022-06-01 19:00:08 -04:00
|
|
|
{{template "common" .}}
|
2022-05-11 12:49:15 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
var opts={{json .Options}}
|
|
|
|
{{- if .IconPath}}
|
|
|
|
opts.withIcon=Path({{json .IconPath}})
|
|
|
|
{{- end}}
|
|
|
|
function dialog(text){try{var res=app.displayDialog(text,opts)}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
|
|
|
if(res.gaveUp){$.exit(5)}
|
|
|
|
if(res.buttonReturned==={{json .Extra}}){$.puts({{json .Extra}})
|
|
|
|
$.exit(1)}
|
|
|
|
return res.textReturned}
|
|
|
|
var start=Date.now()
|
|
|
|
opts.defaultAnswer=''
|
|
|
|
var username=dialog('Username:')
|
|
|
|
{{- if .Options.Timeout}}
|
|
|
|
opts.givingUpAfter-=(Date.now()-start)/1000|0
|
|
|
|
{{- end}}
|
|
|
|
opts.hiddenAnswer=true
|
|
|
|
var password=dialog('Password:')
|
|
|
|
username+{{json .Separator}}+password
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- end}}`))
|