Skip to content

Commit

Permalink
Merge branch 'release/v2.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 8, 2022
2 parents 91c74db + 70b4ad9 commit ac41869
Show file tree
Hide file tree
Showing 39 changed files with 495 additions and 185 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,28 @@
This file lists the main changes with each version of the Fyne toolkit.
More detailed release notes can be found on the [releases page](https://github.com/fyne-io/fyne/releases).

## 2.2.3 - 8 July 2022

### Fixed

* Regression: Preferences are not parsed at program start (#3125)
* Wrappable RichText in a Split container causes crash (#3003, #2961)
* meta.Version is always 1.0.0 on android & ios (#3109)


## 2.2.2 - 30 June 2022

### Fixed

* Windows missing version metadata when packaged (#3046)
* Fyne package would not build apps using old Fyne versions
* System tray icon may not be removed on app exit in Windows
* Emphasis in Markdown gives erroneous output in RichText (#2974)
* When last visible window is closed, hidden window is set visible (#3059)
* Do not close app when last window is closed but systrayMenu exists (#3092)
* Image with ImageFillOriginal not showing (#3102)


## 2.2.1 - 12 June 2022

### Fixed
Expand Down
14 changes: 8 additions & 6 deletions app/app.go
Expand Up @@ -54,7 +54,7 @@ func (a *fyneApp) UniqueID() string {
return a.Metadata().ID
}

fyne.LogError("Preferences API requires a unique ID, use app.NewWithID()", nil)
fyne.LogError("Preferences API requires a unique ID, use app.NewWithID() or the FyneApp.toml ID field", nil)
a.uniqueID = "missing-id-" + strconv.FormatInt(time.Now().Unix(), 10) // This is a fake unique - it just has to not be reused...
return a.uniqueID
}
Expand Down Expand Up @@ -94,8 +94,8 @@ func (a *fyneApp) Storage() fyne.Storage {
}

func (a *fyneApp) Preferences() fyne.Preferences {
if a.uniqueID == "" {
fyne.LogError("Preferences API requires a unique ID, use app.NewWithID()", nil)
if a.UniqueID() == "" {
fyne.LogError("Preferences API requires a unique ID, use app.NewWithID() or the FyneApp.toml ID field", nil)
}
return a.prefs
}
Expand All @@ -104,10 +104,12 @@ func (a *fyneApp) Lifecycle() fyne.Lifecycle {
return a.lifecycle
}

// New returns a new application instance with the default driver and no unique ID
// New returns a new application instance with the default driver and no unique ID (unless specified in FyneApp.toml)
func New() fyne.App {
internal.LogHint("Applications should be created with a unique ID using app.NewWithID()")
return NewWithID("")
if meta.ID == "" {
internal.LogHint("Applications should be created with a unique ID using app.NewWithID()")
}
return NewWithID(meta.ID)
}

func newAppWithDriver(d fyne.Driver, id string) fyne.App {
Expand Down
4 changes: 2 additions & 2 deletions app/app_darwin.go
@@ -1,5 +1,5 @@
//go:build !ci
// +build !ci
//go:build !ci && !js && !wasm && !test_web_driver
// +build !ci,!js,!wasm,!test_web_driver

package app

Expand Down
4 changes: 2 additions & 2 deletions app/app_desktop_darwin.go
@@ -1,5 +1,5 @@
//go:build !ci && !ios
// +build !ci,!ios
//go:build !ci && !ios && !js && !wasm && !test_web_driver
// +build !ci,!ios,!js,!wasm,!test_web_driver

package app

Expand Down
4 changes: 2 additions & 2 deletions app/app_notlegacy_darwin.go
@@ -1,5 +1,5 @@
//go:build !ci && !legacy
// +build !ci,!legacy
//go:build !ci && !legacy && !js && !wasm && !test_web_driver
// +build !ci,!legacy,!js,!wasm,!test_web_driver

package app

Expand Down
5 changes: 5 additions & 0 deletions app/app_test.go
Expand Up @@ -29,6 +29,11 @@ func TestFyneApp_UniqueID(t *testing.T) {
app := NewWithID(appID)

assert.Equal(t, appID, app.UniqueID())

meta.ID = "fakedInject"
app = New()

assert.Equal(t, meta.ID, app.UniqueID())
}

func TestFyneApp_OpenURL(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions app/meta.go
Expand Up @@ -5,9 +5,9 @@ import (
)

var meta = fyne.AppMetadata{
ID: "com.example",
Name: "Fyne App",
Version: "1.0.0",
ID: "",
Name: "",
Version: "0.0.1",
Build: 1,
}

Expand Down
2 changes: 1 addition & 1 deletion app/preferences.go
Expand Up @@ -124,7 +124,7 @@ func newPreferences(app *fyneApp) *preferences {
p.InMemoryPreferences = internal.NewInMemoryPreferences()

// don't load or watch if not setup
if app.uniqueID == "" {
if app.uniqueID == "" && app.Metadata().ID == "" {
return p
}

Expand Down
4 changes: 4 additions & 0 deletions app/preferences_test.go
Expand Up @@ -38,6 +38,10 @@ func TestPreferences_Save(t *testing.T) {
assert.Fail(t, "Failed to load, %v", err)
}
assert.JSONEq(t, string(expected), string(content))

// check it reads the saved output
p = loadPreferences("dummy")
assert.Equal(t, "value", p.String("keyString"))
}

func TestPreferences_Save_OverwriteFast(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion app/storage.go
Expand Up @@ -14,7 +14,7 @@ type store struct {
}

func (s *store) RootURI() fyne.URI {
if s.a.uniqueID == "" {
if s.a.UniqueID() == "" {
fyne.LogError("Storage API requires a unique ID, use app.NewWithID()", nil)
return storage.NewFileURI(os.TempDir())
}
Expand Down
111 changes: 87 additions & 24 deletions cmd/fyne/internal/commands/build.go
@@ -1,17 +1,19 @@
package commands

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

version "github.com/mcuadros/go-version"
"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"
version "github.com/mcuadros/go-version"
"github.com/urfave/cli/v2"
)

// Builder generate the executables.
Expand Down Expand Up @@ -128,6 +130,41 @@ func checkGoVersion(runner runner, versionConstraint *version.ConstraintGroup) e
return checkVersion(string(goVersion), versionConstraint)
}

type goModEdit struct {
Module struct {
Path string
}
Require []struct {
Path string
Version string
}
}

func getFyneGoModVersion(runner runner) (string, error) {
dependenciesOutput, err := runner.runOutput("mod", "edit", "-json")
if err != nil {
return "", err
}

var parsed goModEdit
err = json.Unmarshal(dependenciesOutput, &parsed)
if err != nil {
return "", err
}

if parsed.Module.Path == "fyne.io/fyne/v2" {
return "master", nil
}

for _, dep := range parsed.Require {
if dep.Path == "fyne.io/fyne/v2" {
return dep.Version, nil
}
}

return "", fmt.Errorf("fyne version not found")
}

func (b *Builder) build() error {
var versionConstraint *version.ConstraintGroup

Expand All @@ -136,43 +173,30 @@ func (b *Builder) build() error {
goos = targetOS()
}

fyneGoModRunner := b.runner
if b.runner == nil {
fyneGoModRunner = newCommand("go")
if goos != "gopherjs" {
b.runner = newCommand("go")
} else {
b.runner = newCommand("gopherjs")
}
}

close, err := injectMetadataIfPossible(fyneGoModRunner, b.srcdir, b.appData, b.icon, createMetadataInitFile)
if err != nil {
fyne.LogError("Failed to inject metadata init file, omitting metadata", err)
} else if close != nil {
defer close()
}

args := []string{"build"}
env := os.Environ()

if goos == "darwin" {
env = append(env, "CGO_CFLAGS=-mmacosx-version-min=10.11", "CGO_LDFLAGS=-mmacosx-version-min=10.11")
}

data, err := metadata.LoadStandard(b.srcdir)
if err == nil {
mergeMetadata(b.appData, data)
}

metadataInitFilePath := filepath.Join(b.srcdir, "fyne_metadata_init.go")
metadataInitFile, err := os.Create(metadataInitFilePath)
if err != nil {
fyne.LogError("Failed to make metadata init file, omitting metadata", err)
}
defer os.Remove(metadataInitFilePath)

err = templates.FyneMetadataInit.Execute(metadataInitFile, b.appData)
if err != nil {
fyne.LogError("Failed to generate metadata init, omitting metadata", err)
} else {
if b.icon != "" {
writeResource(b.icon, "fyneMetadataIcon", metadataInitFile)
}
}
metadataInitFile.Close()

if !isWeb(goos) {
env = append(env, "CGO_ENABLED=1") // in case someone is trying to cross-compile...

Expand Down Expand Up @@ -236,6 +260,45 @@ func (b *Builder) build() error {
return err
}

func createMetadataInitFile(srcdir string, app *appData, icon string) (func(), error) {
data, err := metadata.LoadStandard(srcdir)
if err == nil {
mergeMetadata(app, data)
}

metadataInitFilePath := filepath.Join(srcdir, "fyne_metadata_init.go")
metadataInitFile, err := os.Create(metadataInitFilePath)
if err != nil {
return func() {}, err
}
defer metadataInitFile.Close()

err = templates.FyneMetadataInit.Execute(metadataInitFile, app)
if err == nil {
if icon != "" {
writeResource(icon, "fyneMetadataIcon", metadataInitFile)
}
}

return func() { os.Remove(metadataInitFilePath) }, err
}

func injectMetadataIfPossible(runner runner, srcdir string, app *appData, icon string,
createMetadataInitFile func(srcdir string, app *appData, icon string) (func(), error)) (func(), error) {
fyneGoModVersion, err := getFyneGoModVersion(runner)
if err != nil {
return nil, err
}

fyneGoModVersionNormalized := version.Normalize(fyneGoModVersion)
fyneGoModVersionConstraint := version.NewConstrainGroupFromString(">=2.2")
if fyneGoModVersion != "master" && !fyneGoModVersionConstraint.Match(fyneGoModVersionNormalized) {
return nil, nil
}

return createMetadataInitFile(srcdir, app, icon)
}

func targetOS() string {
osEnv, ok := os.LookupEnv("GOOS")
if ok {
Expand Down
57 changes: 57 additions & 0 deletions cmd/fyne/internal/commands/build_test.go
Expand Up @@ -101,6 +101,12 @@ func Test_CheckVersionTableTests(t *testing.T) {

func Test_BuildWasmVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{
ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"}"),
},
},
{
expectedValue: expectedValue{args: []string{"version"}},
mockReturn: mockReturn{ret: []byte("go version go1.17.6 windows/amd64")},
Expand All @@ -125,6 +131,12 @@ func Test_BuildWasmVersion(t *testing.T) {

func Test_BuildWasmReleaseVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{
ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"}"),
},
},
{
expectedValue: expectedValue{args: []string{"version"}},
mockReturn: mockReturn{
Expand Down Expand Up @@ -153,6 +165,12 @@ func Test_BuildWasmReleaseVersion(t *testing.T) {

func Test_BuildGopherJSReleaseVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{
ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"}"),
},
},
{
expectedValue: expectedValue{
args: []string{"version"},
Expand Down Expand Up @@ -184,6 +202,12 @@ func Test_BuildGopherJSReleaseVersion(t *testing.T) {

func Test_BuildWasmOldVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{
ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"}"),
},
},
{
expectedValue: expectedValue{args: []string{"version"}},
mockReturn: mockReturn{ret: []byte("go version go1.16.0 windows/amd64")},
Expand All @@ -196,3 +220,36 @@ func Test_BuildWasmOldVersion(t *testing.T) {
assert.NotNil(t, err)
wasmBuildTest.verifyExpectation()
}

type jsonTest struct {
expected bool
json []byte
}

func Test_FyneGoMod(t *testing.T) {
jsonTests := []jsonTest{
{false, []byte(`{"Module": {"Path": "github.com/fyne-io/calculator"},"Go": "1.14", "Require": [ { "Path": "fyne.io/fyne/v2","Version": "v2.1.4"} ] }`)},
{true, []byte(`{ "Module": {"Path": "fyne.io/fyne/v2"},"Require": [{ "Path": "test","Version": "v2.1.4"} ] }`)},
{true, []byte(`{"Module": {"Path": "github.com/fyne-io/calculator"},"Go": "1.14", "Require": [ { "Path": "fyne.io/fyne/v2","Version": "v2.2.0"} ] }`)},
}

for _, j := range jsonTests {
expected := []mockRunner{
{
expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}},
mockReturn: mockReturn{ret: j.json},
},
}

called := false

fyneGoModTest := &testCommandRuns{runs: expected, t: t}
injectMetadataIfPossible(fyneGoModTest, "myTest", &appData{}, "",
func(string, *appData, string) (func(), error) {
called = true
return func() {}, nil
})

assert.Equal(t, j.expected, called)
}
}

0 comments on commit ac41869

Please sign in to comment.