Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v5.23.4 #314

Merged
merged 2 commits into from
Sep 14, 2024
Merged
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
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
Loading