Re: Screen saver settings don't take effect (again) under Sonoma
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=1a1hai; t=1697116953; bh=HPDkzxDcniMud/IlXLSkyv3XoVapK8Y3eYcDsd6ZEd8=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=l2QQZbVR8F5cIhZUp44bBeGdI0QexJh8y73wv729iahvjNpQGp0fu68xUY6iZz0f9 dV8ClhF/oa14hT/2Yh1TxZQv2wh16l7ggp3diNGNf9fCuTY+5yQHbNC8sgUBv62aBU PuWcR+fsIzOd33uprDdxlND722SFAPMFne5jFO3Df3v2V9UyViJzKrhXVFEeQ+TZ2K KEPlwVOgY3gyu42cR+THL1yVVA/t1u6FwGKq1mzGiRZDHokvQzeS4qrL7fdtBcXDE3 swi1AnByQgfBCCQjOj7vyh9cCUEdjRXdC52KSrSI3X1VKYha5pBpjivqAP3ahLzB6S TE7P4mzX8Gr4w==
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 _______________________________________________ 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/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Steve Mills via Cocoa-dev