-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced SystemCommand with Minimize All Functionality
Added a new functionality to the SystemCommand enumeration that allows users to minimize all open windows. This feature is designed to quickly declutter the desktop and provide users with a more organized workspace. As a consequence, the SystemMinimizeAllWindows runner has been created to handle the execution of this command. To support this new command, corresponding icons and display values have been included to facilitate user interaction and enhance overall usability. Additionally, integrated this functionality into the SystemCommandRunner for seamless operation within the application.
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
App/Sources/Core/Runners/System/SystemMinimizeAllWindows.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Apps | ||
import Foundation | ||
import Carbon | ||
import Cocoa | ||
import MachPort | ||
|
||
enum SystemMinimizeAllWindows { | ||
static func run(_ snapshot: UserSpace.Snapshot, | ||
machPort: MachPortEventController) throws { | ||
Task { | ||
let menuBar = MenuBarCommandRunner() | ||
var uniqueRunningApplications: [Application] = [] | ||
for window in snapshot.windows.visibleWindowsInSpace { | ||
guard let runningApplication = NSWorkspace.shared.runningApplications | ||
.first(where: { $0.localizedName == window.ownerName }), | ||
let bundleIdentifier = runningApplication.bundleIdentifier else { continue } | ||
|
||
if !uniqueRunningApplications.contains(where: { $0.bundleIdentifier == bundleIdentifier }), | ||
let app = ApplicationStore.shared.application(for: bundleIdentifier) { | ||
uniqueRunningApplications.append(app) | ||
let configuration = NSWorkspace.OpenConfiguration() | ||
configuration.activates = true | ||
|
||
let url = URL(fileURLWithPath: app.path) | ||
try Task.checkCancellation() | ||
try await NSWorkspace.shared.openApplication(at: url, configuration: configuration) | ||
try await menuBar.execute(.init(tokens: [ | ||
.menuItem(name: "Window"), .menuItem(name: "Minimize All") | ||
])) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters