Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions KeyStats/AppStats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ struct AppStats: Codable {
case rightClicks
case sideBackClicks
case sideForwardClicks
// legacy field
case otherClicks
case scrollDistance
}

Expand All @@ -43,10 +41,6 @@ struct AppStats: Codable {
rightClicks = try container.decodeIfPresent(Int.self, forKey: .rightClicks) ?? 0
sideBackClicks = try container.decodeIfPresent(Int.self, forKey: .sideBackClicks) ?? 0
sideForwardClicks = try container.decodeIfPresent(Int.self, forKey: .sideForwardClicks) ?? 0
// Backward compatibility: old builds stored all side clicks in `otherClicks`.
if !container.contains(.sideBackClicks) && !container.contains(.sideForwardClicks) {
sideBackClicks = try container.decodeIfPresent(Int.self, forKey: .otherClicks) ?? 0
}
scrollDistance = try container.decodeIfPresent(Double.self, forKey: .scrollDistance) ?? 0
}

Expand Down
6 changes: 0 additions & 6 deletions KeyStats/StatsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ struct DailyStats: Codable {
case rightClicks
case sideBackClicks
case sideForwardClicks
// legacy field
case otherClicks
case mouseDistance
case scrollDistance
case appStats
Expand All @@ -76,10 +74,6 @@ struct DailyStats: Codable {
rightClicks = try container.decodeIfPresent(Int.self, forKey: .rightClicks) ?? 0
sideBackClicks = try container.decodeIfPresent(Int.self, forKey: .sideBackClicks) ?? 0
sideForwardClicks = try container.decodeIfPresent(Int.self, forKey: .sideForwardClicks) ?? 0
Comment on lines 75 to 76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve legacy otherClicks during stats decoding

In DailyStats.init(from:), the decoder now defaults sideBackClicks and sideForwardClicks to 0 without any fallback from the legacy otherClicks key (and AppStats.init(from:) was changed the same way in this commit). For users upgrading directly from builds that only stored otherClicks, historical side-click counts will be dropped on load and then permanently overwritten on the next save, which is an irreversible data-loss regression for existing installations.

Useful? React with 👍 / 👎.

// Backward compatibility: old builds stored all side clicks in `otherClicks`.
if !container.contains(.sideBackClicks) && !container.contains(.sideForwardClicks) {
sideBackClicks = try container.decodeIfPresent(Int.self, forKey: .otherClicks) ?? 0
}
mouseDistance = try container.decodeIfPresent(Double.self, forKey: .mouseDistance) ?? 0
scrollDistance = try container.decodeIfPresent(Double.self, forKey: .scrollDistance) ?? 0
appStats = try container.decodeIfPresent([String: AppStats].self, forKey: .appStats) ?? [:]
Expand Down