Skip to content

Commit

Permalink
#74: Workaround for ScreenSaverDefaults not updated in Sonoma
Browse files Browse the repository at this point in the history
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 re-used when activating the screen saver again instead closing of legacyScreenSaver and starting an new instance with new values from ScreenSaverDefaults.
Adding a notification handler to com.apple.screensaver.willstop with exit(0) will now quit this old background instance when the screensaver is stoped used instead of keeping it running and reuing it later.
  • Loading branch information
Waitsnake committed Jun 3, 2024
1 parent 83b537a commit a34828a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
20 changes: 17 additions & 3 deletions AnimatedGif.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -139,12 +139,12 @@
CC24BA8C1BF124350045BDC7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1250;
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1530;
ORGANIZATIONNAME = "Marco Köhler";
TargetAttributes = {
CC24BA941BF124350045BDC7 = {
CreatedOnToolsVersion = 6.2;
DevelopmentTeam = SQ837JJYGQ;
};
};
};
Expand Down Expand Up @@ -265,9 +265,11 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Apple Development: [email protected] (RHZ2NT4CZR)";
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -321,10 +323,12 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Apple Development: [email protected] (RHZ2NT4CZR)";
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -342,9 +346,14 @@
CC24BAA11BF124350045BDC7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
"DEVELOPMENT_TEAM[sdk=macosx*]" = SQ837JJYGQ;
INFOPLIST_FILE = AnimatedGif/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.5.5;
PRODUCT_BUNDLE_IDENTIFIER = "noname.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
Expand All @@ -355,9 +364,14 @@
CC24BAA21BF124350045BDC7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
"DEVELOPMENT_TEAM[sdk=macosx*]" = SQ837JJYGQ;
INFOPLIST_FILE = AnimatedGif/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.5.5;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "noname.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1530"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
buildImplicitDependencies = "YES"
buildArchitectures = "All">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedGif/AnimatedGifView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
arrayLock = [[NSLock alloc] init];
self = [super initWithFrame:frame isPreview:isPreview];

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

// initialize screensaver defaults with an default value
ScreenSaverDefaults *defaults = [ScreenSaverDefaults defaultsForModuleWithName:[[NSBundle bundleForClass: [self class]] bundleIdentifier]];
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
Expand Down Expand Up @@ -81,6 +91,14 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
return self;
}

- (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);
}

- (NSOpenGLView *)createViewGL
{
NSOpenGLPixelFormatAttribute attribs[] = {
Expand Down
2 changes: 1 addition & 1 deletion AnimatedGif/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.4</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>com.waitsnake.animatedgif</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit a34828a

Please sign in to comment.