Skip to content

Commit

Permalink
Added tray set image
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Apr 1, 2018
1 parent d9b7c4b commit 172da7d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ m.Create()

// Create tray
t.Create()

// Change tray's image
time.Sleep(time.Second)
t.SetImage(astilectron.PtrStr("/path/to/image-2.png"))
```

## Dialogs
Expand Down
2 changes: 1 addition & 1 deletion astilectron.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// Versions
const (
DefaultAcceptTCPTimeout = 30 * time.Second
VersionAstilectron = "0.16.0"
VersionAstilectron = "0.17.0"
VersionElectron = "1.8.1"
)

Expand Down
1 change: 1 addition & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Event struct {
// We use pointers so that omitempty works
CallbackID string `json:"callbackId,omitempty"`
Displays *EventDisplays `json:"displays,omitempty"`
Image string `json:"image,omitempty"`
Menu *EventMenu `json:"menu,omitempty"`
MenuItem *EventMenuItem `json:"menuItem,omitempty"`
MenuItemOptions *MenuItemOptions `json:"menuItemOptions,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import "github.com/asticode/go-astitools/context"
const (
EventNameTrayCmdCreate = "tray.cmd.create"
EventNameTrayCmdDestroy = "tray.cmd.destroy"
EventNameTrayCmdSetImage = "tray.cmd.set.image"
EventNameTrayEventClicked = "tray.event.clicked"
EventNameTrayEventCreated = "tray.event.created"
EventNameTrayEventDestroyed = "tray.event.destroyed"
EventNameTrayEventDoubleClicked = "tray.event.double.clicked"
EventNameTrayEventImageSet = "tray.event.image.set"
EventNameTrayEventRightClicked = "tray.event.right.clicked"
)

Expand Down Expand Up @@ -67,3 +69,13 @@ func (t *Tray) Destroy() (err error) {
func (t *Tray) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(t.ctx, t.id, i, t.c, t.d, t.i, t.w)
}

// SetImage sets the tray image
func (t *Tray) SetImage(image string) (err error) {
if err = t.isActionable(); err != nil {
return
}
t.o.Image = PtrStr(image)
_, err = synchronousEvent(t.c, t, t.w, Event{Name: EventNameTrayCmdSetImage, Image: image, TargetID: t.id}, EventNameTrayEventImageSet)
return
}
1 change: 1 addition & 0 deletions tray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestTray_Actions(t *testing.T) {

// Actions
testObjectAction(t, func() error { return tr.Create() }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdCreate+"\",\"targetID\":\""+tr.id+"\",\"trayOptions\":{\"image\":\"/path/to/image\",\"tooltip\":\"tooltip\"}}\n", EventNameTrayEventCreated)
testObjectAction(t, func() error { return tr.SetImage("test") }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdSetImage+"\",\"targetID\":\""+tr.id+"\",\"image\":\"test\"}\n", EventNameTrayEventImageSet)
testObjectAction(t, func() error { return tr.Destroy() }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdDestroy+"\",\"targetID\":\""+tr.id+"\"}\n", EventNameTrayEventDestroyed)
assert.True(t, tr.IsDestroyed())
}
Expand Down

0 comments on commit 172da7d

Please sign in to comment.