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
This commit is contained in:
Cœur 2024-03-18 05:23:39 +08:00 committed by GitHub
parent 0749300090
commit c63c66c737
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 96 additions and 22 deletions

View File

@ -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)

View File

@ -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 = "<group>"; };
C841A28029197724009F18E8 /* NSKeyedUnarchiverAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSKeyedUnarchiverAdditions.mm; sourceTree = "<group>"; };
C843FC8329C51B9400491854 /* utils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = utils.mm; sourceTree = "<group>"; };
C843FC8529C8B40800491854 /* VersionComparator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VersionComparator.h; sourceTree = "<group>"; };
C843FC8629C8B40800491854 /* VersionComparator.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VersionComparator.mm; sourceTree = "<group>"; };
C86BCD9828228A9600F45599 /* SparkleProxy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SparkleProxy.mm; sourceTree = "<group>"; };
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 */,

View File

@ -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}

View File

@ -91,7 +91,6 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="setAutoUpdateToBeta:" target="-2" id="1900"/>
<binding destination="365" name="value" keyPath="values.AutoUpdateBeta" id="1897"/>
</connections>
</button>

View File

@ -193,6 +193,8 @@ target_sources(${TR_NAME}-mac
URLSheetWindowController.mm
Utils.h
Utils.mm
VersionComparator.h
VersionComparator.mm
WebSeedTableView.h
WebSeedTableView.mm)

View File

@ -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<SUVersionComparison>)versionComparatorForUpdater:(SUUpdater*)updater
{
return [VersionComparator new];
}
@end

View File

@ -61,7 +61,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>14714.@TR_VERSION_MAJOR@.@TR_VERSION_MINOR@.@TR_VERSION_PATCH@</string>
<string>@CFBUNDLE_VERSION@</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>

View File

@ -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];

View File

@ -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 <Foundation/Foundation.h>
#import <Sparkle/SUVersionComparisonProtocol.h>
NS_ASSUME_NONNULL_BEGIN
@interface VersionComparator : NSObject<SUVersionComparison>
@end
NS_ASSUME_NONNULL_END

View File

@ -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<NSString*>* 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<NSString*>* 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

View File

@ -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}