Waitsnake / AnimatedGif

A screensaver for Mac OSX / macOS that plays animated GIFs and APNGs
MIT License
211 stars 31 forks source link

ScreenSaverDefaults not updated in Sonoma #74

Open Waitsnake opened 4 months ago

Waitsnake commented 4 months ago

ScreenSaverDefaults are not updated in macOS Sonoma when changed in System Preferences because an old instance of legacyScreenSaver with older values is still running in background and this instance will be reused when activating the screen saver again. Since Sonoma macOS keeps the instance running instead closing legacyScreenSaver after screen saver was finished and not starting a new instance with new values from ScreenSaverDefaults as it worked with older macOS versions. This new behaviour of macOS leads to the negative side effect that your new options will only shown in preview window of System Preferences (they create here a 2nd instance of legacyScreenSaver that they use correctly), but will be ignored by the real screen saver until you reboot your machine or maybe log off and log in your user account on macOS.

Waitsnake commented 4 months ago

I found a workaround here: https://github.com/JohnCoates/Aerial/issues/1305#issuecomment-1680853387

Adding a notification handler to "com.apple.screensaver.willstop" notification that executes a "exit(0)" will quit this old background instance when the screensaver is no longer used instead of keeping it running.

This has the positive side effect that the 'real screen saver' will use your new changed options and not only the preview window inside System Preferences.

VETspert commented 3 weeks ago

@Waitsnake Hi, can you tell me how this can be done? I am looking for a way to do this via MDM. Thanks

Waitsnake commented 2 weeks ago

Ofc, but you could just have a look at the same files of this very commit #74 that is linked here where you asked your question. ;)

inside your method: - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview start your own event handler method that i called "sonomaQuitWorkaround" for the event "com.apple.screensaver.willstop":

    // workaround for Sonoma
    if ([self isPreview] == FALSE)
    {
        [[NSDistributedNotificationCenter defaultCenter]
           addObserver:self
           selector:@selector(sonomaQuitWorkaround)
           name:@"com.apple.screensaver.willstop"
           object:nil];
    }

and here is the event handler that basically only calls function "exit(0)":

- (void) sonomaQuitWorkaround
{
    // workaround for Sonoma:
    // quit legacyScreenSaver when screensaver is stoped instead of keeping instance running in background as it is the case in Sonoma
    // problem with this running background legacyScreenSaver is that it keeps using old vales of ScreenSaverDefaults and ignores new options the user has done in the meantime.
    exit(0);
}