Skip to content

Commit

Permalink
Merge pull request #173 from wakatime/main
Browse files Browse the repository at this point in the history
Release v3.7.0
  • Loading branch information
alanhamlett authored Nov 2, 2023
2 parents b09802a + 92c6fc9 commit bcf48da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions WakaTime/Helpers/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Dependencies {
let (data, response) = try await URLSession.shared.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else { return nil }

let now = Int(NSDate().timeIntervalSince1970)
ConfigFile.setSetting(section: "internal", key: "cli_version_last_accessed", val: String(now), internalConfig: true)

if httpResponse.statusCode == 304 {
// Current version is still the latest version available
return currentVersion
Expand Down Expand Up @@ -72,6 +75,17 @@ class Dependencies {
} else {
version = nil
}

let accessed = ConfigFile.getSetting(section: "internal", key: "cli_version_last_accessed", internalConfig: true)
if let accessed, let accessed = Int(accessed) {
let now = Int(NSDate().timeIntervalSince1970)
let fourHours = 4 * 3600
if accessed + fourHours > now {
NSLog("Skip checking for wakatime-cli updates because recently checked \(now - accessed) seconds ago")
return true
}
}

let remoteVersion = try? await getLatestVersion()
guard let remoteVersion else {
// Could not retrieve remote version
Expand Down

0 comments on commit bcf48da

Please sign in to comment.