From f36c34f2f4251bfc30ba7c6a2dec79aac66a58b5 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 2 Dec 2022 23:01:01 -0800 Subject: [PATCH] Remove duplicate Sparkle localization strings in Updater app (#2288) --- Sparkle.xcodeproj/project.pbxproj | 2 - .../InstallerProgress-Info.plist | 38 +++++++++++ .../InstallerProgressAppController.m | 2 + .../InstallerProgressDelegate.h | 1 + .../InstallerProgress/ShowInstallerProgress.m | 63 ++++++++++++++++++- Sparkle/SPUStandardUserDriver.m | 4 +- Sparkle/SULocalizations.h | 4 +- Sparkle/SUStatus.xib | 7 +-- Sparkle/SUStatusController.h | 2 +- Sparkle/SUStatusController.m | 11 ++-- 10 files changed, 114 insertions(+), 20 deletions(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index a8808725..ea92932f 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -212,7 +212,6 @@ 724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3971D333832005D534A /* SUInstallerStatus.m */; }; 724BB3B71D35ABA8005D534A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 724F76F91D6EAD0D00ECD062 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; - 725264A91D5FBD9100CD6400 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 725602D31C83551C00DAA70E /* SUApplicationInfo.h */; }; 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SUApplicationInfo.m */; }; 725B3A82263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml in Resources */ = {isa = PBXBuildFile; fileRef = 725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */; }; @@ -3141,7 +3140,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 725264A91D5FBD9100CD6400 /* Sparkle.strings in Resources */, 72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sparkle/InstallerProgress/InstallerProgress-Info.plist b/Sparkle/InstallerProgress/InstallerProgress-Info.plist index 8d16cdba..8171ecad 100644 --- a/Sparkle/InstallerProgress/InstallerProgress-Info.plist +++ b/Sparkle/InstallerProgress/InstallerProgress-Info.plist @@ -28,6 +28,44 @@ $(MACOSX_DEPLOYMENT_TARGET) LSUIElement 1 + CFBundleLocalizations + + en + ca + ar + cs + da + de + el + en + es + fa + fi + fr + he + hr + hu + is + it + ja + ko + nb + nl + pl + pt-BR + pt-PT + ro + ru + sk + sl + sv + th + tr + uk + zh_CN + zh_HK + zh_TW + NSPrincipalClass NSApplication diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index a6078709..51fb5096 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -119,6 +119,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; _application = application; _delegate = delegate; + [delegate loadLocalizationStringsFromHost:host]; + _connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUInstallerAgentProtocol)]; _connection.exportedObject = self; diff --git a/Sparkle/InstallerProgress/InstallerProgressDelegate.h b/Sparkle/InstallerProgress/InstallerProgressDelegate.h index 887b1bb8..6ab9b55b 100644 --- a/Sparkle/InstallerProgress/InstallerProgressDelegate.h +++ b/Sparkle/InstallerProgress/InstallerProgressDelegate.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol InstallerProgressDelegate +- (void)loadLocalizationStringsFromHost:(SUHost *)host; - (void)installerProgressShouldDisplayWithHost:(SUHost *)host; - (void)installerProgressShouldStop; diff --git a/Sparkle/InstallerProgress/ShowInstallerProgress.m b/Sparkle/InstallerProgress/ShowInstallerProgress.m index a749eee2..54800a92 100644 --- a/Sparkle/InstallerProgress/ShowInstallerProgress.m +++ b/Sparkle/InstallerProgress/ShowInstallerProgress.m @@ -19,15 +19,72 @@ @end @implementation ShowInstallerProgress +{ + NSString *_updatingString; + NSString *_cancelUpdateTitle; + NSString *_installingUpdateTitle; +} @synthesize statusController = _statusController; +- (void)loadLocalizationStringsFromHost:(SUHost *)host +{ + // Try to retrieve localization strings from the old bundle if possible + // We won't display these strings until installerProgressShouldDisplayWithHost: + // (which will be after the update is trusted) + // If we fail to load localizations in any way, we default to English + + NSBundle *hostSparkleBundle; + { + NSURL *hostSparkleURL = [host.bundle.privateFrameworksURL URLByAppendingPathComponent:@"Sparkle.framework" isDirectory:YES]; + if (hostSparkleURL == nil) { + hostSparkleBundle = nil; + } else { + hostSparkleBundle = [NSBundle bundleWithURL:hostSparkleURL]; + } + } + + NSString *updatingString; + { + NSString *updatingFormatStringFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Updating %@", @"Sparkle", hostSparkleBundle, nil) : nil; + + NSString *hostNameFromBundle = host.name; + NSString *hostName = (hostNameFromBundle != nil) ? hostNameFromBundle : @""; + + if (updatingFormatStringFromBundle != nil) { + // Replacing the %@ will be a bit safer than using +[NSString stringWithFormat:] + updatingString = [updatingFormatStringFromBundle stringByReplacingOccurrencesOfString:@"%@" withString:hostName]; + } else { + updatingString = [@"Updating " stringByAppendingString:hostName]; + } + } + + _updatingString = updatingString; + + NSString *cancelUpdateTitle; + { + NSString *cancelUpdateTitleFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Cancel Update", @"Sparkle", hostSparkleBundle, @"") : nil; + cancelUpdateTitle = (cancelUpdateTitleFromBundle != nil) ? cancelUpdateTitleFromBundle : @"Cancel Update"; + } + + _cancelUpdateTitle = cancelUpdateTitle; + + NSString *installingUpdateTitle; + { + NSString *installingUpdateTitleFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Installing update…", @"Sparkle", hostSparkleBundle, @"") : nil; + installingUpdateTitle = (installingUpdateTitleFromBundle != nil) ? installingUpdateTitleFromBundle : @"Installing update…"; + } + + _installingUpdateTitle = installingUpdateTitle; +} + - (void)installerProgressShouldDisplayWithHost:(SUHost *)host { - self.statusController = [[SUStatusController alloc] initWithHost:host centerPointValue:nil minimizable:NO closable:NO]; + self.statusController = [[SUStatusController alloc] initWithHost:host windowTitle:_updatingString centerPointValue:nil minimizable:NO closable:NO]; + + [self.statusController setButtonTitle:_cancelUpdateTitle target:nil action:nil isDefault:NO]; + [self.statusController beginActionWithTitle:_installingUpdateTitle maxProgressValue:0 statusText:@""]; - [self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO]; - [self.statusController beginActionWithTitle:SULocalizedString(@"Installing update…", @"") maxProgressValue:0 statusText:@""]; [self.statusController showWindow:self]; } diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index e424093a..7de76c21 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -508,7 +508,7 @@ static const NSTimeInterval SUScheduledUpdateIdleEventLeewayInterval = DEBUG ? 3 self.cancellation = cancellation; - self.checkingController = [[SUStatusController alloc] initWithHost:self.host centerPointValue:nil minimizable:NO closable:NO]; + self.checkingController = [[SUStatusController alloc] initWithHost:self.host windowTitle:[NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [self.host name]] centerPointValue:nil minimizable:NO closable:NO]; [[self.checkingController window] center]; // Force the checking controller to load its window. [self.checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates…", nil) maxProgressValue:0.0 statusText:nil]; [self.checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; @@ -676,7 +676,7 @@ static const NSTimeInterval SUScheduledUpdateIdleEventLeewayInterval = DEBUG ? 3 centerPointValue = nil; } - self.statusController = [[SUStatusController alloc] initWithHost:self.host centerPointValue:centerPointValue minimizable:minimizable closable:closable]; + self.statusController = [[SUStatusController alloc] initWithHost:self.host windowTitle:[NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [self.host name]] centerPointValue:centerPointValue minimizable:minimizable closable:closable]; if (_updateAlertWindowWasInactive) { [self.statusController.window orderFront:nil]; diff --git a/Sparkle/SULocalizations.h b/Sparkle/SULocalizations.h index 9575bdb3..a291f257 100644 --- a/Sparkle/SULocalizations.h +++ b/Sparkle/SULocalizations.h @@ -11,6 +11,8 @@ #import "SUConstants.h" -#define SULocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", (NSBundle * _Nonnull)([NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle]), comment) +#define SULocalizedStringFromTableInBundle(key, tbl, bundle, comment) NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) + +#define SULocalizedString(key, comment) SULocalizedStringFromTableInBundle(key, @"Sparkle", (NSBundle * _Nonnull)([NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle]), comment) #endif /* SULocalizations_h */ diff --git a/Sparkle/SUStatus.xib b/Sparkle/SUStatus.xib index 87ca43b1..ebd4c973 100644 --- a/Sparkle/SUStatus.xib +++ b/Sparkle/SUStatus.xib @@ -1,8 +1,8 @@ - + - + @@ -103,9 +103,6 @@ - - - diff --git a/Sparkle/SUStatusController.h b/Sparkle/SUStatusController.h index 4d070b2a..e5597c19 100644 --- a/Sparkle/SUStatusController.h +++ b/Sparkle/SUStatusController.h @@ -24,7 +24,7 @@ @property (nonatomic) double maxProgressValue; @property (getter=isButtonEnabled) BOOL buttonEnabled; -- (instancetype)initWithHost:(SUHost *)aHost centerPointValue:(NSValue *)centerPointValue minimizable:(BOOL)minimizable closable:(BOOL)closable; +- (instancetype)initWithHost:(SUHost *)aHost windowTitle:(NSString *)windowTitle centerPointValue:(NSValue *)centerPointValue minimizable:(BOOL)minimizable closable:(BOOL)closable; // Pass 0 for the max progress value to get an indeterminate progress bar. // Pass nil for the status text to not show it. diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 2fb88450..a1d1faf2 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -26,6 +26,7 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL @implementation SUStatusController { + NSString *_windowTitle; NSValue *_centerPointValue; BOOL _closable; } @@ -42,7 +43,7 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL @synthesize touchBarButton; @synthesize minimizable = _minimizable; -- (instancetype)initWithHost:(SUHost *)aHost centerPointValue:(NSValue *)centerPointValue minimizable:(BOOL)minimizable closable:(BOOL)closable +- (instancetype)initWithHost:(SUHost *)aHost windowTitle:(NSString *)windowTitle centerPointValue:(NSValue *)centerPointValue minimizable:(BOOL)minimizable closable:(BOOL)closable { self = [super initWithWindowNibName:@"SUStatus" owner:self]; if (self) @@ -51,6 +52,7 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL _centerPointValue = centerPointValue; _minimizable = minimizable; _closable = closable; + _windowTitle = [windowTitle copy]; [self setShouldCascadeWindows:NO]; } return self; @@ -77,11 +79,8 @@ static NSString *const SUStatusControllerTouchBarIndentifier = @"" SPARKLE_BUNDL } [self.progressBar setUsesThreadedAnimation:YES]; [self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]]; -} - -- (NSString *)windowTitle -{ - return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [self.host name]]; + + self.window.title = _windowTitle; } - (NSImage *)applicationIcon