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];
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 5821 bytes
> Desc: not available
> URL: 
> <https://lists.apple.com/archives/cocoa-dev/attachments/20231012/e3a91277/attachment.bin>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 12 Oct 2023 08:22:21 -0500
> From: Steve Mills <sjmi...@mac.com>
> To: Cocoa dev <cocoa-dev@lists.apple.com>
> Subject: Re: Screen saver settings don't take effect (again) under
> Sonoma
> Message-ID: <0d02e197-d36a-4a4b-ac48-297848fe9...@mac.com>
> Content-Type: text/plain; charset=us-ascii
>
>> On Oct 12, 2023, at 04:54, Gabriel Zachmann via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> wrote:
>>
>> 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).
>>
>> 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];
>
> registerDefaults isn't doing what you think it's doing. Read its docs more 
> carefully.
>
> And there's no need to call synchronize. The docs clearly point that out: 
> "this method is unnecessary and shouldn't be used."
>
> To set a new default, simply use setObject:forKey:. To read them, simply use 
> objectForKey: or dictionaryForKey:, since you're using one.
>
> 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?
>
> NSUserDefaults* defaults = [ScreenSaverDefaults 
> defaultsForModuleWithName:@"com.yourcompany.yourscreensaver"];
>
> --
> Steve Mills
> Drummer, Mac geek
>
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 12 Oct 2023 06:43:49 -0700
> From: Michael Diehr <m...@xochi.com>
> To: Cocoa dev <cocoa-dev@lists.apple.com>
> Subject: Re: Screen saver settings don't take effect (again) under
> Sonoma
> Message-ID: <50200ccb-4313-4898-b9f1-c72b15257...@xochi.com>
> Content-Type: text/plain; charset=us-ascii
>
> 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
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
>
> Cocoa-dev mailing list      (Cocoa-dev@lists.apple.com)
>
> Do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins (at) lists.apple.com
>
> https://lists.apple.com/mailman/listinfo/cocoa-dev
>
>
> ------------------------------
>
> End of Cocoa-dev Digest, Vol 20, Issue 55
> *****************************************

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to