Skip to content

Commit 85e096f

Browse files
authored
Fix broken updater check (maxgoedjen#145)
1 parent 331e4ed commit 85e096f

File tree

5 files changed

+239
-17
lines changed

5 files changed

+239
-17
lines changed

Diff for: Brief/Updater.swift

+37-16
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,15 @@ extension Updater {
4545
func evaluate(release: Release) {
4646
guard !userIgnored(release: release) else { return }
4747
guard !release.prerelease else { return }
48-
let latestVersion = semVer(from: release.name)
49-
let currentVersion = semVer(from: Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String)
50-
for (latest, current) in zip(latestVersion, currentVersion) {
51-
if latest > current {
52-
DispatchQueue.main.async {
53-
self.update = release
54-
}
55-
return
48+
let latestVersion = SemVer(release.name)
49+
let currentVersion = SemVer(Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String)
50+
if latestVersion > currentVersion {
51+
DispatchQueue.main.async {
52+
self.update = release
5653
}
5754
}
5855
}
5956

60-
func semVer(from stringVersion: String) -> [Int] {
61-
var split = stringVersion.split(separator: ".").compactMap { Int($0) }
62-
while split.count < 3 {
63-
split.append(0)
64-
}
65-
return split
66-
}
67-
6857
func userIgnored(release: Release) -> Bool {
6958
guard !release.critical else { return false }
7059
return defaults.bool(forKey: release.name)
@@ -75,6 +64,38 @@ extension Updater {
7564
}
7665
}
7766

67+
struct SemVer {
68+
69+
let versionNumbers: [Int]
70+
71+
init(_ version: String) {
72+
// Betas have the format 1.2.3_beta1
73+
let strippedBeta = version.split(separator: "_").first!
74+
var split = strippedBeta.split(separator: ".").compactMap { Int($0) }
75+
while split.count < 3 {
76+
split.append(0)
77+
}
78+
versionNumbers = split
79+
}
80+
81+
}
82+
83+
extension SemVer: Comparable {
84+
85+
static func < (lhs: SemVer, rhs: SemVer) -> Bool {
86+
for (latest, current) in zip(lhs.versionNumbers, rhs.versionNumbers) {
87+
if latest < current {
88+
return true
89+
} else if latest > current {
90+
return false
91+
}
92+
}
93+
return false
94+
}
95+
96+
97+
}
98+
7899
extension Updater {
79100

80101
enum Constants {

Diff for: BriefTests/BriefTests.swift

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import XCTest
2+
@testable import Brief
3+
4+
class SemVerTests: XCTestCase {
5+
6+
func testEqual() {
7+
let current = SemVer("1.0.2")
8+
let old = SemVer("1.0.2")
9+
XCTAssert(!(current > old))
10+
}
11+
12+
func testPatchGreaterButMinorLess() {
13+
let current = SemVer("1.1.0")
14+
let old = SemVer("1.0.2")
15+
XCTAssert(current > old)
16+
}
17+
18+
func testMajorSameMinorGreater() {
19+
let current = SemVer("1.0.2")
20+
let new = SemVer("1.0.3")
21+
XCTAssert(current < new)
22+
}
23+
24+
func testBeta() {
25+
let current = SemVer("1.0.2")
26+
let new = SemVer("1.1.0_beta1")
27+
XCTAssert(current < new)
28+
}
29+
30+
}

Diff for: BriefTests/Info.plist

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>

Diff for: Config/Secretive.xctestplan

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"identifier" : "50617D9323FCE48E0099B055",
3737
"name" : "SecretiveTests"
3838
}
39+
},
40+
{
41+
"parallelizable" : true,
42+
"target" : {
43+
"containerPath" : "container:Secretive.xcodeproj",
44+
"identifier" : "5091D31E2519D56D0049FD9B",
45+
"name" : "BriefTests"
46+
}
3947
}
4048
],
4149
"version" : 1

Diff for: Secretive.xcodeproj/project.pbxproj

+142-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
508A5911241EF09C0069DC07 /* SecretAgentKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5099A06C240242BA0062B6F2 /* SecretAgentKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6363
508A5913241EF0B20069DC07 /* SecretKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 50617DA823FCE4AB0099B055 /* SecretKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6464
5091D2BC25183B830049FD9B /* ApplicationDirectoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5091D2BB25183B830049FD9B /* ApplicationDirectoryController.swift */; };
65+
5091D3222519D56D0049FD9B /* BriefTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5091D3212519D56D0049FD9B /* BriefTests.swift */; };
66+
5091D3242519D56D0049FD9B /* Brief.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 506772FB2426F3F400034DED /* Brief.framework */; };
6567
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */; };
6668
5099A02723FE34FA0062B6F2 /* SmartCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02623FE34FA0062B6F2 /* SmartCard.swift */; };
6769
5099A02923FE35240062B6F2 /* SmartCardStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02823FE35240062B6F2 /* SmartCardStore.swift */; };
@@ -141,6 +143,13 @@
141143
remoteGlobalIDString = 50617DA723FCE4AB0099B055;
142144
remoteInfo = SecretKit;
143145
};
146+
5091D3252519D56D0049FD9B /* PBXContainerItemProxy */ = {
147+
isa = PBXContainerItemProxy;
148+
containerPortal = 50617D7723FCE48D0099B055 /* Project object */;
149+
proxyType = 1;
150+
remoteGlobalIDString = 506772FA2426F3F400034DED;
151+
remoteInfo = Brief;
152+
};
144153
5099A076240242BA0062B6F2 /* PBXContainerItemProxy */ = {
145154
isa = PBXContainerItemProxy;
146155
containerPortal = 50617D7723FCE48D0099B055 /* Project object */;
@@ -266,6 +275,9 @@
266275
508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewAgentStatusChecker.swift; sourceTree = "<group>"; };
267276
508A590F241EEF6D0069DC07 /* Secretive.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Secretive.xctestplan; sourceTree = "<group>"; };
268277
5091D2BB25183B830049FD9B /* ApplicationDirectoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationDirectoryController.swift; sourceTree = "<group>"; };
278+
5091D31F2519D56D0049FD9B /* BriefTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BriefTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
279+
5091D3212519D56D0049FD9B /* BriefTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BriefTests.swift; sourceTree = "<group>"; };
280+
5091D3232519D56D0049FD9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
269281
5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateSecretView.swift; sourceTree = "<group>"; };
270282
5099A02623FE34FA0062B6F2 /* SmartCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCard.swift; sourceTree = "<group>"; };
271283
5099A02823FE35240062B6F2 /* SmartCardStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCardStore.swift; sourceTree = "<group>"; };
@@ -331,6 +343,14 @@
331343
);
332344
runOnlyForDeploymentPostprocessing = 0;
333345
};
346+
5091D31C2519D56D0049FD9B /* Frameworks */ = {
347+
isa = PBXFrameworksBuildPhase;
348+
buildActionMask = 2147483647;
349+
files = (
350+
5091D3242519D56D0049FD9B /* Brief.framework in Frameworks */,
351+
);
352+
runOnlyForDeploymentPostprocessing = 0;
353+
};
334354
5099A069240242BA0062B6F2 /* Frameworks */ = {
335355
isa = PBXFrameworksBuildPhase;
336356
buildActionMask = 2147483647;
@@ -379,6 +399,7 @@
379399
5099A07A240242BA0062B6F2 /* SecretAgentKitTests */,
380400
508A58AF241E144C0069DC07 /* Config */,
381401
506772FC2426F3F400034DED /* Brief */,
402+
5091D3202519D56D0049FD9B /* BriefTests */,
382403
50617D8023FCE48E0099B055 /* Products */,
383404
5099A08B240243730062B6F2 /* Frameworks */,
384405
);
@@ -395,6 +416,7 @@
395416
5099A074240242BA0062B6F2 /* SecretAgentKitTests.xctest */,
396417
50A3B78A24026B7500D209EA /* SecretAgent.app */,
397418
506772FB2426F3F400034DED /* Brief.framework */,
419+
5091D31F2519D56D0049FD9B /* BriefTests.xctest */,
398420
);
399421
name = Products;
400422
sourceTree = "<group>";
@@ -534,6 +556,15 @@
534556
path = Controllers;
535557
sourceTree = "<group>";
536558
};
559+
5091D3202519D56D0049FD9B /* BriefTests */ = {
560+
isa = PBXGroup;
561+
children = (
562+
5091D3212519D56D0049FD9B /* BriefTests.swift */,
563+
5091D3232519D56D0049FD9B /* Info.plist */,
564+
);
565+
path = BriefTests;
566+
sourceTree = "<group>";
567+
};
537568
5099A02523FE34DE0062B6F2 /* SmartCard */ = {
538569
isa = PBXGroup;
539570
children = (
@@ -737,6 +768,24 @@
737768
productReference = 506772FB2426F3F400034DED /* Brief.framework */;
738769
productType = "com.apple.product-type.framework";
739770
};
771+
5091D31E2519D56D0049FD9B /* BriefTests */ = {
772+
isa = PBXNativeTarget;
773+
buildConfigurationList = 5091D32A2519D56D0049FD9B /* Build configuration list for PBXNativeTarget "BriefTests" */;
774+
buildPhases = (
775+
5091D31B2519D56D0049FD9B /* Sources */,
776+
5091D31C2519D56D0049FD9B /* Frameworks */,
777+
5091D31D2519D56D0049FD9B /* Resources */,
778+
);
779+
buildRules = (
780+
);
781+
dependencies = (
782+
5091D3262519D56D0049FD9B /* PBXTargetDependency */,
783+
);
784+
name = BriefTests;
785+
productName = BriefTests;
786+
productReference = 5091D31F2519D56D0049FD9B /* BriefTests.xctest */;
787+
productType = "com.apple.product-type.bundle.unit-test";
788+
};
740789
5099A06B240242BA0062B6F2 /* SecretAgentKit */ = {
741790
isa = PBXNativeTarget;
742791
buildConfigurationList = 5099A083240242BA0062B6F2 /* Build configuration list for PBXNativeTarget "SecretAgentKit" */;
@@ -802,7 +851,7 @@
802851
50617D7723FCE48D0099B055 /* Project object */ = {
803852
isa = PBXProject;
804853
attributes = {
805-
LastSwiftUpdateCheck = 1140;
854+
LastSwiftUpdateCheck = 1220;
806855
LastUpgradeCheck = 1130;
807856
ORGANIZATIONNAME = "Max Goedjen";
808857
TargetAttributes = {
@@ -824,6 +873,9 @@
824873
CreatedOnToolsVersion = 11.4;
825874
LastSwiftMigration = 1140;
826875
};
876+
5091D31E2519D56D0049FD9B = {
877+
CreatedOnToolsVersion = 12.2;
878+
};
827879
5099A06B240242BA0062B6F2 = {
828880
CreatedOnToolsVersion = 11.4;
829881
LastSwiftMigration = 1140;
@@ -857,6 +909,7 @@
857909
5099A06B240242BA0062B6F2 /* SecretAgentKit */,
858910
5099A073240242BA0062B6F2 /* SecretAgentKitTests */,
859911
506772FA2426F3F400034DED /* Brief */,
912+
5091D31E2519D56D0049FD9B /* BriefTests */,
860913
);
861914
};
862915
/* End PBXProject section */
@@ -900,6 +953,13 @@
900953
);
901954
runOnlyForDeploymentPostprocessing = 0;
902955
};
956+
5091D31D2519D56D0049FD9B /* Resources */ = {
957+
isa = PBXResourcesBuildPhase;
958+
buildActionMask = 2147483647;
959+
files = (
960+
);
961+
runOnlyForDeploymentPostprocessing = 0;
962+
};
903963
5099A06A240242BA0062B6F2 /* Resources */ = {
904964
isa = PBXResourcesBuildPhase;
905965
buildActionMask = 2147483647;
@@ -1000,6 +1060,14 @@
10001060
);
10011061
runOnlyForDeploymentPostprocessing = 0;
10021062
};
1063+
5091D31B2519D56D0049FD9B /* Sources */ = {
1064+
isa = PBXSourcesBuildPhase;
1065+
buildActionMask = 2147483647;
1066+
files = (
1067+
5091D3222519D56D0049FD9B /* BriefTests.swift in Sources */,
1068+
);
1069+
runOnlyForDeploymentPostprocessing = 0;
1070+
};
10031071
5099A068240242BA0062B6F2 /* Sources */ = {
10041072
isa = PBXSourcesBuildPhase;
10051073
buildActionMask = 2147483647;
@@ -1078,6 +1146,11 @@
10781146
target = 50617DA723FCE4AB0099B055 /* SecretKit */;
10791147
targetProxy = 507CE4F12420A6B50029F750 /* PBXContainerItemProxy */;
10801148
};
1149+
5091D3262519D56D0049FD9B /* PBXTargetDependency */ = {
1150+
isa = PBXTargetDependency;
1151+
target = 506772FA2426F3F400034DED /* Brief */;
1152+
targetProxy = 5091D3252519D56D0049FD9B /* PBXContainerItemProxy */;
1153+
};
10811154
5099A077240242BA0062B6F2 /* PBXTargetDependency */ = {
10821155
isa = PBXTargetDependency;
10831156
target = 5099A06B240242BA0062B6F2 /* SecretAgentKit */;
@@ -1729,6 +1802,64 @@
17291802
};
17301803
name = Test;
17311804
};
1805+
5091D3272519D56D0049FD9B /* Debug */ = {
1806+
isa = XCBuildConfiguration;
1807+
buildSettings = {
1808+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
1809+
CODE_SIGN_STYLE = Automatic;
1810+
COMBINE_HIDPI_IMAGES = YES;
1811+
DEVELOPMENT_TEAM = Z72PRUAWF6;
1812+
INFOPLIST_FILE = BriefTests/Info.plist;
1813+
LD_RUNPATH_SEARCH_PATHS = (
1814+
"$(inherited)",
1815+
"@executable_path/../Frameworks",
1816+
"@loader_path/../Frameworks",
1817+
);
1818+
PRODUCT_BUNDLE_IDENTIFIER = com.maxgoedjen.BriefTests;
1819+
PRODUCT_NAME = "$(TARGET_NAME)";
1820+
SWIFT_VERSION = 5.0;
1821+
};
1822+
name = Debug;
1823+
};
1824+
5091D3282519D56D0049FD9B /* Test */ = {
1825+
isa = XCBuildConfiguration;
1826+
buildSettings = {
1827+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
1828+
CODE_SIGN_STYLE = Manual;
1829+
COMBINE_HIDPI_IMAGES = YES;
1830+
DEVELOPMENT_TEAM = "";
1831+
INFOPLIST_FILE = BriefTests/Info.plist;
1832+
LD_RUNPATH_SEARCH_PATHS = (
1833+
"$(inherited)",
1834+
"@executable_path/../Frameworks",
1835+
"@loader_path/../Frameworks",
1836+
);
1837+
PRODUCT_BUNDLE_IDENTIFIER = com.maxgoedjen.BriefTests;
1838+
PRODUCT_NAME = "$(TARGET_NAME)";
1839+
PROVISIONING_PROFILE_SPECIFIER = "";
1840+
SWIFT_VERSION = 5.0;
1841+
};
1842+
name = Test;
1843+
};
1844+
5091D3292519D56D0049FD9B /* Release */ = {
1845+
isa = XCBuildConfiguration;
1846+
buildSettings = {
1847+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
1848+
CODE_SIGN_STYLE = Automatic;
1849+
COMBINE_HIDPI_IMAGES = YES;
1850+
DEVELOPMENT_TEAM = Z72PRUAWF6;
1851+
INFOPLIST_FILE = BriefTests/Info.plist;
1852+
LD_RUNPATH_SEARCH_PATHS = (
1853+
"$(inherited)",
1854+
"@executable_path/../Frameworks",
1855+
"@loader_path/../Frameworks",
1856+
);
1857+
PRODUCT_BUNDLE_IDENTIFIER = com.maxgoedjen.BriefTests;
1858+
PRODUCT_NAME = "$(TARGET_NAME)";
1859+
SWIFT_VERSION = 5.0;
1860+
};
1861+
name = Release;
1862+
};
17321863
5099A084240242BA0062B6F2 /* Debug */ = {
17331864
isa = XCBuildConfiguration;
17341865
buildSettings = {
@@ -1941,6 +2072,16 @@
19412072
defaultConfigurationIsVisible = 0;
19422073
defaultConfigurationName = Release;
19432074
};
2075+
5091D32A2519D56D0049FD9B /* Build configuration list for PBXNativeTarget "BriefTests" */ = {
2076+
isa = XCConfigurationList;
2077+
buildConfigurations = (
2078+
5091D3272519D56D0049FD9B /* Debug */,
2079+
5091D3282519D56D0049FD9B /* Test */,
2080+
5091D3292519D56D0049FD9B /* Release */,
2081+
);
2082+
defaultConfigurationIsVisible = 0;
2083+
defaultConfigurationName = Release;
2084+
};
19442085
5099A083240242BA0062B6F2 /* Build configuration list for PBXNativeTarget "SecretAgentKit" */ = {
19452086
isa = XCConfigurationList;
19462087
buildConfigurations = (

0 commit comments

Comments
 (0)