Skip to content

Commit

Permalink
Stop showing wildcard panes if exact match panes exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pennyworth committed Jul 9, 2024
1 parent ac9da7f commit 0982ea4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 7 additions & 10 deletions AlfredExtraPane/Pane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ class Pane {

Alfred.onHide { self.hide() }
Alfred.onFrameChange { self.alfredFrame = $0 }
Alfred.onItemSelect { item in
if (item.workflowuid == self.config.workflowUID)
|| (item.workflowuid == self.workflowIDtoUID[self.config.workflowUID])
|| (self.config.workflowUID == "*") {
if let url = item.quicklookurl {
return self.render(url)
}
}
self.hide()
}
}

lazy var isWildcard: Bool = { self.config.workflowUID == "*" }()

func matchesExactly(item: Alfred.SelectedItem) -> Bool {
item.workflowuid == self.config.workflowUID ||
item.workflowuid == self.workflowIDtoUID[self.config.workflowUID]
}

func render(_ url: URL) {
Expand Down
9 changes: 9 additions & 0 deletions AlfredExtraPane/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let confs: [PaneConfig] =
(try? read(contentsOf: configFile())) ?? [defaultConfig]
panes = confs.map { Pane(config: $0) }
Alfred.onItemSelect { item in
// First, render panes that have exact match with workflowUID.
// Then, if no exact match is found, render the wildcard panes.
[
self.panes.filter({ $0.matchesExactly(item: item) }),
self.panes.filter({ $0.isWildcard })
] .first(where: { !$0.isEmpty })?
.forEach({ pane in item.quicklookurl.map { pane.render($0) } })
}
}

func applicationDidFinishLaunching(_ notification: Notification) {
Expand Down

0 comments on commit 0982ea4

Please sign in to comment.