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 6, 2020
1 parent 4b7bdcc commit eead7f4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/logic/Applications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class Applications {
}

static func removeRunningApplications(_ runningApps: [NSRunningApplication]) {
var indexesToRemove = [Int]()
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)
Expand All @@ -61,7 +61,10 @@ class Applications {
}
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)
let windowsOnTheLeftOrFocusedWindow = indexesToRemove.filter { $0 <= Windows.focusedWindowIndex }.count
if windowsOnTheLeftOrFocusedWindow > 0 {
Windows.cycleFocusedWindowIndex(-windowsOnTheLeftOrFocusedWindow)
}
App.app.refreshOpenUi()
}

Expand Down

0 comments on commit eead7f4

Please sign in to comment.