diff --git a/app/app_goxjs.go b/app/app_goxjs.go index e003518ea6..feddd81b18 100644 --- a/app/app_goxjs.go +++ b/app/app_goxjs.go @@ -6,7 +6,7 @@ import ( "fyne.io/fyne/v2" ) -func (app *fyneApp) SendNotification(_ *fyne.Notification) { +func (a *fyneApp) SendNotification(_ *fyne.Notification) { // TODO #2735 fyne.LogError("Sending notification is not supported yet.", nil) } diff --git a/app/app_openurl_wasm.go b/app/app_openurl_wasm.go index 75397fe655..c92224d07e 100644 --- a/app/app_openurl_wasm.go +++ b/app/app_openurl_wasm.go @@ -8,7 +8,7 @@ import ( "syscall/js" ) -func (app *fyneApp) OpenURL(url *url.URL) error { +func (a *fyneApp) OpenURL(url *url.URL) error { window := js.Global().Call("open", url.String(), "_blank", "") if window.Equal(js.Null()) { return fmt.Errorf("Unable to open a new window/tab for URL: %v.", url) diff --git a/app/app_openurl_web.go b/app/app_openurl_web.go index b03d040281..29b5a187cf 100644 --- a/app/app_openurl_web.go +++ b/app/app_openurl_web.go @@ -7,6 +7,6 @@ import ( "net/url" ) -func (app *fyneApp) OpenURL(url *url.URL) error { +func (a *fyneApp) OpenURL(url *url.URL) error { return errors.New("OpenURL is not supported with the test web driver.") } diff --git a/app/meta.go b/app/meta.go index 6a45af1515..9693033845 100644 --- a/app/meta.go +++ b/app/meta.go @@ -24,5 +24,9 @@ func SetMetadata(m fyne.AppMetadata) { } func (a *fyneApp) Metadata() fyne.AppMetadata { + if meta.ID == "" && meta.Name == "" { + checkLocalMetadata() + } + return meta } diff --git a/app/meta_development.go b/app/meta_development.go new file mode 100644 index 0000000000..998e6b94c0 --- /dev/null +++ b/app/meta_development.go @@ -0,0 +1,64 @@ +package app + +import ( + "os" + "path/filepath" + "strings" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/build" + "fyne.io/fyne/v2/internal/metadata" +) + +func checkLocalMetadata() { + if build.NoMetadata || build.Mode == fyne.BuildRelease { + return + } + + dir := getProjectPath() + file := filepath.Join(dir, "FyneApp.toml") + ref, err := os.Open(file) + if err != nil { // no worries, this is just an optional fallback + return + } + defer ref.Close() + + data, err := metadata.Load(ref) + if err != nil || data == nil { + fyne.LogError("failed to parse FyneApp.toml", err) + return + } + + meta.ID = data.Details.ID + meta.Name = data.Details.Name + meta.Version = data.Details.Version + meta.Build = data.Details.Build + + if data.Details.Icon != "" { + res, err := fyne.LoadResourceFromPath(data.Details.Icon) + if err == nil { + meta.Icon = res + } + } + + meta.Release = false + meta.Custom = data.Development +} + +func getProjectPath() string { + exe, err := os.Executable() + work, _ := os.Getwd() + + if err != nil { + fyne.LogError("failed to lookup build executable", err) + return work + } + + temp := os.TempDir() + if strings.Contains(exe, temp) { // this happens with "go run" + return work + } + + // we were called with an executable from "go build" + return filepath.Dir(exe) +} diff --git a/cmd/fyne/internal/commands/build.go b/cmd/fyne/internal/commands/build.go index 83881cf6ad..205ef2e485 100644 --- a/cmd/fyne/internal/commands/build.go +++ b/cmd/fyne/internal/commands/build.go @@ -13,8 +13,8 @@ import ( "github.com/urfave/cli/v2" "fyne.io/fyne/v2" - "fyne.io/fyne/v2/cmd/fyne/internal/metadata" "fyne.io/fyne/v2/cmd/fyne/internal/templates" + "fyne.io/fyne/v2/internal/metadata" ) // Builder generate the executables. diff --git a/cmd/fyne/internal/commands/data.go b/cmd/fyne/internal/commands/data.go index 783f7bca43..9052619664 100644 --- a/cmd/fyne/internal/commands/data.go +++ b/cmd/fyne/internal/commands/data.go @@ -1,6 +1,6 @@ package commands -import "fyne.io/fyne/v2/cmd/fyne/internal/metadata" +import "fyne.io/fyne/v2/internal/metadata" type appData struct { icon, Name string diff --git a/cmd/fyne/internal/commands/package-unix.go b/cmd/fyne/internal/commands/package-unix.go index e7384b909d..8e10d5790e 100644 --- a/cmd/fyne/internal/commands/package-unix.go +++ b/cmd/fyne/internal/commands/package-unix.go @@ -7,8 +7,8 @@ import ( "path/filepath" "strings" - "fyne.io/fyne/v2/cmd/fyne/internal/metadata" "fyne.io/fyne/v2/cmd/fyne/internal/templates" + "fyne.io/fyne/v2/internal/metadata" "golang.org/x/sys/execabs" ) diff --git a/cmd/fyne/internal/commands/package.go b/cmd/fyne/internal/commands/package.go index 7bc5e209bd..17f609e826 100644 --- a/cmd/fyne/internal/commands/package.go +++ b/cmd/fyne/internal/commands/package.go @@ -21,7 +21,7 @@ import ( "fyne.io/fyne/v2" - "fyne.io/fyne/v2/cmd/fyne/internal/metadata" + "fyne.io/fyne/v2/internal/metadata" ) const ( diff --git a/cmd/fyne/internal/commands/package_test.go b/cmd/fyne/internal/commands/package_test.go index a34348dc42..92f77513ff 100644 --- a/cmd/fyne/internal/commands/package_test.go +++ b/cmd/fyne/internal/commands/package_test.go @@ -10,7 +10,7 @@ import ( "github.com/josephspurrier/goversioninfo" "github.com/stretchr/testify/assert" - "fyne.io/fyne/v2/cmd/fyne/internal/metadata" + "fyne.io/fyne/v2/internal/metadata" ) func Test_calculateExeName(t *testing.T) { diff --git a/internal/build/metadata.go b/internal/build/metadata.go new file mode 100644 index 0000000000..fa525f9ac5 --- /dev/null +++ b/internal/build/metadata.go @@ -0,0 +1,6 @@ +//go:build !no_metadata + +package build + +// NoMetadata is false if the compiler flags have not turned off metadata support. +const NoMetadata = false diff --git a/internal/build/metadata_disabled.go b/internal/build/metadata_disabled.go new file mode 100644 index 0000000000..6217e15d2e --- /dev/null +++ b/internal/build/metadata_disabled.go @@ -0,0 +1,6 @@ +//go:build no_metadata + +package build + +// NoMetadata is true if the compiler flags have turned off metadata support. +const NoMetadata = true diff --git a/cmd/fyne/internal/metadata/data.go b/internal/metadata/data.go similarity index 100% rename from cmd/fyne/internal/metadata/data.go rename to internal/metadata/data.go diff --git a/cmd/fyne/internal/metadata/load.go b/internal/metadata/load.go similarity index 100% rename from cmd/fyne/internal/metadata/load.go rename to internal/metadata/load.go diff --git a/cmd/fyne/internal/metadata/load_test.go b/internal/metadata/load_test.go similarity index 100% rename from cmd/fyne/internal/metadata/load_test.go rename to internal/metadata/load_test.go diff --git a/cmd/fyne/internal/metadata/save.go b/internal/metadata/save.go similarity index 100% rename from cmd/fyne/internal/metadata/save.go rename to internal/metadata/save.go diff --git a/cmd/fyne/internal/metadata/save_test.go b/internal/metadata/save_test.go similarity index 100% rename from cmd/fyne/internal/metadata/save_test.go rename to internal/metadata/save_test.go diff --git a/cmd/fyne/internal/metadata/testdata/FyneApp.toml b/internal/metadata/testdata/FyneApp.toml similarity index 100% rename from cmd/fyne/internal/metadata/testdata/FyneApp.toml rename to internal/metadata/testdata/FyneApp.toml