diff --git a/Sparkle/SPUDownloadData.m b/Sparkle/SPUDownloadData.m index e769dd50..ecef8338 100644 --- a/Sparkle/SPUDownloadData.m +++ b/Sparkle/SPUDownloadData.m @@ -8,6 +8,7 @@ #import "SPUDownloadData.h" +#import "SUOperatingSystem.h" #include "AppKitPrevention.h" @@ -52,7 +53,9 @@ static NSString *SPUDownloadMIMETypeKey = @"SPUDownloadMIMEType"; - (nullable instancetype)initWithCoder:(NSCoder *)decoder { - if (@available(macOS 10.8, *)) { + if (SUAVAILABLE(10, 8)) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" NSData *data = [decoder decodeObjectOfClass:[NSData class] forKey:SPUDownloadDataKey]; if (data == nil) { return nil; @@ -61,6 +64,7 @@ static NSString *SPUDownloadMIMETypeKey = @"SPUDownloadMIMEType"; NSString *textEncodingName = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadTextEncodingKey]; NSString *MIMEType = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadMIMETypeKey]; +#pragma clang diagnostic pop return [self initWithData:data textEncodingName:textEncodingName MIMEType:MIMEType]; } else { diff --git a/Sparkle/SPUURLRequest.m b/Sparkle/SPUURLRequest.m index 13e4ad3a..b4866797 100644 --- a/Sparkle/SPUURLRequest.m +++ b/Sparkle/SPUURLRequest.m @@ -8,6 +8,7 @@ #import "SPUURLRequest.h" +#import "SUOperatingSystem.h" #include "AppKitPrevention.h" @@ -72,11 +73,14 @@ static NSString *SPUURLRequestNetworkServiceTypeKey = @"SPUURLRequestNetworkServ - (instancetype)initWithCoder:(NSCoder *)decoder { - if (@available(macOS 10.8, *)) { + if (SUAVAILABLE(10, 8)) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" NSURL *url = [decoder decodeObjectOfClass:[NSURL class] forKey:SPUURLRequestURLKey]; NSURLRequestCachePolicy cachePolicy = (NSURLRequestCachePolicy)[decoder decodeIntegerForKey:SPUURLRequestCachePolicyKey]; NSTimeInterval timeoutInterval = [decoder decodeDoubleForKey:SPUURLRequestTimeoutIntervalKey]; NSDictionary *httpHeaderFields = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class], [NSString class]]] forKey:SPUURLRequestHttpHeaderFieldsKey]; +#pragma clang diagnostic pop NSURLRequestNetworkServiceType networkServiceType = (NSURLRequestNetworkServiceType)[decoder decodeIntegerForKey:SPUURLRequestNetworkServiceTypeKey]; return [self initWithURL:url cachePolicy:cachePolicy timeoutInterval:timeoutInterval httpHeaderFields:httpHeaderFields networkServiceType:networkServiceType]; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index d63a023c..14aa3729 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -86,7 +86,7 @@ [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"]; - if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 9, 0}]) { + if (SUAVAILABLE(10, 9)) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" self.download = [[SPUDownloaderSession alloc] initWithDelegate:self]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 4265a3eb..1fe2f293 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -283,7 +283,7 @@ withRequest:request]; } - if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 9, 0}]) { + if (SUAVAILABLE(10, 9)) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" self.download = [[SPUDownloaderSession alloc] initWithDelegate:self]; diff --git a/Sparkle/SUOperatingSystem.h b/Sparkle/SUOperatingSystem.h index e4334d90..bdb87926 100644 --- a/Sparkle/SUOperatingSystem.h +++ b/Sparkle/SUOperatingSystem.h @@ -22,3 +22,9 @@ typedef struct { + (NSString *)systemVersionString; @end + +#if defined(__clang_major__) && __clang_major__ >= 9 +#define SUAVAILABLE(major, minor) @available(macOS major##.##minor, *) +#else +#define SUAVAILABLE(major, minor) [SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){major, minor, 0}] +#endif diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 7bb932ab..b51fe7fe 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -57,7 +57,7 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL [[self window] setFrameAutosaveName:@"SUStatusFrame"]; [self.progressBar setUsesThreadedAnimation:YES]; - if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 11, 0}]) { + if (SUAVAILABLE(10, 11)) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpartial-availability" [self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]]; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 2eb73ef0..59ddd32e 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,6 +21,7 @@ #import "SUAppcastItem.h" #import "SUApplicationInfo.h" #import "SUSystemUpdateInfo.h" +#import "SUOperatingSystem.h" #import "SUTouchBarForwardDeclarations.h" #import "SUTouchBarButtonGroup.h" @@ -97,7 +98,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (void)dealloc { #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - if (@available(macOS 10.14, *)) { + if (SUAVAILABLE(10, 14)) { if (self.observingAppearance) { [self.window removeObserver:self forKeyPath:@"effectiveAppearance"]; self.observingAppearance = NO; @@ -167,7 +168,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE prefs.defaultFontSize = (int)[NSFont systemFontSize]; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - if (@available(macOS 10.14, *)) + if (SUAVAILABLE(10, 14)) { NSBox *darkBackgroundView = [[NSBox alloc] initWithFrame:self.releaseNotesView.frame]; darkBackgroundView.boxType = NSBoxCustom; @@ -308,11 +309,14 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (void)adaptReleaseNotesAppearance { #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - if (@available(macOS 10.14, *)) + if (SUAVAILABLE(10, 14)) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" NSAppearanceName bestAppearance = [self.window.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; BOOL isDarkAqua = ([bestAppearance isEqualToString:NSAppearanceNameDarkAqua]); self.releaseNotesView.preferences.userStyleSheetEnabled = isDarkAqua; +#pragma clang diagnostic pop } #endif } diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index e12761b9..e1c7b1f8 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -26,6 +26,7 @@ #import "SUSystemProfiler.h" #import "SUSystemUpdateInfo.h" #import "SUSignatures.h" +#import "SUOperatingSystem.h" NSString *const SUUpdaterDidFinishLoadingAppCastNotification = @"SUUpdaterDidFinishLoadingAppCastNotification"; NSString *const SUUpdaterDidFindValidUpdateNotification = @"SUUpdaterDidFindValidUpdateNotification"; @@ -298,8 +299,11 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults BOOL automatic = [self automaticallyDownloadsUpdates]; if (!automatic) { - if (@available(macOS 10.9, *)) { + if (SUAVAILABLE(10, 9)) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.apple.notificationcenterui"]; +#pragma clang diagnostic pop BOOL dnd = [defaults boolForKey:@"doNotDisturb"]; if (dnd) { SULog(SULogLevelDefault, @"Delayed update, because Do Not Disturb is on");