http connector first impl

This commit is contained in:
Ilia Denisov
2026-03-12 23:45:06 +02:00
committed by GitHub
parent f985370089
commit 9adadc3bbf
13 changed files with 962 additions and 41 deletions
+17
View File
@@ -0,0 +1,17 @@
package loader
import "galaxy/connector"
func (l *loader) newerVersion(version string) bool {
current := l.cli.Version()
return compareSemver(current, version) > 0
}
// downloadVersion fetches given version artifact, when newer to the current version,
// and stores at the App's local storage with a pre-defined name with semver suffix
func (l *loader) downloadVersion(v connector.VersionInfo) {
if !l.newerVersion(v.Version) {
return
}
l.conn.DownloadVersion(v.URL)
}
+41 -12
View File
@@ -6,29 +6,44 @@ import (
"fmt"
"galaxy/connector"
mc "galaxy/model/client"
"galaxy/storage"
"plugin"
"time"
"fyne.io/fyne/v2"
)
type ClientInit func(context.Context, connector.UIConnector, fyne.App, mc.Settings) (mc.Client, error)
type ClientInit func(context.Context, storage.UIStorage, connector.UIConnector, fyne.App) (mc.Client, error)
type loader struct {
conn connector.Connector
cli mc.Client
conn connector.Connector
cli mc.Client
storagePath string
}
const (
clientLibraryFile = "client"
)
var (
checkConnectionTimeout = time.Second * 5
checkVersionTimeout = time.Minute * 60
)
func NewLoader(ctx context.Context, app fyne.App, conn connector.Connector) (*loader, error) {
app.Storage().List()
settings := mc.Settings{}
cli, err := loadClientPlugin(ctx, conn, app, settings, "./client.so", "NewClient")
storagePath, err := initStorage(app)
if err != nil {
return nil, err
}
var s storage.Storage = nil
cli, err := loadClientPlugin(ctx, s, conn, app, "./client.so", "NewClient")
if err != nil {
return nil, err
}
l := &loader{
conn: conn,
cli: cli,
conn: conn,
cli: cli,
storagePath: storagePath,
}
return l, nil
}
@@ -44,7 +59,12 @@ func (l *loader) Run(ctx context.Context) error {
}
func (l *loader) backgroundLoop(ctx context.Context, final <-chan struct{}) {
t := time.NewTicker(time.Second * 5)
checkConnTimer := time.NewTimer(checkConnectionTimeout)
checkVersionTimer := time.NewTimer(checkVersionTimeout)
defer func() {
checkConnTimer.Stop()
checkVersionTimer.Stop()
}()
for {
select {
case <-ctx.Done():
@@ -52,16 +72,25 @@ func (l *loader) backgroundLoop(ctx context.Context, final <-chan struct{}) {
return
case <-final:
return
case <-t.C:
case <-checkConnTimer.C:
isGood := l.conn.CheckConnection()
l.cli.OnConnection(isGood)
checkConnTimer.Reset(checkConnectionTimeout)
case <-checkVersionTimer.C:
versions, err := l.conn.CheckVersion()
if err != nil {
// propagate error to the UI
} else if latest, ok := latestVersion(versions); ok {
l.downloadVersion(latest)
}
checkVersionTimer.Reset(checkVersionTimeout)
}
}
}
// loadClientPlugin loads a Client implementation from a shared object (.so) file at the specified path.
// It calls the constructor function by name, passing the necessary dependencies, and returns the initialized Client.
func loadClientPlugin(ctx context.Context, conn connector.UIConnector, app fyne.App, s mc.Settings, path, name string) (mc.Client, error) {
func loadClientPlugin(ctx context.Context, s storage.UIStorage, conn connector.UIConnector, app fyne.App, path, name string) (mc.Client, error) {
if path == "" {
return nil, errors.New("no plugin path given")
}
@@ -81,5 +110,5 @@ func loadClientPlugin(ctx context.Context, conn connector.UIConnector, app fyne.
return nil, fmt.Errorf("unexpected type %T; want %T", sym, initializerPtr)
}
return (*initializerPtr)(ctx, conn, app, s)
return (*initializerPtr)(ctx, s, conn, app)
}
+8
View File
@@ -0,0 +1,8 @@
package loader
func (l *loader) clientPluginVersionExists(version string) (bool, error) {
file := resolvePluginFile(version)
_ = file
// check file existence
return false, nil
}
+33
View File
@@ -0,0 +1,33 @@
package loader
import (
"galaxy/connector"
"runtime"
"slices"
"fyne.io/fyne/v2"
)
func resolvePluginFile(version string) string {
return clientLibraryFile + "-" + version
}
func compareSemver(a, b string) int {
return 0
}
func latestVersion(versions []connector.VersionInfo) (connector.VersionInfo, bool) {
os := runtime.GOOS
versions = slices.DeleteFunc(versions, func(v connector.VersionInfo) bool { return v.OS != os })
if len(versions) == 0 {
return connector.VersionInfo{}, false
}
slices.SortFunc(versions, func(a, b connector.VersionInfo) int { return compareSemver(b.Version, a.Version) })
return versions[0], true
}
// initStorage returns filesystem storage root or error if initialization fails.
func initStorage(app fyne.App) (string, error) {
_ = app.Storage() // use fyne.App's Storage
return "", nil
}