Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting SF Symbols identifiers for script icons #273

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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