diff --git a/window.go b/window.go index 3735e82..e90dda4 100644 --- a/window.go +++ b/window.go @@ -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" @@ -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 @@ -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 +} diff --git a/window_test.go b/window_test.go index 5b3dbf9..0bf5daf 100644 --- a/window_test.go +++ b/window_test.go @@ -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) }