Add display window opacity websocket command
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

This commit is contained in:
Snider 2026-04-15 20:13:37 +01:00
parent 8e91384143
commit fc73d2bb71
2 changed files with 32 additions and 0 deletions

View file

@ -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}
}

View file

@ -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")