From c63c66c737346840c436b27ed4d1adfc20227af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 18 Mar 2024 05:23:39 +0800 Subject: [PATCH] fix: Sparkle Version Comparator (#5263) * fix: Sparkle Version Comparator * Code review: Reducing CFBundleVersion to three components and avoiding versionComparatorForUpdater * adding +99 when it's a non-beta release * code review: set CFBUNDLE_VERSION and unset components * re-adding support for ignoring beta --- CMakeLists.txt | 13 +++++++++ Transmission.xcodeproj/project.pbxproj | 6 ++++ libtransmission/version.h.in | 2 +- macosx/Base.lproj/PrefsWindow.xib | 1 - macosx/CMakeLists.txt | 2 ++ macosx/Controller.mm | 20 +++++++++---- macosx/Info.plist.in | 2 +- macosx/PrefsController.mm | 13 --------- macosx/VersionComparator.h | 15 ++++++++++ macosx/VersionComparator.mm | 39 ++++++++++++++++++++++++++ update-version-h.sh | 5 +++- 11 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 macosx/VersionComparator.h create mode 100644 macosx/VersionComparator.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index c65fd3dd5..ac786853f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,19 @@ else() set(TR_STABLE_RELEASE 1) endif() +# derived from above: CFBundleVersion +# note: CFBundleVersion only honors 3 numbers, so third number has to hold both patch and beta info. +# 5.0.1-dev -> 14719.0.100 +# 5.0.1-beta.1 -> 14719.0.101 +# 5.0.1 -> 14719.0.199 +math(EXPR CFBUNDLE_1 "${TR_VERSION_MAJOR} + 14714") +math(EXPR CFBUNDLE_2 "${TR_VERSION_MINOR}") +math(EXPR CFBUNDLE_3 "${TR_VERSION_PATCH} * 100 + 0${TR_STABLE_RELEASE} * 99 + 0${TR_VERSION_BETA_NUMBER}") +set(CFBUNDLE_VERSION "${CFBUNDLE_1}.${CFBUNDLE_2}.${CFBUNDLE_3}") +unset(CFBUNDLE_1) +unset(CFBUNDLE_2) +unset(CFBUNDLE_3) + # derived from above: semver version string. https://semver.org/ # '4.0.0-beta.1' # '4.0.0-beta.1.dev' (a dev release between beta 1 and 2) diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index 0f8f8d85f..93142f2a5 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -403,6 +403,7 @@ C83B17212B7341BC00B2EAE4 /* tr-assert.cc in Sources */ = {isa = PBXBuildFile; fileRef = C1425B321EE9C5EA001DB85F /* tr-assert.cc */; }; C841A28129197724009F18E8 /* NSKeyedUnarchiverAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = C841A28029197724009F18E8 /* NSKeyedUnarchiverAdditions.mm */; }; C843FC8429C51B9400491854 /* utils.mm in Sources */ = {isa = PBXBuildFile; fileRef = C843FC8329C51B9400491854 /* utils.mm */; }; + C843FC8729C8B40800491854 /* VersionComparator.mm in Sources */ = {isa = PBXBuildFile; fileRef = C843FC8629C8B40800491854 /* VersionComparator.mm */; }; C86BCD9928228A9600F45599 /* SparkleProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = C86BCD9828228A9600F45599 /* SparkleProxy.mm */; }; C87369652809984200573C90 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C87369642809984200573C90 /* UserNotifications.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; C8748D8A29891EA100D9E979 /* suffixes_dafsa.h in Headers */ = {isa = PBXBuildFile; fileRef = C8748D8929891EA100D9E979 /* suffixes_dafsa.h */; }; @@ -1338,6 +1339,8 @@ C841A27F29197724009F18E8 /* NSKeyedUnarchiverAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSKeyedUnarchiverAdditions.h; sourceTree = ""; }; C841A28029197724009F18E8 /* NSKeyedUnarchiverAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSKeyedUnarchiverAdditions.mm; sourceTree = ""; }; C843FC8329C51B9400491854 /* utils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = utils.mm; sourceTree = ""; }; + C843FC8529C8B40800491854 /* VersionComparator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VersionComparator.h; sourceTree = ""; }; + C843FC8629C8B40800491854 /* VersionComparator.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VersionComparator.mm; sourceTree = ""; }; C86BCD9828228A9600F45599 /* SparkleProxy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SparkleProxy.mm; sourceTree = ""; }; C87369642809984200573C90 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; C8748D8929891EA100D9E979 /* suffixes_dafsa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = suffixes_dafsa.h; path = "third-party/suffixes_dafsa.h"; sourceTree = SOURCE_ROOT; }; @@ -1573,6 +1576,8 @@ C86BCD9828228A9600F45599 /* SparkleProxy.mm */, 4DF0C5AA0899190500DD8943 /* Controller.h */, 4DF0C5A90899190500DD8943 /* Controller.mm */, + C843FC8529C8B40800491854 /* VersionComparator.h */, + C843FC8629C8B40800491854 /* VersionComparator.mm */, 4DFBC2DD09C0970D00D5C571 /* Torrent.h */, 4DFBC2DE09C0970D00D5C571 /* Torrent.mm */, A27F0F310E19AD9800B2DB97 /* TorrentGroup.h */, @@ -3312,6 +3317,7 @@ A2B5B4E91880665E0071A66A /* ShareTorrentFileHelper.mm in Sources */, A22BAE281388040500FB022F /* NSMutableArrayAdditions.mm in Sources */, A2966E8713DAF74C007B52DF /* GlobalOptionsPopoverViewController.mm in Sources */, + C843FC8729C8B40800491854 /* VersionComparator.mm in Sources */, A234EA541453563B000F3E97 /* NSImageAdditions.mm in Sources */, A2AB883E16A399A6008FAD50 /* VDKQueue.mm in Sources */, 4534164229B0EA8600F544C9 /* SmallTorrentCell.mm in Sources */, diff --git a/libtransmission/version.h.in b/libtransmission/version.h.in index 2448fb281..778deb2d1 100644 --- a/libtransmission/version.h.in +++ b/libtransmission/version.h.in @@ -7,7 +7,7 @@ #define SHORT_VERSION_STRING "${TR_USER_AGENT_PREFIX}" #define LONG_VERSION_STRING "${TR_USER_AGENT_PREFIX} (${TR_VCS_REVISION})" #define VERSION_STRING_INFOPLIST ${TR_USER_AGENT_PREFIX} -#define BUILD_STRING_INFOPLIST 14714.${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_PATCH} +#define BUILD_STRING_INFOPLIST ${CFBUNDLE_VERSION} #define MAJOR_VERSION ${TR_VERSION_MAJOR} #define MINOR_VERSION ${TR_VERSION_MINOR} #define PATCH_VERSION ${TR_VERSION_PATCH} diff --git a/macosx/Base.lproj/PrefsWindow.xib b/macosx/Base.lproj/PrefsWindow.xib index 6b99fd4ef..bfbb8e676 100644 --- a/macosx/Base.lproj/PrefsWindow.xib +++ b/macosx/Base.lproj/PrefsWindow.xib @@ -91,7 +91,6 @@ - diff --git a/macosx/CMakeLists.txt b/macosx/CMakeLists.txt index 2e04f2ab1..3be8fe014 100644 --- a/macosx/CMakeLists.txt +++ b/macosx/CMakeLists.txt @@ -193,6 +193,8 @@ target_sources(${TR_NAME}-mac URLSheetWindowController.mm Utils.h Utils.mm + VersionComparator.h + VersionComparator.mm WebSeedTableView.h WebSeedTableView.mm) diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 9f7b015b9..367212ce4 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -55,6 +55,7 @@ #import "NSStringAdditions.h" #import "ExpandedPathToPathTransformer.h" #import "ExpandedPathToIconTransformer.h" +#import "VersionComparator.h" typedef NSString* ToolbarItemIdentifier NS_TYPED_EXTENSIBLE_ENUM; @@ -5428,11 +5429,6 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool [NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:kDonateURL]]; } -- (void)updaterWillRelaunchApplication:(SUUpdater*)updater -{ - self.fQuitRequested = YES; -} - - (void)rpcCallback:(tr_rpc_callback_type)type forTorrentStruct:(struct tr_torrent*)torrentStruct { @autoreleasepool @@ -5585,3 +5581,17 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool } @end + +@implementation Controller (SUUpdaterDelegate) + +- (void)updaterWillRelaunchApplication:(SUUpdater*)updater +{ + self.fQuitRequested = YES; +} + +- (nullable id)versionComparatorForUpdater:(SUUpdater*)updater +{ + return [VersionComparator new]; +} + +@end diff --git a/macosx/Info.plist.in b/macosx/Info.plist.in index ebfeeb3e7..cb3aff3b3 100644 --- a/macosx/Info.plist.in +++ b/macosx/Info.plist.in @@ -61,7 +61,7 @@ CFBundleVersion - 14714.@TR_VERSION_MAJOR@.@TR_VERSION_MINOR@.@TR_VERSION_PATCH@ + @CFBUNDLE_VERSION@ LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/macosx/PrefsController.mm b/macosx/PrefsController.mm index 5e0cee08d..635d07342 100644 --- a/macosx/PrefsController.mm +++ b/macosx/PrefsController.mm @@ -178,8 +178,6 @@ static NSString* const kWebUIURLFormat = @"http://localhost:%ld/"; [_fDefaults removeObjectForKey:@"CheckForUpdates"]; } - [self setAutoUpdateToBeta:nil]; - _fDefaultAppHelper = [[DefaultAppHelper alloc] init]; } @@ -409,17 +407,6 @@ static NSString* const kWebUIURLFormat = @"http://localhost:%ld/"; [self.window setFrame:windowRect display:YES animate:NO]; } -//for a beta release, always use the beta appcast -#if defined(TR_BETA_RELEASE) -#define SPARKLE_TAG YES -#else -#define SPARKLE_TAG [fDefaults boolForKey:@"AutoUpdateBeta"] -#endif -- (void)setAutoUpdateToBeta:(id)sender -{ - // TODO: Support beta releases (if/when necessary) -} - - (void)setPort:(id)sender { uint16_t const port = [sender intValue]; diff --git a/macosx/VersionComparator.h b/macosx/VersionComparator.h new file mode 100644 index 000000000..f31ec88ad --- /dev/null +++ b/macosx/VersionComparator.h @@ -0,0 +1,15 @@ +// This file Copyright © 2023 Transmission authors and contributors. +// It may be used under the MIT (SPDX: MIT) license. +// License text can be found in the licenses/ folder. + +#import + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface VersionComparator : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/macosx/VersionComparator.mm b/macosx/VersionComparator.mm new file mode 100644 index 000000000..1020481d2 --- /dev/null +++ b/macosx/VersionComparator.mm @@ -0,0 +1,39 @@ +// This file Copyright © 2023 Transmission authors and contributors. +// It may be used under the MIT (SPDX: MIT) license. +// License text can be found in the licenses/ folder. + +#import "VersionComparator.h" + +@implementation VersionComparator +- (NSComparisonResult)compareVersion:(NSString*)versionA toVersion:(NSString*)versionB +{ + // Transmission version format follows: + // 14714+major.minor.patch&beta + // 5.0.1-dev -> 14719.0.100 + // 5.0.1-beta.1 -> 14719.0.101 + // 5.0.1 -> 14719.0.199 + NSArray* versionBComponents = [versionB componentsSeparatedByString:@"."]; + if (versionBComponents.count > 2 && versionBComponents[2].integerValue % 100 != 99 && + ![NSUserDefaults.standardUserDefaults boolForKey:@"AutoUpdateBeta"] && + ![[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] isEqualToString:versionB]) + { + // pre-releases are ignored + return NSOrderedDescending; + } + NSArray* versionAComponents = [versionA componentsSeparatedByString:@"."]; + for (NSUInteger idx = 0; versionAComponents.count > idx || versionBComponents.count > idx; idx++) + { + NSInteger vA = versionAComponents.count > idx ? versionAComponents[idx].integerValue : 0; + NSInteger vB = versionBComponents.count > idx ? versionBComponents[idx].integerValue : 0; + if (vA < vB) + { + return NSOrderedAscending; + } + if (vA > vB) + { + return NSOrderedDescending; + } + } + return NSOrderedSame; +} +@end diff --git a/update-version-h.sh b/update-version-h.sh index 477e45509..af6ff4451 100755 --- a/update-version-h.sh +++ b/update-version-h.sh @@ -21,6 +21,9 @@ if grep -q 'set[(]TR_VERSION_DEV TRUE)' CMakeLists.txt; then else is_dev=false fi +if [ "$is_dev" != true ] && [ -z "${beta_number}" ]; then + release_number=1 +fi # derived from above: semver version string. https://semver.org/ # '4.0.0-beta.1' @@ -90,7 +93,7 @@ cat > libtransmission/version.h.new << EOF #define SHORT_VERSION_STRING "${user_agent_prefix}" #define LONG_VERSION_STRING "${user_agent_prefix} (${vcs_revision})" #define VERSION_STRING_INFOPLIST ${user_agent_prefix} -#define BUILD_STRING_INFOPLIST 14714.${major_version}.${minor_version}.${patch_version} +#define BUILD_STRING_INFOPLIST $((major_version + 14714)).${minor_version}.$((patch_version * 100 + release_number * 99 + beta_number)) #define MAJOR_VERSION ${major_version} #define MINOR_VERSION ${minor_version} #define PATCH_VERSION ${patch_version}