Skip to content

Commit

Permalink
Merge pull request fyne-io#4715 from andydotxyz/fix/4688
Browse files Browse the repository at this point in the history
Read from FyneApp.toml when developing with go tools
  • Loading branch information
andydotxyz authored Apr 4, 2024
2 parents 37cbaab + 0381460 commit 7e2bb66
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/app_goxjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion app/app_openurl_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/app_openurl_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
4 changes: 4 additions & 0 deletions app/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ func SetMetadata(m fyne.AppMetadata) {
}

func (a *fyneApp) Metadata() fyne.AppMetadata {
if meta.ID == "" && meta.Name == "" {
checkLocalMetadata()
}

return meta
}
64 changes: 64 additions & 0 deletions app/meta_development.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/data.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"fyne.io/fyne/v2"

"fyne.io/fyne/v2/cmd/fyne/internal/metadata"
"fyne.io/fyne/v2/internal/metadata"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions internal/build/metadata.go
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions internal/build/metadata_disabled.go
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7e2bb66

Please sign in to comment.