From c0cf32c2b7d89f5e976dddcd05e663eec83c26b6 Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 22 Apr 2022 05:00:33 +0200 Subject: [PATCH] Remove obsolete fallbacks folder older OS versions (#2110) * Remove fallback for NSByteCountFormatter * Remove fallback for NSFont -monospacedDigitSystemFontOfSize:weight: --- Sparkle/SPUStandardUserDriver.m | 41 ++++++--------------------------- Sparkle/SUStatusController.m | 8 +------ 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 58374b58..810d22d5 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -440,50 +440,23 @@ } } -- (NSString *)localizedStringFromByteCount:(long long)value -{ - if (![SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}]) { - if (value < 1000) { - return [NSString stringWithFormat:@"%.0lf %@", value / 1.0, - SULocalizedString(@"B", @"the unit for bytes")]; - } - - if (value < 1000 * 1000) { - return [NSString stringWithFormat:@"%.0lf %@", value / 1000.0, - SULocalizedString(@"KB", @"the unit for kilobytes")]; - } - - if (value < 1000 * 1000 * 1000) { - return [NSString stringWithFormat:@"%.1lf %@", value / 1000.0 / 1000.0, - SULocalizedString(@"MB", @"the unit for megabytes")]; - } - - return [NSString stringWithFormat:@"%.2lf %@", value / 1000.0 / 1000.0 / 1000.0, - SULocalizedString(@"GB", @"the unit for gigabytes")]; - } - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpartial-availability" - NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init]; - [formatter setZeroPadsFractionDigits:YES]; - return [formatter stringFromByteCount:value]; -#pragma clang diagnostic pop -} - - (void)showDownloadDidReceiveDataOfLength:(uint64_t)length { assert(NSThread.isMainThread); - + self.bytesDownloaded += length; - + + NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init]; + [formatter setZeroPadsFractionDigits:YES]; + if (self.expectedContentLength > 0.0) { double newProgressValue = (double)self.bytesDownloaded / (double)self.expectedContentLength; [self.statusController setProgressValue:MIN(newProgressValue, 1.0)]; - [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self localizedStringFromByteCount:(long long)self.bytesDownloaded], [self localizedStringFromByteCount:(long long)MAX(self.bytesDownloaded, self.expectedContentLength)]]]; + [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", @"The download progress in units of bytes, e.g. 100 KB of 1,0 MB"), [formatter stringFromByteCount:(long long)self.bytesDownloaded], [formatter stringFromByteCount:(long long)MAX(self.bytesDownloaded, self.expectedContentLength)]]]; } else { - [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self localizedStringFromByteCount:(long long)self.bytesDownloaded]]]; + [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", @"The download progress in a unit of bytes, e.g. 100 KB"), [formatter stringFromByteCount:(long long)self.bytesDownloaded]]]; } } diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index fa006a25..5787f073 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -60,13 +60,7 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL self.window.styleMask |= NSWindowStyleMaskMiniaturizable; } [self.progressBar setUsesThreadedAnimation:YES]; - - if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 11, 0}]) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpartial-availability" - [self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]]; -#pragma clang diagnostic pop - } + [self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]]; } - (NSString *)windowTitle