Skip to content

Commit

Permalink
Update Google Chrome version detection based on new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Feb 7, 2023
1 parent e8410c7 commit fca6f98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Pareto/Checks/GoogleChrome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import Version
// MARK: - GoogleResponse

private struct GoogleResponse: Codable {
let versions: [ChromeVersion]
let nextPageToken: String
let releases: [ChromeVersion]
}

// MARK: - Version

private struct ChromeVersion: Codable {
let name, version: String
let version: String
let fraction: Float
}

class AppGoogleChromeCheck: AppCheck {
Expand All @@ -50,11 +50,13 @@ class AppGoogleChromeCheck: AppCheck {
}

override func getLatestVersion(completion: @escaping (String) -> Void) {
let url = viaEdgeCache("https://versionhistory.googleapis.com/v1/chrome/platforms/mac/channels/stable/versions")
let url = viaEdgeCache("https://versionhistory.googleapis.com/v1/chrome/platforms/mac/channels/stable/versions/all/releases?filter=endtime=none")
os_log("Requesting %{public}s", url)
AF.request(url).responseDecodable(of: GoogleResponse.self, queue: AppCheck.queue, completionHandler: { response in
if response.error == nil {
let v = response.value?.versions.first?.version.split(separator: ".") ?? ["0", "0", "0"]
let v = response.value?.releases.filter({ v in
v.fraction >= 0.9
}).first?.version.split(separator: ".") ?? ["0", "0", "0"]
completion("\(v[0]).\(v[1]).\(v[2])")
} else {
os_log("%{public}s failed: %{public}s", self.appBundle, response.error.debugDescription)
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>5144</string>
<string>5145</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit fca6f98

Please sign in to comment.