From 58795b66b23760b6c83c28c0ef72563790b17486 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Thu, 4 Jun 2026 03:28:32 +0800 Subject: [PATCH] fix: keep default templates and plugins folder working --- cmd/verstak-gui/bindings_settings.go | 20 +++++++++++++++++++ cmd/verstak-gui/settings_test.go | 26 +++++++++++++++++++++++++ frontend/src/lib/SettingsPlugins.svelte | 2 +- internal/core/config/appconfig.go | 2 +- internal/core/config/appconfig_test.go | 26 +++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 cmd/verstak-gui/settings_test.go create mode 100644 internal/core/config/appconfig_test.go diff --git a/cmd/verstak-gui/bindings_settings.go b/cmd/verstak-gui/bindings_settings.go index 74cf84b..3e691ee 100644 --- a/cmd/verstak-gui/bindings_settings.go +++ b/cmd/verstak-gui/bindings_settings.go @@ -231,6 +231,26 @@ func (a *App) OpenVaultFolder() error { return cmd.Run() } +func ensurePluginsFolder(vaultPath string) (string, error) { + path := filepath.Join(vaultPath, ".verstak", "plugins") + if err := os.MkdirAll(path, 0o750); err != nil { + return "", err + } + return path, nil +} + +func (a *App) OpenPluginsFolder() error { + if !a.IsReady() { + return fmt.Errorf("vault not open") + } + target, err := ensurePluginsFolder(a.vault) + if err != nil { + return err + } + cmd := exec.Command("xdg-open", target) + return cmd.Run() +} + func (a *App) Search(query string) ([]SearchResultDTO, error) { if err := a.requireVault(); err != nil { return nil, err diff --git a/cmd/verstak-gui/settings_test.go b/cmd/verstak-gui/settings_test.go new file mode 100644 index 0000000..861149a --- /dev/null +++ b/cmd/verstak-gui/settings_test.go @@ -0,0 +1,26 @@ +package main + +import ( + "os" + "path/filepath" + "testing" +) + +func TestEnsurePluginsFolder(t *testing.T) { + vault := t.TempDir() + + path, err := ensurePluginsFolder(vault) + if err != nil { + t.Fatalf("ensurePluginsFolder: %v", err) + } + + want := filepath.Join(vault, ".verstak", "plugins") + if path != want { + t.Fatalf("plugins path = %q, want %q", path, want) + } + if info, err := os.Stat(path); err != nil { + t.Fatalf("stat plugins dir: %v", err) + } else if !info.IsDir() { + t.Fatalf("plugins path is not a directory: %s", path) + } +} diff --git a/frontend/src/lib/SettingsPlugins.svelte b/frontend/src/lib/SettingsPlugins.svelte index ad30972..1014529 100644 --- a/frontend/src/lib/SettingsPlugins.svelte +++ b/frontend/src/lib/SettingsPlugins.svelte @@ -12,7 +12,7 @@ } async function openPluginsDir() { - try { await wailsCall('OpenFolder', '') } catch(e) {} + try { await wailsCall('OpenPluginsFolder') } catch(e) {} } diff --git a/internal/core/config/appconfig.go b/internal/core/config/appconfig.go index 76649db..d25e202 100644 --- a/internal/core/config/appconfig.go +++ b/internal/core/config/appconfig.go @@ -55,7 +55,7 @@ func DefaultAppConfig() *AppConfig { Version: AppConfigVersion, Theme: "system", Language: "ru", - EnabledTemplates: []string{"folder", "project", "client", "document", "recipe"}, + EnabledTemplates: []string{"folder.default", "project.default", "client.default", "document.default", "recipe.default"}, EnabledPlugins: []string{}, } } diff --git a/internal/core/config/appconfig_test.go b/internal/core/config/appconfig_test.go new file mode 100644 index 0000000..e3b8401 --- /dev/null +++ b/internal/core/config/appconfig_test.go @@ -0,0 +1,26 @@ +package config_test + +import ( + "testing" + + "verstak/internal/core/config" + "verstak/internal/core/templates" +) + +func TestDefaultAppConfigEnabledTemplatesMatchSystemTemplateIDs(t *testing.T) { + cfg := config.DefaultAppConfig() + if len(cfg.EnabledTemplates) == 0 { + t.Fatal("default enabled templates is empty") + } + + reg := templates.NewRegistry() + if err := reg.LoadSystem(); err != nil { + t.Fatalf("LoadSystem: %v", err) + } + + for _, id := range cfg.EnabledTemplates { + if _, ok := reg.Get(id); !ok { + t.Fatalf("default enabled template %q does not match any system template ID", id) + } + } +}