Skip to content

Commit

Permalink
Added ability to activate apps and windows (#5)
Browse files Browse the repository at this point in the history
* Added ability to activate apps and windows

* Update app.go

Co-authored-by: Marwan Sulaiman <[email protected]>

* Use utility function to get boolean ptr

* Rename receiver and use utility function

---------

Co-authored-by: Arjen Brouwer <[email protected]>
Co-authored-by: Marwan Sulaiman <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 6f0bd81 commit be1613b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type App interface {
CreateWindow() (Window, error)
ListWindows() ([]Window, error)
SelectMenuItem(item string) error
Activate(raiseAllWindows, ignoreOtherApps bool) error
}

// NewApp establishes a connection
Expand All @@ -37,6 +38,19 @@ type app struct {
c *client.Client
}

func (a *app) Activate(raiseAllWindows bool, ignoreOtherApps bool) error {
_, err := a.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_ActivateRequest{ActivateRequest: &api.ActivateRequest{
OrderWindowFront: b(true),
ActivateApp: &api.ActivateRequest_App{
RaiseAllWindows: &raiseAllWindows,
IgnoringOtherApps: &ignoreOtherApps,
},
}},
})
return err
}

func (a *app) CreateWindow() (Window, error) {
resp, err := a.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_CreateTabRequest{
Expand Down Expand Up @@ -84,6 +98,10 @@ func str(s string) *string {
return &s
}

func b(b bool) *bool {
return &b
}

func (a *app) SelectMenuItem(item string) error {
resp, err := a.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_MenuItemRequest{
Expand Down
11 changes: 11 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Window interface {
SetTitle(s string) error
CreateTab() (Tab, error)
ListTabs() ([]Tab, error)
Activate() error
}

type window struct {
Expand Down Expand Up @@ -83,3 +84,13 @@ func (w *window) SetTitle(s string) error {
})
return err
}

func (w *window) Activate() error {
_, err := w.c.Call(&api.ClientOriginatedMessage{
Submessage: &api.ClientOriginatedMessage_ActivateRequest{ActivateRequest: &api.ActivateRequest{
Identifier: &api.ActivateRequest_WindowId{WindowId: w.id},
OrderWindowFront: b(true),
}},
})
return err
}

0 comments on commit be1613b

Please sign in to comment.