Skip to content

Commit

Permalink
```
Browse files Browse the repository at this point in the history
refactor: simplify window focus logic and streamline call

Remove inout parameter in SystemFrontmostWindowFocus.run,
assign frontMostIndex within the function, and streamline
call in SystemCommandRunner for better maintainability.
```
  • Loading branch information
zenangst committed Jun 5, 2024
1 parent cf3d17c commit 3555d3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import Foundation
import Windows

enum SystemFrontmostWindowFocus {
static func run(_ frontMostIndex: inout Int, kind: SystemCommand.Kind, snapshot: UserSpace.Snapshot) {
var windows = snapshot.windows.frontMostApplicationWindows
static func run(kind: SystemCommand.Kind, snapshot: UserSpace.Snapshot) {
var frontMostIndex = 0
let windows = snapshot.windows.frontMostApplicationWindows
let frontMostApplication = snapshot.frontMostApplication
let frontMostAppElement = AppAccessibilityElement(frontMostApplication.ref.processIdentifier)
if let focusedWindow = try? frontMostAppElement.focusedWindow(),
let index = windows.firstIndex(where: { $0.id == focusedWindow.id }){
windows.remove(at: index)
frontMostIndex = index
}

guard !windows.isEmpty else {
Expand Down
6 changes: 1 addition & 5 deletions App/Sources/Core/Runners/SystemCommandRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ final class SystemCommandRunner: @unchecked Sendable {
workspace: workspace
)
case .moveFocusToNextWindowFront, .moveFocusToPreviousWindowFront:
SystemFrontmostWindowFocus.run(
&frontMostIndex,
kind: command.kind,
snapshot: snapshot
)
SystemFrontmostWindowFocus.run(kind: command.kind, snapshot: snapshot)
case .minimizeAllOpenWindows:
guard let machPort else { return }
try SystemMinimizeAllWindows.run(snapshot, machPort: machPort)
Expand Down

0 comments on commit 3555d3f

Please sign in to comment.