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

Commit a95bcff

Browse files
authored
Add setAlwaysOnTop support (#361)
* Add setAlwaysOnTop support * Add missing tests
1 parent 1a9ca6a commit a95bcff

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

astilectron.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// Versions
1414
const (
1515
DefaultAcceptTCPTimeout = 30 * time.Second
16-
DefaultVersionAstilectron = "0.51.0"
16+
DefaultVersionAstilectron = "0.52.0"
1717
DefaultVersionElectron = "11.4.3"
1818
)
1919

window.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
EventNameWindowCmdWebContentsCloseDevTools = "window.cmd.web.contents.close.dev.tools"
3939
EventNameWindowCmdWebContentsOpenDevTools = "window.cmd.web.contents.open.dev.tools"
4040
EventNameWindowCmdWebContentsExecuteJavaScript = "window.cmd.web.contents.execute.javascript"
41+
EventNameWindowCmdSetAlwaysOnTop = "window.cmd.set.always.on.top"
4142
EventNameWindowEventBlur = "window.event.blur"
4243
EventNameWindowEventClosed = "window.event.closed"
4344
EventNameWindowEventContentProtectionSet = "window.event.content.protection.set"
@@ -60,6 +61,7 @@ const (
6061
EventNameWindowEventWebContentsExecutedJavaScript = "window.event.web.contents.executed.javascript"
6162
EventNameWindowEventWillNavigate = "window.event.will.navigate"
6263
EventNameWindowEventUpdatedCustomOptions = "window.event.updated.custom.options"
64+
EventNameWindowEventAlwaysOnTopChanged = "window.event.always.on.top.changed"
6365
)
6466

6567
// Title bar styles
@@ -459,6 +461,18 @@ func (w *Window) OpenDevTools() (err error) {
459461
return w.w.write(Event{Name: EventNameWindowCmdWebContentsOpenDevTools, TargetID: w.id})
460462
}
461463

464+
// SetAlwaysOnTop sets whether the window should show always on top of other windows.
465+
func (w *Window) SetAlwaysOnTop(flag bool) (err error) {
466+
if err = w.ctx.Err(); err != nil {
467+
return
468+
}
469+
w.m.Lock()
470+
w.o.AlwaysOnTop = astikit.BoolPtr(flag)
471+
w.m.Unlock()
472+
_, err = synchronousEvent(w.ctx, w, w.w, Event{Name: EventNameWindowCmdSetAlwaysOnTop, TargetID: w.id, Enable: astikit.BoolPtr(flag)}, EventNameWindowEventAlwaysOnTopChanged)
473+
return
474+
}
475+
462476
// Resize resizes the window
463477
func (w *Window) Resize(width, height int) (err error) {
464478
if err = w.ctx.Err(); err != nil {

window_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ func TestWindow_Actions(t *testing.T) {
6767
testObjectAction(t, func() error { return w.Resize(1, 2) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdResize+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"height\":2,\"width\":1}}\n", EventNameWindowEventResize)
6868
testObjectAction(t, func() error { return w.ResizeContent(1, 2) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdResizeContent+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"height\":2,\"width\":1}}\n", EventNameWindowEventResizeContent)
6969
testObjectAction(t, func() error { return w.Restore() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdRestore+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventRestore)
70+
testObjectAction(t, func() error { return w.SetAlwaysOnTop(true) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdSetAlwaysOnTop+"\",\"targetID\":\""+w.id+"\",\"enable\":true}\n", EventNameWindowEventAlwaysOnTopChanged)
7071
testObjectAction(t, func() error { return w.Show() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdShow+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventShow)
7172
assert.Equal(t, true, w.IsShown())
72-
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", EventNameWindowEventUpdatedCustomOptions)
73+
testObjectAction(t, func() error { return w.UpdateCustomOptions(WindowCustomOptions{HideOnClose: astikit.BoolPtr(true)}) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdUpdateCustomOptions+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"alwaysOnTop\":true,\"height\":2,\"show\":true,\"width\":1,\"x\":4,\"y\":6,\"custom\":{\"hideOnClose\":true}}}\n", EventNameWindowEventUpdatedCustomOptions)
7374
testObjectAction(t, func() error { return w.Unmaximize() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdUnmaximize+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventUnmaximize)
7475
testObjectAction(t, func() error { return w.ExecuteJavaScript("console.log('test');") }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdWebContentsExecuteJavaScript+"\",\"targetID\":\""+w.id+"\",\"code\":\"console.log('test');\"}\n", EventNameWindowEventWebContentsExecutedJavaScript)
7576
}

0 commit comments

Comments
 (0)