Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Fix for issue #297 (#304)
Browse files Browse the repository at this point in the history
* Add UpdateCustomOptions Event

* Added test for custom option event

* Changed from synchronousEvent to write

* update comment

* Changed to synchronousEvent with new event

* changed update to updated
  • Loading branch information
bennetty authored Jan 12, 2021
1 parent 0294cda commit e021f56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
EventNameWindowCmdRestore = "window.cmd.restore"
EventNameWindowCmdShow = "window.cmd.show"
EventNameWindowCmdUnmaximize = "window.cmd.unmaximize"
EventNameWindowCmdUpdateCustomOptions = "window.cmd.update.custom.options"
EventNameWindowCmdWebContentsCloseDevTools = "window.cmd.web.contents.close.dev.tools"
EventNameWindowCmdWebContentsOpenDevTools = "window.cmd.web.contents.open.dev.tools"
EventNameWindowCmdWebContentsExecuteJavaScript = "window.cmd.web.contents.execute.javascript"
Expand All @@ -54,6 +55,7 @@ const (
EventNameWindowEventDidGetRedirectRequest = "window.event.did.get.redirect.request"
EventNameWindowEventWebContentsExecutedJavaScript = "window.event.web.contents.executed.javascript"
EventNameWindowEventWillNavigate = "window.event.will.navigate"
EventNameWindowEventUpdatedCustomOptions = "window.event.updated.custom.options"
)

// Title bar styles
Expand Down Expand Up @@ -531,3 +533,15 @@ func (w *Window) Unmaximize() (err error) {
_, err = synchronousEvent(w.ctx, w, w.w, Event{Name: EventNameWindowCmdUnmaximize, TargetID: w.id}, EventNameWindowEventUnmaximize)
return
}

// UpdateCustomOptions updates the window custom options
func (w *Window) UpdateCustomOptions(o WindowCustomOptions) (err error) {
if err = w.ctx.Err(); err != nil {
return
}
w.m.Lock()
w.o.Custom = &o
w.m.Unlock()
_, err = synchronousEvent(w.ctx, w, w.w, Event{WindowOptions: w.o, Name: EventNameWindowCmdUpdateCustomOptions, TargetID: w.id}, EventNameWindowEventUpdatedCustomOptions)
return
}
1 change: 1 addition & 0 deletions window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestWindow_Actions(t *testing.T) {
testObjectAction(t, func() error { return w.Restore() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdRestore+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventRestore)
testObjectAction(t, func() error { return w.Show() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdShow+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventShow)
assert.Equal(t, true, w.IsShown())
testObjectAction(t, func() error { return w.UpdateCustomOptions(WindowCustomOptions{HideOnClose: astikit.BoolPtr(true)}) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdUpdateCustomOptions+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"height\":2,\"show\":true,\"width\":1,\"x\":4,\"y\":6,\"custom\":{\"hideOnClose\":true}}}\n", EventNameWindowCmdUpdateCustomOptions)
testObjectAction(t, func() error { return w.Unmaximize() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdUnmaximize+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventUnmaximize)
testObjectAction(t, func() error { return w.ExecuteJavaScript("console.log('test');") }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdWebContentsExecuteJavaScript+"\",\"targetID\":\""+w.id+"\",\"code\":\"console.log('test');\"}\n", EventNameWindowEventWebContentsExecutedJavaScript)
}
Expand Down

0 comments on commit e021f56

Please sign in to comment.