site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-bremen.de; s=2019; t=1706810031; i=@uni-bremen.de; bh=c/gEwS/uH1M27jc/l1FssWBqkr9vLEBZ0/Zer3FX9bI=; h=From:In-Reply-To:Date:Cc:References:To; b=PoYD+7emqFBJvGCt+ruf1K+C1t9t9yqfFKdj70otL9k5Uo3+mbQpVkPQmNUOOHZ6F 6H2h+GJhDS6BSadL+MpxsH/20S61ZghN3GH2FJ4PHbNJxHpQfBD1ElT468P0xUC65K 6wOQuzdsIDLTxjl6Zk+QwDzqKorHi/5+wr5OiQwtDTFD0HQ9hvBcy3cS8LDixCfUCH Hrmwh24itR1tQtCrmgcQVGSmMFGSXmGvMsrH1K309bM5qbUnAQdMDMX6wqv6cEwgMd Oz1hC7gYV0vZd/Jcg7cTsx2P2A2VoheaM29pmk0VXiCIDiCobaQ9FmiKy8EeZHJjno 8GA2M7s6bTu+g== Thanks a lot for your responses. I'd like to come back on this issue, and start tackling it again. (Last time, lots of other stuff got in the way.) As a recap in a nutshell: user preferences/settings won't stick in the screensaver. (They do in the app, which uses pretty much the same code, but for the screensaver they only stick after rebooting.) Enclosed you can find my original post. Below you can find my responses and questions.
registerDefaults isn't doing what you think it's doing. Read its docs more carefully.
I am unsure what you mean. I have (re-)read the docs on NSUserDefaults , and it says there "Adds the contents of the specified dictionary to the registration domain". And later, it says: """ NSRegistrationDomain The domain consisting of a set of temporary defaults whose values can be set by the application to ensure that searches will always be successful. """ Maybe you were thinking of a situation where a new version of my app would add a default of some key/value, but the defaults database of that app does not contain it in its dictionary for the display, although it would contain a value (i.e., dictionary) for that displayname. That could become a problem at some point, but I fail to se why it should prevent the defaults from being persistent. (for the screensaver)
And there's no need to call synchronize. The docs clearly point that out: "this method is unnecessary and shouldn't be used."
I removed that.
To set a new default, simply use setObject:forKey:. To read them, simply use objectForKey: or dictionaryForKey:, since you're using one.
That is what I am doing. Once I get the dictionary, I extract all the values from it. So, at load time, I do NSDictionary * monitor_user_prefs = [defaults_ dictionaryForKey: displayName_]; And if the user changes one of the settings, I just create a new dictionary object, and do [defaults_ setObject: monitor_user_prefs forKey: displayName_];
What you haven't shown is how you're coming up with a screen name. Are you sure it's the same every time for each screen?
Also, you *are* using the correct NSUserDefaults object, yes?
I would like to think so. In the regular app, I just use: defaults_ = [NSUserDefaults standardUserDefaults]; In the screensaver , I use: defaults_name_ = [ NSString stringWithFormat:@"de.zach.ArtSaver" ]; defaults_ = [ScreenSaverDefaults defaultsForModuleWithName: defaults_name_]; And that is the only difference in the code; all the rest is exactly the same.
What you haven't shown is how you're coming up with a screen name. Are you sure it's the same every time for each screen?
Yes, and I have just double-checked. I noticed something rather curious: my screensaver continues to run, even though I quit System Settings. But I can see messages from my screen saver appearing in the log even a long time afterwards. Could that be related to me problem with the persistence of the settings? @Michael Diehl:
There's an active discussion rying to reverse-engineer the screen saver settings in Sonoma over on GitHub: https://github.com/JohnCoates/Aerial/issues/1332
Thanks a lot, but it seems to me that the goal/issue of that discussion is different to what I am facing. Best regards, Gabriel Encl.:
Now, under Sonoma (14.0), I have an issue with the settings (user defaults) of my screen saver, again.
I go into System Settings, change some settings of my screen saver, they take effect immediately in the little Preview window in SysSettings, but when I click on "Preview" or let the screen saver come on automatically, the new settings are *not* in effect.
From one user, I heard that the new settings take effect only after rebooting.
So, maybe, something has changed in the way macOS 14.0 handles the NSUserDefaults, and/or maybe I make an error with using the API. Maybe there is a bug in macOS 14.0 ?
Below you can find a recap of how I handle the settings using NSUserDefaults. Interestingly, the same code works fine in a regular app (not screensaver).
I will be very grateful for any kind of suggestions or insights.
Best regards, Gabriel
My screensaver stores different settings for different monitors in the [NSUserDefaults standardUserDefaults]. To do so, I generate defaults_ = [NSUserDefaults standardUserDefaults];
Then, I create a dictionary containing the default settings and register them, like this:
NSDictionary * monitor_defaults = [NSDictionary dictionaryWithObjectsAndKeys: defaultsForMonitor, displayname, nil ]; [defaults_ registerDefaults: monitor_defaults]; NSDictionary * monitor_user_prefs = [defaults_ dictionaryForKey: displayname];
Then, I read the actual values from monitor_user_prefs.
When the user changes a setting, I do the inverse, like this:
.. create a new dictionary monitor_user_prefs, containing all the key/value pairs of the settings .. [defaults_ setObject: monitor_user_prefs forKey: displayName_]; bool success = [defaults_ synchronize];