From de4bce8c467296f4584ff8d2845d13fa1ea6470e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 30 Apr 2023 19:00:20 -0400 Subject: [PATCH] Plugins are now properly loaded woohoo --- examples/test/main.go | 21 +++++++++++++++++++++ nasin/application.go | 1 - nasin/plugin.go | 23 +++++++++-------------- nasin/unix.go | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 examples/test/main.go diff --git a/examples/test/main.go b/examples/test/main.go new file mode 100644 index 0000000..60b9d20 --- /dev/null +++ b/examples/test/main.go @@ -0,0 +1,21 @@ +package main + +import "git.tebibyte.media/sashakoshka/tomo" +import "git.tebibyte.media/sashakoshka/tomo/nasin" +import "git.tebibyte.media/sashakoshka/tomo/elements/testing" + +func main () { + nasin.Run(Application { }) +} + +type Application struct { } + +func (Application) Init () error { + window, err := nasin.NewWindow(tomo.Bounds(0, 0, 0, 0)) + if err != nil { return err } + window.SetTitle("Mouse Test") + window.Adopt(testing.NewMouse()) + window.OnClose(nasin.Stop) + window.Show() + return nil +} diff --git a/nasin/application.go b/nasin/application.go index 679a2a7..4af5d3a 100644 --- a/nasin/application.go +++ b/nasin/application.go @@ -6,7 +6,6 @@ import "git.tebibyte.media/sashakoshka/tomo" // Application represents a Tomo/Nasin application. type Application interface { - Name () string Init () error } diff --git a/nasin/plugin.go b/nasin/plugin.go index 3c820b6..0411845 100644 --- a/nasin/plugin.go +++ b/nasin/plugin.go @@ -8,12 +8,7 @@ import "plugin" import "path/filepath" import "git.tebibyte.media/sashakoshka/tomo" -type expectsFunc func () tomo.Version -type nameFunc func () string -type descriptionFunc func () string type backendFactory func () (tomo.Backend, error) -type themeFactory func () tomo.Theme - var factories []backendFactory var theme tomo.Theme @@ -21,7 +16,9 @@ var pluginPaths []string func loadPlugins () { for _, dir := range pluginPaths { - loadPluginsFrom(dir) + if dir != "" { + loadPluginsFrom(dir) + } } } @@ -40,9 +37,7 @@ func loadPluginsFrom (dir string) { func loadPlugin (path string) { die := func (reason string) { - println ( - "nasin: could not load plugin at ", - path + ":", reason) + println("nasin: could not load plugin at", path + ":", reason) } plugin, err := plugin.Open(path) @@ -52,11 +47,11 @@ func loadPlugin (path string) { } // check for and obtain basic plugin functions - expects, ok := extract[expectsFunc](plugin, "Expects") + expects, ok := extract[func () tomo.Version](plugin, "Expects") if !ok { die("does not implement Expects() tomo.Version"); return } - name, ok := extract[nameFunc](plugin, "Name") + name, ok := extract[func () string](plugin, "Name") if !ok { die("does not implement Name() string"); return } - _, ok = extract[descriptionFunc](plugin, "Description") + _, ok = extract[func () string](plugin, "Description") if !ok { die("does not implement Description() string"); return } // check for version compatibility @@ -71,11 +66,11 @@ func loadPlugin (path string) { } // if it's a backend plugin... - newBackend, ok := extract[backendFactory](plugin, "NewBackend") + newBackend, ok := extract[func () (tomo.Backend, error)](plugin, "NewBackend") if ok { factories = append(factories, newBackend) } // if it's a theme plugin... - newTheme, ok := extract[themeFactory](plugin, "NewTheme") + newTheme, ok := extract[func () tomo.Theme](plugin, "NewTheme") if ok { theme = newTheme() } println("nasin: loaded plugin", name()) diff --git a/nasin/unix.go b/nasin/unix.go index bb0283d..0ea10b7 100644 --- a/nasin/unix.go +++ b/nasin/unix.go @@ -14,7 +14,7 @@ func init () { "/usr/lib/nasin/plugins", "/usr/local/lib/nasin/plugins") homeDir, err := os.UserHomeDir() - if err != nil { + if err == nil { pluginPaths = append ( pluginPaths, filepath.Join(homeDir, ".local/lib/nasin/plugins"))