// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package app import ( "git.stormux.org/storm/cthulhu/internal/config" "git.stormux.org/storm/cthulhu/internal/wine" "sync/atomic" ) // Published settings are immutable snapshots shared by the preferences, input, // and accessibility workers. Each event uses one complete snapshot. type liveSettings struct { editFieldFocused func() bool // Installed before workers start; reads cached focus only. current atomic.Pointer[config.Settings] globalWine atomic.Pointer[config.WineSettings] preferencesPID atomic.Int64 // Owned by the preferences window lifetime; zero when closed. application atomic.Pointer[string] requestedApplication atomic.Pointer[string] clipboardChanges chan struct{} onApplication func(string) wineTitles chan wineWindowTitle wineReview *wine.ReviewRegistry } func (live *liveSettings) Store(settings config.Settings) { live.current.Store(&settings) live.notify_clipboard() } func (live *liveSettings) notify_clipboard() { select { case live.clipboardChanges <- struct{}{}: default: } } func (live *liveSettings) Load() config.Settings { return *live.current.Load() } // Wine values are global-only: one list governs every prefix regardless of // which application has focus. The preferences worker publishes them here // only when the active/global profile changes, never when it publishes a // per-application profile through Store, so application switching cannot // change the governing Wine list. The Wine manager reads them at each poll // and helper spawn. func (live *liveSettings) StoreGlobalWine(settings config.WineSettings) { settings.ExcludedPrograms = append([]string(nil), settings.ExcludedPrograms...) live.globalWine.Store(&settings) } func (live *liveSettings) LoadGlobalWine() config.WineSettings { current := live.globalWine.Load() if current == nil { return config.WineSettings{} } settings := *current settings.ExcludedPrograms = append([]string(nil), settings.ExcludedPrograms...) return settings }