feat: icons for menu items

This commit is contained in:
relikd
2026-02-07 12:17:06 +01:00
parent d514bfb610
commit 284eb1aa5c
2 changed files with 8 additions and 5 deletions

View File

@@ -36,7 +36,7 @@ Apart from that, there is no limitation on the script language.
You can use Bash, Python, Swift, Ruby, whatever. You can use Bash, Python, Swift, Ruby, whatever.
And of course, you can always write a script wrapper to call something else. And of course, you can always write a script wrapper to call something else.
=> If you can call the script with `open` (e.g., `open myscript`), it will work in the status menu too. => If you can run the script with `open` (e.g., `open myscript`), it will work in the status menu too.
### Configuration ### Configuration
@@ -46,6 +46,7 @@ There are a few ways to modify the menu structure:
#### Menu Icon #### Menu Icon
A subdirectory can have a custom icon if the folder contains an image file named `icon.X` (where `X` is one of: `svg`, `png`, `jpg`, `jpeg`, `gif`, `ico`, `icns`). A subdirectory can have a custom icon if the folder contains an image file named `icon.X` (where `X` is one of: `svg`, `png`, `jpg`, `jpeg`, `gif`, `ico`, `icns`).
For menu items, the icon file should be named exactly like the script file plus one of the icon extensions (e.g., `cmd.sh` -> `cmd.sh.png`).
#### Sort Order #### Sort Order

View File

@@ -317,18 +317,20 @@ struct Entry {
func icon() -> NSImage? { func icon() -> NSImage? {
var img: NSImage? = nil var img: NSImage? = nil
if isDir { if !hasDynParent {
let basePath = self.isDir ? self.url.appendingPathComponent("icon") : self.url
for ext in ["svg", "png", "jpg", "jpeg", "gif", "ico", "icns"] { for ext in ["svg", "png", "jpg", "jpeg", "gif", "ico", "icns"] {
let iconPath = self.url.appendingPathComponent("icon." + ext) let iconPath = basePath.appendingPathExtension(ext)
if FileManager.default.fileExists(atPath: iconPath.path) { if FileManager.default.fileExists(atPath: iconPath.path) {
img = NSImage(contentsOf: iconPath) img = NSImage(contentsOf: iconPath)
break break
} }
} }
if img == nil { if img == nil, self.isDir {
img = NSImage(named: NSImage.folderName) img = NSImage(named: NSImage.folderName)
} }
} else if action == .Dynamic || hasDynParent { }
if img == nil, action == .Dynamic || hasDynParent {
let cmd = Exec(file: self.url, env: ["ACTION": "icon", "ITEM": hasDynParent ? self.title : ""]) let cmd = Exec(file: self.url, env: ["ACTION": "icon", "ITEM": hasDynParent ? self.title : ""])
img = NSImage(data: cmd.readData()) img = NSImage(data: cmd.readData())
} }