Skip to content

Commit

Permalink
fix: rare crash when alt-tab is triggered when the dock isn't running
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 25, 2020
1 parent 1452602 commit b13fabb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/logic/Applications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ class Applications {

static func refreshBadges() {
retryAxCallUntilTimeout {
let axDock = AXUIElementCreateApplication(Applications.list.first { $0.runningApplication.bundleIdentifier == "com.apple.dock" }!.runningApplication.processIdentifier)
let axList = try axDock.children()!.first { try $0.role() == "AXList" }!
let axAppDockItem = try axList.children()!.filter { try $0.subrole() == "AXApplicationDockItem" && ($0.appIsRunning() ?? false) }
try Applications.list.forEach { app in
if app.runningApplication.activationPolicy == .regular,
let bundleId = app.runningApplication.bundleIdentifier,
let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleId) {
app.dockLabel = try axAppDockItem.first { try $0.attribute(kAXURLAttribute, URL.self) == url }?.attribute(kAXStatusLabelAttribute, String.self)
if let dockPid = (Applications.list.first { $0.runningApplication.bundleIdentifier == "com.apple.dock" }?.runningApplication.processIdentifier),
let axList = (try AXUIElementCreateApplication(dockPid).children()?.first { try $0.role() == "AXList" }),
let axAppDockItem = (try axList.children()?.filter { try $0.subrole() == "AXApplicationDockItem" && ($0.appIsRunning() ?? false) }) {
try Applications.list.forEach { app in
if app.runningApplication.activationPolicy == .regular,
let bundleId = app.runningApplication.bundleIdentifier,
let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleId) {
app.dockLabel = try axAppDockItem.first { try $0.attribute(kAXURLAttribute, URL.self) == url }?.attribute(kAXStatusLabelAttribute, String.self)
}
}
}
}
Expand Down

0 comments on commit b13fabb

Please sign in to comment.