Skip to content

Commit 501a7ea

Browse files
committed
v2.0.12 - better handling of bad cached sofa feeds
1 parent 726804a commit 501a7ea

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.12] - 2024-09-18
8+
Requires macOS 12.0 and higher.
9+
10+
### Fixed
11+
- When cached SOFA feed is malformed, attempt to retry downloading and invalidate for future Nudge runs
12+
713
## [2.0.11] - 2024-08-22
814
Requires macOS 12.0 and higher.
915

Nudge.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
"@executable_path/../Frameworks",
699699
);
700700
MACOSX_DEPLOYMENT_TARGET = 12.0;
701-
MARKETING_VERSION = 2.0.11;
701+
MARKETING_VERSION = 2.0.12;
702702
PRODUCT_BUNDLE_IDENTIFIER = com.github.macadmins.Nudge;
703703
PRODUCT_NAME = "$(TARGET_NAME)";
704704
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -729,7 +729,7 @@
729729
"@executable_path/../Frameworks",
730730
);
731731
MACOSX_DEPLOYMENT_TARGET = 12.0;
732-
MARKETING_VERSION = 2.0.11;
732+
MARKETING_VERSION = 2.0.12;
733733
PRODUCT_BUNDLE_IDENTIFIER = com.github.macadmins.Nudge;
734734
PRODUCT_NAME = "$(TARGET_NAME)";
735735
PROVISIONING_PROFILE_SPECIFIER = "";

Nudge/3rd Party Assets/sofa.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ extension MacOSDataFeed {
222222
}
223223

224224
class SOFA: NSObject, URLSessionDelegate {
225-
func URLSync(url: URL, maxRetries: Int = 3) -> (data: Data?, response: URLResponse?, error: Error?, responseCode: Int?, eTag: String?) {
225+
func URLSync(url: URL, maxRetries: Int = 3, clearCache: Bool = false) -> (data: Data?, response: URLResponse?, error: Error?, responseCode: Int?, eTag: String?) {
226226
if url.scheme == "file" {
227227
do {
228228
let data = try Data(contentsOf: url)
@@ -233,10 +233,14 @@ class SOFA: NSObject, URLSessionDelegate {
233233
}
234234

235235
let semaphore = DispatchSemaphore(value: 0)
236-
let lastEtag = Globals.nudgeDefaults.string(forKey: "LastEtag") ?? ""
236+
var lastEtag = Globals.nudgeDefaults.string(forKey: "LastEtag") ?? ""
237237
var request = URLRequest(url: url)
238238
let config = URLSessionConfiguration.default
239239
config.requestCachePolicy = .useProtocolCachePolicy
240+
if clearCache {
241+
URLCache.shared.removeAllCachedResponses()
242+
lastEtag = ""
243+
}
240244
let session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
241245

242246
request.addValue("\(Globals.bundleID)/\(VersionManager.getNudgeVersion())", forHTTPHeaderField: "User-Agent")

Nudge/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<key>CFBundlePackageType</key>
1616
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.11</string>
18+
<string>2.0.12</string>
1919
<key>CFBundleVersion</key>
20-
<string>2.0.11</string>
20+
<string>2.0.12</string>
2121
<key>LSApplicationCategoryType</key>
2222
<string>public.app-category.utilities</string>
2323
<key>LSMinimumSystemVersion</key>

Nudge/Utilities/Utils.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ struct NetworkFileManager {
12191219
}
12201220

12211221
func redownloadAndReprocessSOFA(url: URL) -> MacOSDataFeed? {
1222-
let sofaData = SOFA().URLSync(url: url)
1222+
let sofaData = SOFA().URLSync(url: url, clearCache: true)
12231223
if let responseCode = sofaData.responseCode, responseCode == 200 {
12241224
let fileManager = FileManager.default
12251225
let appSupportDirectory = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
@@ -1233,10 +1233,13 @@ struct NetworkFileManager {
12331233
try data.write(to: sofaPath)
12341234
}
12351235
let assetInfo = try MacOSDataFeed(data: data)
1236+
Globals.nudgeDefaults.set(sofaData.eTag, forKey: "LastEtag")
12361237
return assetInfo
12371238
} else {
12381239
LogManager.error("Failed to fetch sofa JSON: No data received.", logger: sofaLog)
1239-
return redownloadAndReprocessSOFA(url: url)
1240+
LogManager.error("Could not fetch SOFA feed", logger: sofaLog)
1241+
nudgePrimaryState.shouldExit = true
1242+
exit(1)
12401243
}
12411244
} catch {
12421245
LogManager.error("Failed to decode sofa JSON after redownload: \(error.localizedDescription)", logger: sofaLog)

0 commit comments

Comments
 (0)