Skip to content

Add packaged plugin support (.swiftbar directories)#481

Merged
melonamin merged 4 commits intomainfrom
packaged-plugins
Mar 21, 2026
Merged

Add packaged plugin support (.swiftbar directories)#481
melonamin merged 4 commits intomainfrom
packaged-plugins

Conversation

@melonamin
Copy link
Copy Markdown
Member

Summary

Closes #387

Adds support for packaged plugins.swiftbar directories that bundle a main script with supporting files (libraries, assets, resources).

  • New PackagedPlugin type — full Plugin protocol conformance with thread-safe metadata, timer lifecycle, and plugin variable support
  • Directory traversalPluginManager detects .swiftbar directories as plugin bundles and skips descending into their contents
  • Working directory — packaged plugins execute with their package directory as cwd, so scripts can use relative paths (e.g., source ./lib/utils.sh)
  • Environment variableSWIFTBAR_PLUGIN_PACKAGE_PATH is set to the package directory path
  • UTI registration.swiftbar directories are registered as com.ameba.SwiftBar.PluginPackage so Finder treats them as opaque bundles

Plugin structure

my-plugin.swiftbar/
├── plugin.5m.sh      # Entry point (plugin.*)
├── lib/              # Helper scripts/libraries
└── assets/           # Data files, images, etc.

Ported from

This is a clean manual port of the packaged_plugins branch onto current main, preserving all recent features (menu diffing, folding menus, plugin variables, stdin support) that would have been lost in a rebase.

Test plan

  • Place a .swiftbar directory with a plugin.sh entry point in the plugin folder — verify it loads and displays in the menu bar
  • Verify source ./lib/helper.sh works inside a packaged plugin (confirms working directory is set correctly)
  • Verify SWIFTBAR_PLUGIN_PACKAGE_PATH is set in the plugin's environment
  • Verify regular (non-packaged) plugins still work as before
  • Verify .swiftbar directories appear as bundles in Finder
  • Verify refresh interval works via entry point naming (e.g., plugin.30s.sh)

Introduce PackagedPlugin, a new Plugin type that treats .swiftbar
directories as self-contained plugin bundles with a plugin.* entry
point and supporting files (libraries, assets, etc.).

- Add PackagedPlugin.swift with full Plugin protocol conformance
- Update PluginManager directory traversal to detect .swiftbar dirs
  and skip descending into their contents
- Add workingDirectory parameter to runScript so packaged plugins
  execute with their package directory as cwd
- Add SWIFTBAR_PLUGIN_PACKAGE_PATH environment variable
- Register com.ameba.SwiftBar.PluginPackage UTI so Finder treats
  .swiftbar directories as opaque bundles
- Fix crash in enableTimer Combine sink (self! after weak self)
- Fix disableTimer not invalidating cronTimer
- Fix error shadowing in invoke() catch block
- Make executable selection sort deterministic with alphabetical tie-breaking
- Add logging when packaged plugin init fails in loadPlugin
- Add plugin import support for .swiftbar packages via file open
- Add sync path helpers for packaged plugin identity matching
- Add tests for packaged plugin sync, merge, import, and validation
Extract `pluginNeverUpdateInterval` constant and `URL.isSwiftBarPackage`
extension to eliminate scattered magic numbers and repeated string checks.
Remove unused `fileManager` parameters from sync path helpers.
@melonamin melonamin merged commit c7acc09 into main Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin with multiple files

1 participant