From bb9ee3c59b39e6b3abebc6abae1e1e293eca0340 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 23 Jan 2021 19:09:25 -0800 Subject: [PATCH 1/5] Fix edge cases with hiding alert buttons and using "Install Later" --- Sparkle/SUUpdateAlert.m | 58 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index e826ee69..2ac88868 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -305,57 +305,55 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.releaseNotesContainerView removeFromSuperview]; } + // NOTE: The code below for deciding what buttons to hide is complex! Due to array of feature configurations :) + // When we show release notes, it looks ugly if the install buttons are not closer to the release notes view // However when we don't show release notes, it looks ugly if the install buttons are too close to the description field. Shrugs. - if (showReleaseNotes && ![self allowsAutomaticUpdates]) { + BOOL allowsAutomaticUpdates = [self allowsAutomaticUpdates]; + // Automatic downloads is enabled by developer if they set SUAutomaticallyUpdateKey in Info.plist, + // rather than the user toggling the setting + BOOL automaticDownloadsEnabledByDeveloper = [self.host boolForInfoDictionaryKey:SUAutomaticallyUpdateKey]; + if (showReleaseNotes && (!allowsAutomaticUpdates || automaticDownloadsEnabledByDeveloper)) { + // Fix constraints so that buttons aren't far away from web view when we hide the automatic updates check box NSLayoutConstraint *skipButtonToReleaseNotesContainerConstraint = [NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.releaseNotesContainerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12.0]; [self.window.contentView addConstraint:skipButtonToReleaseNotesContainerConstraint]; [self.automaticallyInstallUpdatesButton removeFromSuperview]; } + + if (automaticDownloadsEnabledByDeveloper) { + if (!showReleaseNotes) { + // Disable automatic install updates option if the developer wishes for it in Info.plist + // If we are showing release notes, this button will be hidden instead + self.automaticallyInstallUpdatesButton.enabled = NO; + } + + // A developer wishing for automatic updates shouldn't want users to skip updates + self.skipButton.hidden = YES; + } if ([self.updateItem isCriticalUpdate]) { - self.skipButton.enabled = NO; self.skipButton.hidden = YES; - self.laterButton.enabled = NO; self.laterButton.hidden = YES; } - if (![self automaticChecksEnabled]) { - self.laterButton.enabled = NO; + // Reminding user later doesn't make sense when automatic update checks are off + if (![self.host boolForKey:SUEnableAutomaticChecksKey]) { self.laterButton.hidden = YES; } - - if([self automaticallyUpdateEnabled]) { - self.skipButton.hidden = YES; - self.automaticallyInstallUpdatesButton.hidden = YES; - [self.laterButton setTitle:SULocalizedString(@"Install later", @"Alternate title for 'Remind me later' button when automatic updates are enabled")]; + + // If the developer makes use of minimumAutoupdateVersion, just stick to Remind Me Later on the safe side + // (Install Later would be harmfully incorrect if this update cannot be automatically installed) + // And SUUpdateAlert is really not the place to do comparison/version checks. + // Also make sure to check that the system allows us to automatically update. + if ([self.host boolForKey:SUAutomaticallyUpdateKey] && allowsAutomaticUpdates && self.updateItem.minimumAutoupdateVersion.length == 0) { + [self.laterButton setTitle:SULocalizedString(@"Install Later", @"Alternate title for 'Remind Me Later' button when automatic updates are enabled")]; } [self.window center]; } -- (BOOL)automaticChecksEnabled { - NSNumber *automaticChecksEnabled = [self.host objectForKey:SUEnableAutomaticChecksKey]; - if (automaticChecksEnabled == nil) - { - return false; - } - - return [automaticChecksEnabled boolValue]; -} - -- (BOOL)automaticallyUpdateEnabled { - NSNumber *automaticChecksEnabled = [self.host objectForKey:SUAutomaticallyUpdateKey]; - if (automaticChecksEnabled == nil) - { - return false; - } - - return [automaticChecksEnabled boolValue]; -} - - (BOOL)windowShouldClose:(NSNotification *) __unused note { [self endWithSelection:SURemindMeLaterChoice]; From 9cc9f51d7c7339e0311b85d67651ca893ec5b10e Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 23 Jan 2021 19:20:33 -0800 Subject: [PATCH 2/5] Add clarification on developer too --- Sparkle/SUUpdateAlert.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 2ac88868..f9440a04 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -345,8 +345,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // If the developer makes use of minimumAutoupdateVersion, just stick to Remind Me Later on the safe side // (Install Later would be harmfully incorrect if this update cannot be automatically installed) - // And SUUpdateAlert is really not the place to do comparison/version checks. - // Also make sure to check that the system allows us to automatically update. + // And this is really not the place to do comparison/version checks. + // Also make sure to check that the system and developer allows us to automatically update. if ([self.host boolForKey:SUAutomaticallyUpdateKey] && allowsAutomaticUpdates && self.updateItem.minimumAutoupdateVersion.length == 0) { [self.laterButton setTitle:SULocalizedString(@"Install Later", @"Alternate title for 'Remind Me Later' button when automatic updates are enabled")]; } From a85db747f13d222d8889e775b2a1c6eb14bc5078 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 23 Jan 2021 19:37:29 -0800 Subject: [PATCH 3/5] Add more comments --- Sparkle/SUUpdateAlert.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index f9440a04..9db1a078 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -347,6 +347,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // (Install Later would be harmfully incorrect if this update cannot be automatically installed) // And this is really not the place to do comparison/version checks. // Also make sure to check that the system and developer allows us to automatically update. + // This logic is not very sound and gets worse in 2.x where apps can be sandboxed. We may need to revisit this + // and also decide if we really need this button in the first place. if ([self.host boolForKey:SUAutomaticallyUpdateKey] && allowsAutomaticUpdates && self.updateItem.minimumAutoupdateVersion.length == 0) { [self.laterButton setTitle:SULocalizedString(@"Install Later", @"Alternate title for 'Remind Me Later' button when automatic updates are enabled")]; } From f60b60b08f7e44a47033c6d85a05c8254081efbc Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 23 Jan 2021 21:14:59 -0800 Subject: [PATCH 4/5] Fix automatic updates checkbox state when not showing release notes --- Sparkle/Base.lproj/SUUpdateAlert.xib | 5 ----- Sparkle/SUUpdateAlert.m | 24 +++++++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Sparkle/Base.lproj/SUUpdateAlert.xib b/Sparkle/Base.lproj/SUUpdateAlert.xib index f9d5d104..94fbcc59 100644 --- a/Sparkle/Base.lproj/SUUpdateAlert.xib +++ b/Sparkle/Base.lproj/SUUpdateAlert.xib @@ -174,11 +174,6 @@ DQ - - - NSNegateBoolean - - diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 9db1a078..1ed51560 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -313,22 +313,20 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // Automatic downloads is enabled by developer if they set SUAutomaticallyUpdateKey in Info.plist, // rather than the user toggling the setting BOOL automaticDownloadsEnabledByDeveloper = [self.host boolForInfoDictionaryKey:SUAutomaticallyUpdateKey]; - if (showReleaseNotes && (!allowsAutomaticUpdates || automaticDownloadsEnabledByDeveloper)) { - // Fix constraints so that buttons aren't far away from web view when we hide the automatic updates check box - NSLayoutConstraint *skipButtonToReleaseNotesContainerConstraint = [NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.releaseNotesContainerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12.0]; - - [self.window.contentView addConstraint:skipButtonToReleaseNotesContainerConstraint]; - - [self.automaticallyInstallUpdatesButton removeFromSuperview]; + if (!allowsAutomaticUpdates || automaticDownloadsEnabledByDeveloper) { + if (showReleaseNotes) { + // Fix constraints so that buttons aren't far away from web view when we hide the automatic updates check box + NSLayoutConstraint *skipButtonToReleaseNotesContainerConstraint = [NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.releaseNotesContainerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12.0]; + + [self.window.contentView addConstraint:skipButtonToReleaseNotesContainerConstraint]; + + [self.automaticallyInstallUpdatesButton removeFromSuperview]; + } else { + self.automaticallyInstallUpdatesButton.enabled = NO; + } } if (automaticDownloadsEnabledByDeveloper) { - if (!showReleaseNotes) { - // Disable automatic install updates option if the developer wishes for it in Info.plist - // If we are showing release notes, this button will be hidden instead - self.automaticallyInstallUpdatesButton.enabled = NO; - } - // A developer wishing for automatic updates shouldn't want users to skip updates self.skipButton.hidden = YES; } From 9561d522e39bbb387d2037c4cd06cc8a518a8f74 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 24 Jan 2021 01:09:36 -0800 Subject: [PATCH 5/5] Keep skip button available if there is a minimum autoupdate version --- Sparkle/SUUpdateAlert.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 1ed51560..e42fe7ea 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -326,8 +326,9 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } - if (automaticDownloadsEnabledByDeveloper) { - // A developer wishing for automatic updates shouldn't want users to skip updates + // A developer wishing for automatic updates shouldn't want users to skip updates + // Except maybe when there's a minimum auto update version for auto-downloading specified + if (automaticDownloadsEnabledByDeveloper && self.updateItem.minimumAutoupdateVersion.length == 0) { self.skipButton.hidden = YES; }