Skip to content

Commit

Permalink
Merge pull request #314 from wakatime/main
Browse files Browse the repository at this point in the history
Release v5.23.4
  • Loading branch information
alanhamlett authored Sep 14, 2024
2 parents e0d23b5 + 5b4e03b commit b382161
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions WakaTime/Views/MonitoredAppsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
}

private var outlineView: NSOutlineView!
private var runningApps: [AppData] = []

private lazy var apps: [AppData] = {
private func refreshRunningApps() -> [AppData] {
var apps = [AppData]()
let bundleIds = sort(MonitoredApp.allBundleIds + runningApps())
let bundleIds = sort(MonitoredApp.allBundleIds + getRunningApps())
var index = 0
for bundleId in bundleIds {
if let icon = AppInfo.getIcon(bundleId: bundleId),
Expand All @@ -28,10 +29,11 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
index += 1
}
}
runningApps = apps
return apps
}()
}

private func runningApps() -> [String] {
private func getRunningApps() -> [String] {
var ids: [String] = []
for runningApp in NSWorkspace.shared.runningApplications where runningApp.activationPolicy == .regular {
guard let id = runningApp.bundleIdentifier else { continue }
Expand Down Expand Up @@ -92,21 +94,22 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
}

func reloadData() {
refreshRunningApps()
outlineView.reloadData()
}

// MARK: NSOutlineViewDataSource

func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
apps.count
runningApps.count
}

func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
false
}

func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
apps[index]
runningApps[index]
}

// MARK: NSOutlineViewDelegate
Expand Down Expand Up @@ -145,7 +148,7 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
cellView.addSubview(action)

// Determine if the current item is the last in the list
let isLastItem = apps.last == appData
let isLastItem = runningApps.last == appData

if !isLastItem {
let divider = NSView()
Expand Down Expand Up @@ -203,12 +206,12 @@ class MonitoredAppsView: NSView, NSOutlineViewDataSource, NSOutlineViewDelegate
}

@objc func switchToggled(_ sender: NSSwitch) {
let appData = apps[sender.tag]
let appData = runningApps[sender.tag]
MonitoringManager.set(monitoringState: sender.state == .on ? .on : .off, for: appData.bundleId)
}

@objc func clickInstallPlugin(_ sender: NSButton) {
let appData = apps[sender.tag]
let appData = runningApps[sender.tag]
guard
let path = MonitoredApp.pluginAppIds[appData.bundleId],
let url = URL(string: "https://wakatime.com/\(path)")
Expand Down

0 comments on commit b382161

Please sign in to comment.