Skip to content

Commit

Permalink
Merge pull request IvanMathy#273 from nd-net/main
Browse files Browse the repository at this point in the history
Supporting SF Symbols identifiers for script icons
  • Loading branch information
IvanMathy authored Aug 10, 2021
2 parents d11dadd + 7eda443 commit 90be3eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Boop/Boop/Controllers/ScriptsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ class ScriptsTableViewController: NSViewController, NSTableViewDelegate, NSTable
return results.count
}

private func scriptIcon(identifier: String?) -> NSImage? {
guard let identifier = identifier else {
return NSImage(named: "icons8-unknown")
}
if let namedImage = NSImage(named: "icons8-\(identifier)") {
return namedImage
}
if #available(macOS 11.0, *),
let systemImage = NSImage(systemSymbolName: identifier, accessibilityDescription: nil) {
return systemImage
}
return nil
}

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

let view = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "scriptCell"), owner: self) as! ScriptTableViewCell
Expand All @@ -33,7 +47,7 @@ class ScriptsTableViewController: NSViewController, NSTableViewDelegate, NSTable
view.titleLabel.stringValue = script.name ?? "No Name 🤔"
view.subtitleLabel.stringValue = script.desc ?? "No Description 😢"

view.imageView?.image = NSImage(named: "icons8-\(script.icon ?? "unknown")")
view.imageView?.image = self.scriptIcon(identifier: script.icon)

return view

Expand Down
2 changes: 1 addition & 1 deletion Boop/Documentation/CustomScripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Each script starts with a declarative JSON document, describing the contents of

* `api` is not currently used, but is strongly recommended for potential backwards compatibility. You should set it to 1.
* `name`, `description` and `author` are exactly what you think they are.
* `icon` is a visual representation of your scripts' actions. You can see available icons in `Boop/Assets.xcassets/Icons/`. If you can't find what you like, feel free to create an issue and we'll make it work!
* `icon` is a visual representation of your scripts' actions. You can see available icons in `Boop/Assets.xcassets/Icons/`. On macOS 11 and above you can also use [SF Symbols](https://developer.apple.com/sf-symbols/). If you can't find what you like, feel free to create an issue and we'll make it work!
* `tags` are used by the fuzzy-search algorythm to filter and sort results.

An optional property, `bias`, can also be added to help Boop prioritize your scripts. A positive value will move your script higher in the results, a negative value will push it further down. The bias property is a number:
Expand Down

0 comments on commit 90be3eb

Please sign in to comment.