add session to settings change.

This commit is contained in:
Miroslav Šedivý
2024-05-05 00:03:32 +02:00
parent d47302e2cd
commit 57ffca0bed
8 changed files with 46 additions and 30 deletions

View File

@ -39,7 +39,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
}
// update settings in atomic way
h.sessions.UpdateSettingsFunc(func(settings *types.Settings) bool {
h.sessions.UpdateSettingsFunc(session, func(settings *types.Settings) bool {
// if control protection & locked controls: unlock controls
if settings.LockedControls && settings.ControlProtection {
settings.LockedControls = false
@ -70,7 +70,7 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
})
// update settings in atomic way
h.sessions.UpdateSettingsFunc(func(settings *types.Settings) bool {
h.sessions.UpdateSettingsFunc(session, func(settings *types.Settings) bool {
// if control protection & not locked controls & no admin: lock controls
if !settings.LockedControls && settings.ControlProtection && !hasAdmin {
settings.LockedControls = true

View File

@ -127,7 +127,7 @@ func (manager *WebSocketManagerCtx) Start() {
Msg("session host changed")
})
manager.sessions.OnSettingsChanged(func(new types.Settings, old types.Settings) {
manager.sessions.OnSettingsChanged(func(session types.Session, new types.Settings, old types.Settings) {
// start inactive cursors
if new.InactiveCursors && !old.InactiveCursors {
manager.startInactiveCursors()
@ -138,8 +138,13 @@ func (manager *WebSocketManagerCtx) Start() {
manager.stopInactiveCursors()
}
manager.sessions.Broadcast(event.SYSTEM_SETTINGS, new)
manager.sessions.Broadcast(event.SYSTEM_SETTINGS, message.SystemSettingsUpdate{
ID: session.ID(),
Settings: new,
})
manager.logger.Info().
Str("session_id", session.ID()).
Interface("new", new).
Interface("old", old).
Msg("settings changed")