Add accessor for global config

This commit is contained in:
Sasha Koshka 2024-08-23 01:12:02 -04:00
parent f512deb96e
commit 4b29820452

View File

@ -147,7 +147,11 @@ func RunApplication (application Application) {
// open config // open config
globalConfig, err := ApplicationConfig(GlobalApplicationDescription()) globalConfig, err := ApplicationConfig(GlobalApplicationDescription())
if err != nil { log.Fatalln("nasin: could not open config:", err) } if err != nil { log.Fatalln("nasin: could not open config:", err) }
defer globalConfig.Close() currentGlobalConfig = globalConfig
defer func () {
globalConfig.Close()
currentGlobalConfig = nil
} ()
styleConfigKey := "Style" styleConfigKey := "Style"
iconSetConfigKey := "IconSet" iconSetConfigKey := "IconSet"
@ -224,6 +228,13 @@ func ApplicationConfig (app ApplicationDescription) (config.ConfigCloser, error)
return config.NewConfig(user, system...) return config.NewConfig(user, system...)
} }
var currentGlobalConfig config.Config
// GlobalConfig returns the global config. This is managed by Nasin and must not
// be closed by the application.
func GlobalConfig () config.Config {
return currentGlobalConfig
}
func errorPopupf (title, format string, v ...any) func (func ()) { func errorPopupf (title, format string, v ...any) func (func ()) {
return func (callback func ()) { return func (callback func ()) {
dialog, err := objects.NewDialogOk ( dialog, err := objects.NewDialogOk (