Skip to content

Commit

Permalink
Implement list-apps command
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Nov 19, 2023
1 parent 57e7a08 commit 0a7c6ec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
BD6301B2CFC16FDE4223ACB8 /* MacApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB782C527ABE0CF31740EB /* MacApp.swift */; };
BF16873111EEDE60A8AACD6B /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F068BCC50ED846DCBFDE57 /* Workspace.swift */; };
C0A88261ECF505FC5648FC0A /* OptionalEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EDFD4A9F45182CA6E0BD7B /* OptionalEx.swift */; };
C68DE433A62D8698545AE405 /* ListAppsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A74FD8E971E46F2049E2AA6 /* ListAppsCommand.swift */; };
C76E421FB0D0F0EB1C93A06C /* Monitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739F4FE1DB101DF4E508F3FE /* Monitor.swift */; };
C830FD347D7F9C06CF53103F /* Socket in Frameworks */ = {isa = PBXBuildFile; productRef = 998F8F4D88E65F73B0B2894D /* Socket */; };
D12277DFEAAAC7AE19D0B629 /* LazySequenceProtocolEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D36D0F8EEB30A7BABC42343 /* LazySequenceProtocolEx.swift */; };
Expand Down Expand Up @@ -132,6 +133,7 @@
43DD32B1711B8EFCC834B68E /* WorkspaceCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceCommand.swift; sourceTree = "<group>"; };
458AD0CD907B56A99DA821C4 /* AeroSpace-cli */ = {isa = PBXFileReference; includeInIndex = 0; path = "AeroSpace-cli"; sourceTree = BUILT_PRODUCTS_DIR; };
49B99DD05BF656B8351E12CE /* gitHashGenerated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = gitHashGenerated.swift; sourceTree = "<group>"; };
4A74FD8E971E46F2049E2AA6 /* ListAppsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListAppsCommand.swift; sourceTree = "<group>"; };
4B0CD3C2A0E86CDB9DF312AB /* ModeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModeCommand.swift; sourceTree = "<group>"; };
51CC651BEB897CB7A555D230 /* MoveWorkspaceToMonitorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveWorkspaceToMonitorCommand.swift; sourceTree = "<group>"; };
51CE37C1B8D858C81A396F40 /* CollectionEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionEx.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -366,6 +368,7 @@
88F5F202E4D39BE05D077944 /* cli */ = {
isa = PBXGroup;
children = (
4A74FD8E971E46F2049E2AA6 /* ListAppsCommand.swift */,
F187A6469837B279A528F0AF /* VersionCommand.swift */,
);
path = cli;
Expand Down Expand Up @@ -614,6 +617,7 @@
5BC4AA58A69956C8B6379E47 /* JoinWithCommand.swift in Sources */,
5DA2DA21600E8B5BCA3DCFC0 /* LayoutCommand.swift in Sources */,
D12277DFEAAAC7AE19D0B629 /* LazySequenceProtocolEx.swift in Sources */,
C68DE433A62D8698545AE405 /* ListAppsCommand.swift in Sources */,
BD6301B2CFC16FDE4223ACB8 /* MacApp.swift in Sources */,
EECC59858691B99A95542D72 /* MacWindow.swift in Sources */,
6E4E235FDA41307B19F16182 /* ModeCommand.swift in Sources */,
Expand Down
26 changes: 26 additions & 0 deletions docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,34 @@
In addition to [regular commands](./commands.md), the CLI provides commands listed in this file

**Table of contents**
- [list-apps](#list-apps)
- [version](#version)

## list-apps

```
list-apps
```

- Available since: 0.6.0-Beta

Prints the list of ordinary applications that appears in the Dock and may have a user interface.

Output format is the table with the following colums:
- Process ID
- Application ID
- Application name

Output example:
```
486 com.apple.finder Finder
17966 org.alacritty Alacritty
24780 com.jetbrains.AppCode AppCode
32541 com.apple.systempreferences System Settings
```

The command is useful to inspect list of applications to compose filter for [`on-window-detected`](./guide.md#on-window-detected-callback)

## version

```
Expand Down
2 changes: 2 additions & 0 deletions src/command/parseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func parseQueryCommand(_ raw: String) -> Parsed<QueryCommand> {
return .failure("Single quotation mark is reserved for future use")
} else if raw == "version" || raw == "--version" || raw == "-v" {
return .success(VersionCommand())
} else if raw == "list-apps" {
return .success(ListAppsCommand())
} else if raw == "" {
return .failure("Can't parse empty string query command")
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/AeroApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AeroApp: Hashable {
hasher.combine(id)
}

var title: String? { nil }
var name: String? { nil }
var focusedWindow: Window? { error("Not implemented") }
var windows: [Window] { error("Not implemented") }
}
4 changes: 2 additions & 2 deletions src/tree/MacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class MacApp: AeroApp {
}

private func garbageCollect() {
debug("garbageCollectApp: terminated \(self.title ?? "")")
debug("garbageCollectApp: terminated \(self.name ?? "")")
MacApp.allAppsMap.removeValue(forKey: nsApp.processIdentifier)
for obs in axObservers {
AXObserverRemoveNotification(obs.obs, obs.ax, obs.notif)
Expand All @@ -48,7 +48,7 @@ final class MacApp: AeroApp {
}
}

override var title: String? { nsApp.localizedName }
override var name: String? { nsApp.localizedName }

private func observe(_ handler: AXObserverCallback, _ notifKey: String) -> Bool {
guard let observer = AXObserver.observe(nsApp.processIdentifier, notifKey, axApp, handler, data: nil) else { return false }
Expand Down
2 changes: 1 addition & 1 deletion src/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class MacWindow: Window, CustomStringConvertible {
}

func garbageCollect() {
debug("garbageCollectWindow of \(app.title ?? "NO TITLE")")
debug("garbageCollectWindow of \(app.name ?? "NO TITLE")")
MacWindow.allWindowsMap.removeValue(forKey: windowId)
unbindFromParent()
for obs in axObservers {
Expand Down

0 comments on commit 0a7c6ec

Please sign in to comment.