Skip to content

Commit

Permalink
Merge pull request #180 from wakatime/bugfix/strip-whitespace-from-us…
Browse files Browse the repository at this point in the history
…er-agent

Strip whitespace from plugin name and version
  • Loading branch information
alanhamlett authored Nov 29, 2023
2 parents b7a0879 + a8f97e5 commit cd4df92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions WakaTime/Helpers/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AppInfo {
return getAppName(bundleId: bundleId)
}

static func getAppNameForHeartbeat(_ app: NSRunningApplication) -> String? {
guard let appName = getAppName(app) else { return nil }
return appName.filter { !$0.isWhitespace }
}

static func getIcon(file path: String) -> NSImage? {
guard
FileManager.default.fileExists(atPath: path)
Expand Down
2 changes: 1 addition & 1 deletion WakaTime/WakaTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class WakaTime: HeartbeatEventHandler {
guard MonitoringManager.isAppMonitored(app) else { return }

guard
let appName = AppInfo.getAppName(app),
let appName = AppInfo.getAppNameForHeartbeat(app),
let appVersion = watcher.getAppVersion(app)
else { return }

Expand Down
3 changes: 1 addition & 2 deletions WakaTime/Watcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class Watcher: NSObject {
let bundle = Bundle(url: url)
else { return }

let version = "\(bundle.version)-\(bundle.build)"
appVersions[id] = version
appVersions[id] = "\(bundle.version)-\(bundle.build)".filter { !$0.isWhitespace }
}

public func getAppVersion(_ app: NSRunningApplication) -> String? {
Expand Down

0 comments on commit cd4df92

Please sign in to comment.