Skip to content

Commit

Permalink
fix: focus correct window after app quits (see #213)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Apr 7, 2020
1 parent bc2a38b commit 7f27cb9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/logic/Applications.swift
Expand Up @@ -49,19 +49,20 @@ class Applications {
}

static func removeRunningApplications(_ runningApps: [NSRunningApplication]) {
var windowsOnTheLeftOfFocusedWindow = 0
for runningApp in runningApps {
Applications.list.removeAll(where: { $0.runningApplication.isEqual(runningApp) })
var indexesToRemove = [Int]()
Windows.list.enumerated().forEach { (index, window) in
if window.application.runningApplication.isEqual(runningApp) {
indexesToRemove.append(index)
if window.application.runningApplication.isEqual(runningApp) && index <= Windows.focusedWindowIndex {
windowsOnTheLeftOfFocusedWindow += 1
}
}
Windows.list.removeAll(where: { $0.application.runningApplication.isEqual(runningApp) })
}
guard Windows.list.count > 0 else { App.app.hideUi(); return }
// TODO: implement of more sophisticated way to decide which thumbnail gets focused on app quit
Windows.updateFocusedWindowIndex(1)
if windowsOnTheLeftOfFocusedWindow > 0 {
Windows.cycleFocusedWindowIndex(-windowsOnTheLeftOfFocusedWindow)
}
App.app.refreshOpenUi()
}

Expand Down

0 comments on commit 7f27cb9

Please sign in to comment.