Add display window opacity websocket command
This commit is contained in:
parent
8e91384143
commit
fc73d2bb71
2 changed files with 32 additions and 0 deletions
|
|
@ -878,6 +878,18 @@ func (s *Service) handleWSMessage(msg WSMessage) core.Result {
|
|||
Primary: primary, Secondary: secondary, ScreenID: screenID, Ratio: ratio,
|
||||
}},
|
||||
))
|
||||
case "window:set-opacity":
|
||||
name, e := wsRequire(msg.Data, "name")
|
||||
if e != nil {
|
||||
return core.Result{Value: e, OK: false}
|
||||
}
|
||||
opacity, ok := msg.Data["opacity"].(float64)
|
||||
if !ok {
|
||||
return core.Result{Value: coreerr.E("display.handleWSMessage", "missing required field \"opacity\"", nil), OK: false}
|
||||
}
|
||||
return c.Action("window.setOpacity").Run(ctx, core.NewOptions(
|
||||
core.Option{Key: "task", Value: window.TaskSetOpacity{Name: name, Opacity: opacity}},
|
||||
))
|
||||
default:
|
||||
return core.Result{Value: coreerr.E("display.handleWSMessage", "unknown websocket action: "+msg.Action, nil), OK: false}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,6 +372,26 @@ func TestSetWindowTitle_Good(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestHandleWSMessage_SetWindowOpacity_Good(t *testing.T) {
|
||||
c := newTestConclave(t)
|
||||
svc := core.MustServiceFor[*Service](c, "display")
|
||||
_ = svc.OpenWindow(window.WithName("opacity-win"))
|
||||
|
||||
r := svc.handleWSMessage(WSMessage{
|
||||
Action: "window:set-opacity",
|
||||
Data: map[string]any{
|
||||
"name": "opacity-win",
|
||||
"opacity": 0.35,
|
||||
},
|
||||
})
|
||||
require.True(t, r.OK)
|
||||
|
||||
info, err := svc.GetWindowInfo("opacity-win")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, info)
|
||||
assert.InDelta(t, 0.35, info.Opacity, 0.0001)
|
||||
}
|
||||
|
||||
func TestGetFocusedWindow_Good(t *testing.T) {
|
||||
c := newTestConclave(t)
|
||||
svc := core.MustServiceFor[*Service](c, "display")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue