Skip to content

Commit

Permalink
Merge branch 'develop' into fix/3810
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 24, 2023
2 parents bd8ca23 + 6fd3c28 commit 8f67578
Show file tree
Hide file tree
Showing 49 changed files with 373 additions and 194 deletions.
5 changes: 5 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func newAppWithDriver(d fyne.Driver, id string) fyne.App {
fyne.SetCurrentApp(newApp)

newApp.prefs = newApp.newDefaultPreferences()
newApp.lifecycle.(*app.Lifecycle).SetOnStoppedHookExecuted(func() {
if prefs, ok := newApp.prefs.(*preferences); ok {
prefs.forceImmediateSave()
}
})
newApp.settings = loadSettings()
store := &store{a: newApp}
store.Docs = makeStoreDocs(id, store)
Expand Down
16 changes: 15 additions & 1 deletion app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@ type preferences struct {
savedRecently bool
changedDuringSaving bool

app *fyneApp
app *fyneApp
needsSaveBeforeExit bool
}

// Declare conformity with Preferences interface
var _ fyne.Preferences = (*preferences)(nil)

// forceImmediateSave writes preferences to file immediately, ignoring the debouncing
// logic in the change listener. Does nothing if preferences are not backed with a file.
func (p *preferences) forceImmediateSave() {
if !p.needsSaveBeforeExit {
return
}
err := p.save()
if err != nil {
fyne.LogError("Failed on force saving preferences", err)
}
}

func (p *preferences) resetSavedRecently() {
go func() {
time.Sleep(time.Millisecond * 100) // writes are not always atomic. 10ms worked, 100 is safer.
Expand Down Expand Up @@ -132,6 +145,7 @@ func newPreferences(app *fyneApp) *preferences {
return p
}

p.needsSaveBeforeExit = true
p.AddChangeListener(func() {
if p != app.prefs {
return
Expand Down
19 changes: 15 additions & 4 deletions cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"strings"

version "github.com/mcuadros/go-version"
"github.com/mcuadros/go-version"
"github.com/urfave/cli/v2"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -414,14 +414,14 @@ func injectMetadataIfPossible(runner runner, srcdir string, app *appData,
return nil, err
}

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

fyneGoModVersionAtLeast2_3 := version.NewConstrainGroupFromString(">=2.3")
if fyneGoModVersionAtLeast2_3.Match(fyneGoModVersionNormalized) {
if fyneGoModVersionAtLeast2_3.Match(fyneGoModVersion) {
app.VersionAtLeast2_3 = true
}

Expand Down Expand Up @@ -485,3 +485,14 @@ func extractLdFlags(goFlags string) (string, string) {

return ldflags, newGoFlags
}

func normaliseVersion(str string) string {
if str == "master" {
return str
}

if pos := strings.Index(str, "-0.20"); pos != -1 {
str = str[:pos] + "-dev"
}
return version.Normalize(str)
}
7 changes: 7 additions & 0 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,10 @@ func Test_ExtractLdFlags(t *testing.T) {
assert.Equal(t, test.wantGoFlags, goFlags)
}
}

func Test_NormaliseVersion(t *testing.T) {
assert.Equal(t, "master", normaliseVersion("master"))
assert.Equal(t, "2.3.0.0", normaliseVersion("v2.3"))
assert.Equal(t, "2.4.0.0", normaliseVersion("v2.4.0"))
assert.Equal(t, "2.3.6.0-dev", normaliseVersion("v2.3.6-0.20230711180435-d4b95e1cb1eb"))
}
15 changes: 10 additions & 5 deletions cmd/fyne/internal/commands/package-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

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

"golang.org/x/sys/execabs"
Expand Down Expand Up @@ -58,16 +59,20 @@ func (p *Packager) packageUNIX() error {
desktop := filepath.Join(appsDir, p.Name+".desktop")
deskFile, _ := os.Create(desktop)

linuxBSD := metadata.LinuxAndBSD{}
if p.linuxAndBSDMetadata != nil {
linuxBSD = *p.linuxAndBSDMetadata
}
tplData := unixData{
Name: p.Name,
Exec: filepath.Base(p.exe),
Icon: p.Name + filepath.Ext(p.icon),
Local: local,
GenericName: p.linuxAndBSDMetadata.GenericName,
Keywords: formatDesktopFileList(p.linuxAndBSDMetadata.Keywords),
Comment: p.linuxAndBSDMetadata.Comment,
Categories: formatDesktopFileList(p.linuxAndBSDMetadata.Categories),
ExecParams: p.linuxAndBSDMetadata.ExecParams,
GenericName: linuxBSD.GenericName,
Keywords: formatDesktopFileList(linuxBSD.Keywords),
Comment: linuxBSD.Comment,
Categories: formatDesktopFileList(linuxBSD.Categories),
ExecParams: linuxBSD.ExecParams,
}
err = templates.DesktopFileUNIX.Execute(deskFile, tplData)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func Package() *cli.Command {
Name: "profile",
Usage: "iOS/macOS: name of the provisioning profile for this build",
Destination: &p.profile,
Value: "XCWildcard",
},
&cli.BoolFlag{
Name: "release",
Expand Down Expand Up @@ -136,7 +137,7 @@ type Packager struct {
tempDir string

customMetadata keyValueFlag
linuxAndBSDMetadata metadata.LinuxAndBSD
linuxAndBSDMetadata *metadata.LinuxAndBSD
}

// AddFlags adds the flags for interacting with the package command.
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/metadata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type FyneApp struct {
Details AppDetails
Development map[string]string `toml:",omitempty"`
Release map[string]string `toml:",omitempty"`
LinuxAndBSD LinuxAndBSD
LinuxAndBSD *LinuxAndBSD `toml:",omitempty"`
}

// AppDetails describes the build information, this group may be OS or arch specific
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/templates/bundled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/fyne/internal/templates/data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ user-install:
install -Dm00644 usr/{{.Local}}share/applications/$(Name).desktop $(DESTDIR)$(HOME)/.local/share/applications/$(Name).desktop
install -Dm00755 usr/{{.Local}}bin/$(Exec) $(DESTDIR)$(HOME)/.local/bin/$(Exec)
install -Dm00644 usr/{{.Local}}share/pixmaps/$(Icon) $(DESTDIR)$(HOME)/.local/share/icons/$(Icon)
sed -i -e "s,Exec=.*,Exec=$(DESTDIR)$(HOME)/.local/bin/$(Exec),g" $(DESTDIR)$(HOME)/.local/share/applications/$(Name).desktop
sed -i -e "s,Exec=$(Exec),Exec=$(DESTDIR)$(HOME)/.local/bin/$(Exec),g" $(DESTDIR)$(HOME)/.local/share/applications/$(Name).desktop

user-uninstall:
-rm $(DESTDIR)$(HOME)/.local/share/applications/$(Name).desktop
Expand Down
2 changes: 1 addition & 1 deletion cmd/hello/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Name = "Fyne Hello"
ID = "io.fyne.hello"
Version = "2.3.0"
Build = 1
Build = 2
5 changes: 5 additions & 0 deletions container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ func (r *docTabsRenderer) Layout(size fyne.Size) {
r.updateCreateTab()
r.updateTabs()
r.layout(r.docTabs, size)

// lay out buttons before updating indicator, which is relative to their position
buttons := r.scroller.Content.(*fyne.Container)
buttons.Layout.Layout(buttons.Objects, buttons.Size())
r.updateIndicator(r.docTabs.transitioning())

if r.docTabs.transitioning() {
r.docTabs.setTransitioning(false)
}
Expand Down
16 changes: 16 additions & 0 deletions container/doctabs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ func TestDocTabs_tabButtonRenderer_SetText(t *testing.T) {
renderer = cache.Renderer(button).(*tabButtonRenderer)
assert.Equal(t, "Replace", renderer.label.Text)
}

func TestDocTabs_tabButtonRenderer_Remove(t *testing.T) {
items := []*TabItem{{Text: "1", Content: widget.NewLabel("Content1")},
{Text: "2", Content: widget.NewLabel("Content2")},
{Text: "3", Content: widget.NewLabel("Content3")}}
tabs := NewDocTabs(items...)
tabs.Resize(fyne.NewSize(160, 160))
tabRenderer := cache.Renderer(tabs).(*docTabsRenderer)

tabs.SelectIndex(1)
pos := tabRenderer.indicator.Position()
tabs.RemoveIndex(0)
assert.Equal(t, 0, tabs.SelectedIndex())

assert.Less(t, tabRenderer.indicator.Position().X, pos.X)
}
2 changes: 1 addition & 1 deletion container/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ type tabButton struct {
hovered bool
icon fyne.Resource
iconPosition buttonIconPosition
importance widget.ButtonImportance
importance widget.Importance
onTapped func()
onClosed func()
text string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<container size="500x36">
<widget size="460x36" type="*widget.Scroll">
<container size="460x36">
<widget size="83x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="67x20">New longer text 1</text>
<widget size="164x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="148x20">New longer text 1</text>
</widget>
<widget pos="87,0" size="83x36" type="*container.tabButton">
<widget pos="168,0" size="83x36" type="*container.tabButton">
<text bold pos="8,8" size="67x20">New 2</text>
</widget>
</container>
Expand Down
4 changes: 2 additions & 2 deletions container/testdata/doctabs/desktop/dynamic_appended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<widget size="76x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="60x20">Test1</text>
</widget>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
<widget pos="80,0" size="76x36" type="*container.tabButton">
<text bold pos="8,8" size="60x20">Test2</text>
</widget>
</container>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="0x0" type="*container.tabButton">
<text bold color="primary" size="0x0">Test2</text>
<widget size="76x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="60x20">Test2</text>
</widget>
</container>
</widget>
Expand Down
16 changes: 8 additions & 8 deletions container/testdata/doctabs/mobile/dynamic_appended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="260x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x19">Test1</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<widget size="128x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="120x19">Test1</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
</widget>
</widget>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
<widget size="0x0" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="0x0"/>
<widget pos="132,0" size="128x36" type="*container.tabButton">
<text bold pos="4,8" size="120x19">Test2</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize"/>
</widget>
</widget>
</container>
Expand All @@ -27,7 +27,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="0,36" size="300x4"/>
<rectangle fillColor="primary" pos="0,36" size="260x4"/>
<rectangle fillColor="primary" pos="0,36" size="128x4"/>
<widget pos="0,40" size="300x110" type="*widget.Label">
<text pos="8,8" size="38x19">Text 1</text>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="0x0" type="*container.tabButton">
<text bold color="primary" size="0x0">Test2</text>
<widget size="0x0" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="0x0" themed="primary"/>
<widget size="260x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x19">Test2</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
</widget>
</widget>
</container>
Expand All @@ -21,7 +21,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="0,36" size="300x4"/>
<rectangle fillColor="primary" pos="0,36" size="72x4"/>
<rectangle fillColor="primary" pos="0,36" size="260x4"/>
<widget pos="0,40" size="300x110" type="*widget.Label">
<text pos="8,8" size="38x19">Text 2</text>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion dialog/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (d *ConfirmDialog) SetConfirmText(label string) {
// SetConfirmImportance sets the importance level of the confirm button.
//
// Since 2.4
func (d *ConfirmDialog) SetConfirmImportance(importance widget.ButtonImportance) {
func (d *ConfirmDialog) SetConfirmImportance(importance widget.Importance) {
d.confirm.Importance = importance
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module fyne.io/fyne/v2
go 1.17

require (
fyne.io/systray v1.10.1-0.20230717104455-e8b2022f921f
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a
github.com/BurntSushi/toml v1.1.0
github.com/fogleman/gg v1.3.0
github.com/fredbi/uri v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
fyne.io/systray v1.10.1-0.20230717104455-e8b2022f921f h1:Jbfqir+vcbTAAwInKWN8cZXsFHO3mDqOvw6+CZsH80w=
fyne.io/systray v1.10.1-0.20230717104455-e8b2022f921f/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a h1:6Xf9fP3/mt72NrqlQhJWhQGcNf6GoG9X96NTaXr+K6A=
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
Expand Down
14 changes: 13 additions & 1 deletion internal/app/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type Lifecycle struct {
onBackground atomic.Value // func()
onStarted atomic.Value // func()
onStopped atomic.Value // func()

onStoppedHookExecuted func()
}

// SetOnStoppedHookExecuted is an internal function that lets Fyne schedule a clean-up after
// the user-provided stopped hook. It should only be called once during an application start-up.
func (l *Lifecycle) SetOnStoppedHookExecuted(f func()) {
l.onStoppedHookExecuted = f
}

// SetOnEnteredForeground hooks into the the app becoming foreground.
Expand Down Expand Up @@ -64,10 +72,14 @@ func (l *Lifecycle) TriggerStarted() {
}
}

// TriggerStopped will call the stopped hook, if one is registered.
// TriggerStopped will call the stopped hook, if one is registered,
// and an internal stopped hook after that.
func (l *Lifecycle) TriggerStopped() {
f := l.onStopped.Load()
if ff, ok := f.(func()); ok && ff != nil {
ff()
}
if l.onStoppedHookExecuted != nil {
l.onStoppedHookExecuted()
}
}
Loading

0 comments on commit 8f67578

Please sign in to comment.