This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
186 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package astilectron | ||
|
||
import "github.com/asticode/go-astitools/context" | ||
|
||
// Dock event names | ||
const ( | ||
eventNameDockCmdBounce = "dock.cmd.bounce" | ||
eventNameDockCmdBounceDownloads = "dock.cmd.bounce.downloads" | ||
eventNameDockCmdCancelBounce = "dock.cmd.cancel.bounce" | ||
eventNameDockCmdHide = "dock.cmd.hide" | ||
eventNameDockCmdSetBadge = "dock.cmd.set.badge" | ||
eventNameDockCmdSetIcon = "dock.cmd.set.icon" | ||
eventNameDockCmdShow = "dock.cmd.show" | ||
eventNameDockEventBadgeSet = "dock.event.badge.set" | ||
eventNameDockEventBouncing = "dock.event.bouncing" | ||
eventNameDockEventBouncingCancelled = "dock.event.bouncing.cancelled" | ||
eventNameDockEventDownloadsBouncing = "dock.event.download.bouncing" | ||
eventNameDockEventHidden = "dock.event.hidden" | ||
eventNameDockEventIconSet = "dock.event.icon.set" | ||
eventNameDockEventShown = "dock.event.shown" | ||
) | ||
|
||
// Dock bounce types | ||
const ( | ||
DockBounceTypeCritical = "critical" | ||
DockBounceTypeInformational = "informational" | ||
) | ||
|
||
// Dock represents a dock | ||
// https://github.com/electron/electron/blob/v1.8.1/docs/api/app.md#appdockbouncetype-macos | ||
type Dock struct { | ||
*object | ||
o *DockOptions | ||
} | ||
|
||
// DockOptions represents dock options | ||
type DockOptions struct { | ||
Badge string `json:"badge,omitempty"` | ||
IsVisible *bool `json:"isVisible,omitempty"` | ||
} | ||
|
||
func newDock(o *DockOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, wrt *writer) *Dock { | ||
return &Dock{ | ||
o: o, | ||
object: newObject(nil, c, d, i, wrt, targetIDDock), | ||
} | ||
} | ||
|
||
// Badge returns the badge | ||
func (d *Dock) Badge() string { | ||
return d.o.Badge | ||
} | ||
|
||
// Bounce bounces the dock | ||
func (d *Dock) Bounce(bounceType string) (id int, err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
var e Event | ||
if e, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounce, TargetID: d.id, BounceType: bounceType}, eventNameDockEventBouncing); err != nil { | ||
return | ||
} | ||
if e.ID != nil { | ||
id = *e.ID | ||
} | ||
return | ||
} | ||
|
||
// BounceDownloads bounces the downloads part of the dock | ||
func (d *Dock) BounceDownloads(filePath string) (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounceDownloads, TargetID: d.id, FilePath: filePath}, eventNameDockEventDownloadsBouncing) | ||
return | ||
} | ||
|
||
// CancelBounce cancels the dock bounce | ||
func (d *Dock) CancelBounce(id int) (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdCancelBounce, TargetID: d.id, ID: PtrInt(id)}, eventNameDockEventBouncingCancelled) | ||
return | ||
} | ||
|
||
// Hide hides the dock | ||
func (d *Dock) Hide() (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdHide, TargetID: d.id}, eventNameDockEventHidden) | ||
d.o.IsVisible = PtrBool(false) | ||
return | ||
} | ||
|
||
// IsVisible returns whether the dock is visible | ||
func (d *Dock) IsVisible() *bool { | ||
return d.o.IsVisible | ||
} | ||
|
||
// NewMenu creates a new dock menu | ||
func (d *Dock) NewMenu(i []*MenuItemOptions) *Menu { | ||
return newMenu(d.ctx, d.id, i, d.c, d.d, d.i, d.w) | ||
} | ||
|
||
// SetBadge sets the badge of the dock | ||
func (d *Dock) SetBadge(badge string) (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetBadge, TargetID: d.id, Badge: badge}, eventNameDockEventBadgeSet) | ||
d.o.Badge = badge | ||
return | ||
} | ||
|
||
// SetIcon sets the icon of the dock | ||
func (d *Dock) SetIcon(image string) (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetIcon, TargetID: d.id, Image: image}, eventNameDockEventIconSet) | ||
return | ||
} | ||
|
||
// Show shows the dock | ||
func (d *Dock) Show() (err error) { | ||
if err = d.isActionable(); err != nil { | ||
return | ||
} | ||
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdShow, TargetID: d.id}, eventNameDockEventShown) | ||
d.o.IsVisible = PtrBool(true) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.