Window icons (macOS).
This commit is contained in:
parent
550da1f8ed
commit
ab7621bec9
18 changed files with 106 additions and 59 deletions
|
@ -7,6 +7,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func selectColor(opts options) (color.Color, error) {
|
func selectColor(opts options) (color.Color, error) {
|
||||||
|
var data zenutil.Color
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
var col color.Color
|
var col color.Color
|
||||||
if opts.color != nil {
|
if opts.color != nil {
|
||||||
col = opts.color
|
col = opts.color
|
||||||
|
@ -14,12 +19,13 @@ func selectColor(opts options) (color.Color, error) {
|
||||||
col = color.White
|
col = color.White
|
||||||
}
|
}
|
||||||
r, g, b, _ := col.RGBA()
|
r, g, b, _ := col.RGBA()
|
||||||
|
data.Color = [3]float32{
|
||||||
out, err := zenutil.Run(opts.ctx, "color", []float32{
|
|
||||||
float32(r) / 0xffff,
|
float32(r) / 0xffff,
|
||||||
float32(g) / 0xffff,
|
float32(g) / 0xffff,
|
||||||
float32(b) / 0xffff,
|
float32(b) / 0xffff,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
out, err := zenutil.Run(opts.ctx, "color", data)
|
||||||
str, err := strResult(opts, out, err)
|
str, err := strResult(opts, out, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -7,26 +7,29 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func calendar(text string, opts options) (t time.Time, err error) {
|
func calendar(text string, opts options) (t time.Time, err error) {
|
||||||
var date zenutil.Date
|
var data zenutil.Date
|
||||||
|
|
||||||
date.OK, date.Cancel, date.Extra = getAlertButtons(opts)
|
data.OK, data.Cancel, data.Extra = getAlertButtons(opts)
|
||||||
date.Format, err = zenutil.DateUTS35()
|
data.Format, err = zenutil.DateUTS35()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if opts.time != nil {
|
if opts.time != nil {
|
||||||
unix := opts.time.Unix()
|
unix := opts.time.Unix()
|
||||||
date.Date = &unix
|
data.Date = &unix
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.title != nil {
|
if opts.title != nil {
|
||||||
date.Text = *opts.title
|
data.Text = *opts.title
|
||||||
date.Info = text
|
data.Info = text
|
||||||
} else {
|
} else {
|
||||||
date.Text = text
|
data.Text = text
|
||||||
|
}
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := zenutil.Run(opts.ctx, "date", date)
|
out, err := zenutil.Run(opts.ctx, "date", data)
|
||||||
str, err := strResult(opts, out, err)
|
str, err := strResult(opts, out, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,6 +14,9 @@ func entry(text string, opts options) (string, error) {
|
||||||
data.Options.Answer = &opts.entryText
|
data.Options.Answer = &opts.entryText
|
||||||
data.Options.Hidden = opts.hideText
|
data.Options.Hidden = opts.hideText
|
||||||
data.Options.Timeout = zenutil.Timeout
|
data.Options.Timeout = zenutil.Timeout
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
switch i := opts.icon.(type) {
|
switch i := opts.icon.(type) {
|
||||||
case string:
|
case string:
|
||||||
_, err := os.Stat(i)
|
_, err := os.Stat(i)
|
||||||
|
|
|
@ -7,6 +7,9 @@ func selectFile(opts options) (string, error) {
|
||||||
data.Options.Prompt = opts.title
|
data.Options.Prompt = opts.title
|
||||||
data.Options.Invisibles = opts.showHidden
|
data.Options.Invisibles = opts.showHidden
|
||||||
data.Options.Location, _ = splitDirAndName(opts.filename)
|
data.Options.Location, _ = splitDirAndName(opts.filename)
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
if opts.directory {
|
if opts.directory {
|
||||||
data.Operation = "chooseFolder"
|
data.Operation = "chooseFolder"
|
||||||
|
@ -26,6 +29,9 @@ func selectFileMultiple(opts options) ([]string, error) {
|
||||||
data.Options.Location, _ = splitDirAndName(opts.filename)
|
data.Options.Location, _ = splitDirAndName(opts.filename)
|
||||||
data.Options.Multiple = true
|
data.Options.Multiple = true
|
||||||
data.Separator = zenutil.Separator
|
data.Separator = zenutil.Separator
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
if opts.directory {
|
if opts.directory {
|
||||||
data.Operation = "chooseFolder"
|
data.Operation = "chooseFolder"
|
||||||
|
@ -43,6 +49,9 @@ func selectFileSave(opts options) (string, error) {
|
||||||
data.Options.Prompt = opts.title
|
data.Options.Prompt = opts.title
|
||||||
data.Options.Invisibles = opts.showHidden
|
data.Options.Invisibles = opts.showHidden
|
||||||
data.Options.Location, data.Options.Name = splitDirAndName(opts.filename)
|
data.Options.Location, data.Options.Name = splitDirAndName(opts.filename)
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
if opts.directory {
|
if opts.directory {
|
||||||
data.Operation = "chooseFolder"
|
data.Operation = "chooseFolder"
|
||||||
|
|
|
@ -13,20 +13,31 @@ var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func
|
||||||
return string(b), err
|
return string(b), err
|
||||||
}}).Parse(`
|
}}).Parse(`
|
||||||
{{define "color" -}}
|
{{define "color" -}}
|
||||||
var app=Application.currentApplication()
|
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
try{var res=app.chooseColor({defaultColor:{{json .}}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
{{template "common" .}}
|
||||||
|
try{var res=app.chooseColor({defaultColor:{{json .Color}}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
||||||
$.dprintf(2,e)
|
$.dprintf(2,e)
|
||||||
$.exit(-1)}
|
$.exit(-1)}
|
||||||
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
{{define "common" -}}
|
||||||
|
{var app=Application.currentApplication()
|
||||||
|
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" -}}
|
{{define "date" -}}
|
||||||
ObjC.import('Cocoa')
|
ObjC.import('Cocoa')
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
{{template "common" .}}
|
||||||
var date=$.NSDatePicker.alloc.init
|
var date=$.NSDatePicker.alloc.init
|
||||||
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
||||||
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
||||||
|
@ -56,11 +67,9 @@ fmt.dateFormat={{json .Format}}
|
||||||
fmt.stringFromDate(date.dateValue)
|
fmt.stringFromDate(date.dateValue)
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{define "dialog" -}}
|
{{define "dialog" -}}
|
||||||
var app=Application.currentApplication()
|
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
{{template "common" .}}
|
||||||
var opts={{json .Options}}
|
var opts={{json .Options}}
|
||||||
{{- if .IconPath}}
|
{{- if .IconPath}}
|
||||||
opts.withIcon=Path({{json .IconPath}})
|
opts.withIcon=Path({{json .IconPath}})
|
||||||
|
@ -74,9 +83,7 @@ $.exit(1)}
|
||||||
res.textReturned
|
res.textReturned
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{define "file" -}}
|
{{define "file" -}}
|
||||||
var app=Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
try{var res=app.{{.Operation}}({{json .Options}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
try{var res=app.{{.Operation}}({{json .Options}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
||||||
|
@ -85,9 +92,7 @@ $.exit(-1)}
|
||||||
if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
|
if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{define "list" -}}
|
{{define "list" -}}
|
||||||
var app=Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
try{var res=app.chooseFromList({{json .Items}},{{json .Options}})}catch(e){$.dprintf(2,e)
|
try{var res=app.chooseFromList({{json .Items}},{{json .Options}})}catch(e){$.dprintf(2,e)
|
||||||
|
@ -101,9 +106,7 @@ app.includeStandardAdditions=true
|
||||||
void app.displayNotification({{json .Text}},{{json .Options}})
|
void app.displayNotification({{json .Text}},{{json .Options}})
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{define "progress" -}}
|
{{define "progress" -}}
|
||||||
var app=Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
ObjC.import('readline')
|
ObjC.import('readline')
|
||||||
{{- if .Total}}
|
{{- if .Total}}
|
||||||
|
@ -120,9 +123,7 @@ var i=parseInt(s)
|
||||||
if(i>=0&&Progress.totalUnitCount>0){Progress.completedUnitCount=i}}
|
if(i>=0&&Progress.totalUnitCount>0){Progress.completedUnitCount=i}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{define "pwd" -}}
|
{{define "pwd" -}}
|
||||||
var app=Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions=true
|
|
||||||
app.activate()
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
var opts={{json .Options}}
|
var opts={{json .Options}}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
var app = Application.currentApplication()
|
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
{{template "common" .}}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var res = app.chooseColor({defaultColor: {{json .}}})
|
var res = app.chooseColor({defaultColor: {{json .Color}}})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.errorNumber === -128) $.exit(1)
|
if (e.errorNumber === -128) $.exit(1)
|
||||||
$.dprintf(2, e)
|
$.dprintf(2, e)
|
||||||
|
|
14
internal/zenutil/osascripts/common.gojs
Normal file
14
internal/zenutil/osascripts/common.gojs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
var app = Application.currentApplication()
|
||||||
|
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()
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
ObjC.import('Cocoa')
|
ObjC.import('Cocoa')
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
{{template "common" .}}
|
||||||
|
|
||||||
var date = $.NSDatePicker.alloc.init
|
var date = $.NSDatePicker.alloc.init
|
||||||
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
var app = Application.currentApplication()
|
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
{{template "common" .}}
|
||||||
|
|
||||||
var opts = {{json .Options}}
|
var opts = {{json .Options}}
|
||||||
{{- if .IconPath}}
|
{{- if .IconPath}}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
var app = Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
var app = Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
var app = Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
ObjC.import('readline')
|
ObjC.import('readline')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
var app = Application.currentApplication()
|
{{template "common" .}}
|
||||||
app.includeStandardAdditions = true
|
|
||||||
app.activate()
|
|
||||||
|
|
||||||
ObjC.import('stdio')
|
ObjC.import('stdio')
|
||||||
ObjC.import('stdlib')
|
ObjC.import('stdlib')
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,10 @@ func RunProgress(ctx context.Context, max int, data Progress) (dlg *progressDial
|
||||||
return dlg, nil
|
return dlg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type common struct {
|
||||||
|
WindowIcon string
|
||||||
|
}
|
||||||
|
|
||||||
// Dialog is internal.
|
// Dialog is internal.
|
||||||
type Dialog struct {
|
type Dialog struct {
|
||||||
Operation string
|
Operation string
|
||||||
|
@ -130,6 +134,7 @@ type Dialog struct {
|
||||||
Extra *string
|
Extra *string
|
||||||
Options DialogOptions
|
Options DialogOptions
|
||||||
IconPath string
|
IconPath string
|
||||||
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialogOptions is internal.
|
// DialogOptions is internal.
|
||||||
|
@ -152,6 +157,7 @@ type Password struct {
|
||||||
Extra *string
|
Extra *string
|
||||||
Options PasswordOptions
|
Options PasswordOptions
|
||||||
IconPath string
|
IconPath string
|
||||||
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
// PasswordOptions is internal.
|
// PasswordOptions is internal.
|
||||||
|
@ -199,6 +205,7 @@ type List struct {
|
||||||
Items []string
|
Items []string
|
||||||
Separator string
|
Separator string
|
||||||
Options ListOptions
|
Options ListOptions
|
||||||
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListOptions is internal.
|
// ListOptions is internal.
|
||||||
|
@ -217,6 +224,7 @@ type File struct {
|
||||||
Operation string
|
Operation string
|
||||||
Separator string
|
Separator string
|
||||||
Options FileOptions
|
Options FileOptions
|
||||||
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileOptions is internal.
|
// FileOptions is internal.
|
||||||
|
@ -241,10 +249,10 @@ type NotifyOptions struct {
|
||||||
Subtitle string `json:"subtitle,omitempty"`
|
Subtitle string `json:"subtitle,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress is internal.
|
// Color is internal.
|
||||||
type Progress struct {
|
type Color struct {
|
||||||
Description *string
|
Color [3]float32
|
||||||
Total *int
|
common
|
||||||
}
|
}
|
||||||
|
|
||||||
// Date is internal.
|
// Date is internal.
|
||||||
|
@ -256,4 +264,12 @@ type Date struct {
|
||||||
OK string
|
OK string
|
||||||
Cancel string
|
Cancel string
|
||||||
Extra *string
|
Extra *string
|
||||||
|
common
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress is internal.
|
||||||
|
type Progress struct {
|
||||||
|
Description *string
|
||||||
|
Total *int
|
||||||
|
common
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ func list(text string, items []string, opts options) (string, error) {
|
||||||
data.Options.Cancel = opts.cancelLabel
|
data.Options.Cancel = opts.cancelLabel
|
||||||
data.Options.Default = opts.defaultItems
|
data.Options.Default = opts.defaultItems
|
||||||
data.Options.Empty = !opts.disallowEmpty
|
data.Options.Empty = !opts.disallowEmpty
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
out, err := zenutil.Run(opts.ctx, "list", data)
|
out, err := zenutil.Run(opts.ctx, "list", data)
|
||||||
return strResult(opts, out, err)
|
return strResult(opts, out, err)
|
||||||
|
|
|
@ -10,6 +10,9 @@ func message(kind messageKind, text string, opts options) error {
|
||||||
var data zenutil.Dialog
|
var data zenutil.Dialog
|
||||||
data.Text = text
|
data.Text = text
|
||||||
data.Options.Timeout = zenutil.Timeout
|
data.Options.Timeout = zenutil.Timeout
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
// dialog is more flexible, alert prettier
|
// dialog is more flexible, alert prettier
|
||||||
var dialog bool
|
var dialog bool
|
||||||
|
|
|
@ -19,6 +19,9 @@ func progress(opts options) (ProgressDialog, error) {
|
||||||
if opts.maxValue >= 0 {
|
if opts.maxValue >= 0 {
|
||||||
data.Total = &opts.maxValue
|
data.Total = &opts.maxValue
|
||||||
}
|
}
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
|
|
||||||
return zenutil.RunProgress(opts.ctx, opts.maxValue, data)
|
return zenutil.RunProgress(opts.ctx, opts.maxValue, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ func password(opts options) (string, string, error) {
|
||||||
data.Separator = zenutil.Separator
|
data.Separator = zenutil.Separator
|
||||||
data.Options.Title = opts.title
|
data.Options.Title = opts.title
|
||||||
data.Options.Timeout = zenutil.Timeout
|
data.Options.Timeout = zenutil.Timeout
|
||||||
|
if i, ok := opts.windowIcon.(string); ok {
|
||||||
|
data.WindowIcon = i
|
||||||
|
}
|
||||||
switch i := opts.icon.(type) {
|
switch i := opts.icon.(type) {
|
||||||
case string:
|
case string:
|
||||||
_, err := os.Stat(i)
|
_, err := os.Stat(i)
|
||||||
|
|
Loading…
Reference in a new issue