Files
cthulhu/internal/app/live_settings.go
hjozwiak 9a10a15b68 Read Wine settings live at poll and spawn
Phase 2 of the Wine/Proton stage (decisions 3, 4, 16, 17, 19 in docs/testing/wine-proton.md): replace the Wine manager's startup snapshot with a live settings source read once per poll, so accepted global settings take effect with no reader restart. The source publishes only the active/global profile's Wine values; per-application profile switching never changes the governing list. A newly listed running program restarts its helper once in the same mode; removals and clearing the global switch never downgrade a running helper.
2026-11-02 01:15:33 -05:00

60 lines
2.1 KiB
Go

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