fix: resolve plugin path relative to binary location + copy plugins in build

- main.go: use filepath.Dir(os.Args[0]) instead of ./plugins for discovery
- api/app.go: same fix for ReloadPlugins
- build.sh: copy plugins/ to build/bin/plugins/ after wails build
- Fixes: plugin not found when binary launched from different CWD
This commit is contained in:
mirivlad 2026-06-16 21:00:44 +08:00
parent fa52a0bfc3
commit 70d4c75d7e
3 changed files with 17 additions and 2 deletions

View File

@ -101,9 +101,13 @@ func expandPath(path string) string {
// ReloadPlugins re-discovers plugins from disk and returns a summary. // ReloadPlugins re-discovers plugins from disk and returns a summary.
func (a *App) ReloadPlugins() (int, string) { func (a *App) ReloadPlugins() (int, string) {
// Resolve plugin directories relative to the binary location
binDir := filepath.Dir(os.Args[0])
pluginDir := filepath.Join(binDir, "plugins")
discoveryDirs := []string{ discoveryDirs := []string{
"~/.config/verstak/plugins", "~/.config/verstak/plugins",
"./plugins", pluginDir,
} }
// Expand tilde in all paths // Expand tilde in all paths

View File

@ -71,9 +71,14 @@ func main() {
log.Printf("[main] registered vault capability") log.Printf("[main] registered vault capability")
// ─── Plugin Discovery ─────────────────────────────────── // ─── Plugin Discovery ───────────────────────────────────
// Resolve plugin directories relative to the binary location,
// not CWD (Wails may launch from a different directory).
binDir := filepath.Dir(os.Args[0])
pluginDir := filepath.Join(binDir, "plugins")
discoveryDirs := []string{ discoveryDirs := []string{
"~/.config/verstak/plugins", "~/.config/verstak/plugins",
"./plugins", pluginDir,
} }
// Expand tilde in all paths // Expand tilde in all paths

View File

@ -127,6 +127,12 @@ if [ -n "$WAILS" ]; then
echo " 🔨 wails build..." echo " 🔨 wails build..."
(cd "$ROOT" && "$WAILS" build -clean $WAILS_TAGS) (cd "$ROOT" && "$WAILS" build -clean $WAILS_TAGS)
report "wails build" $? report "wails build" $?
# Copy plugins/ to build/bin/ so the binary can find them at runtime
if [ -d "$ROOT/plugins" ]; then
mkdir -p "$ROOT/build/bin/plugins"
cp -r "$ROOT/plugins/"* "$ROOT/build/bin/plugins/" 2>/dev/null || true
echo " 📦 plugins copied to build/bin/plugins/"
fi
# Show where the binary ended up # Show where the binary ended up
if [ -f "$ROOT/build/bin/$WAILS_BINARY" ]; then if [ -f "$ROOT/build/bin/$WAILS_BINARY" ]; then
echo " 📦 binary: $ROOT/build/bin/$WAILS_BINARY" echo " 📦 binary: $ROOT/build/bin/$WAILS_BINARY"