Skip to content

Commit

Permalink
Refactor all app code into app package.
Browse files Browse the repository at this point in the history
Create flexible new app.New() which can help detect the correct scenario, such as CI tests.
Completed with a refactor of desktop to driver/efl, leaving behind the old desktop/NewApp() function
  • Loading branch information
andydotxyz committed Nov 16, 2018
1 parent 2aa98f9 commit fdbb239
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 111 deletions.
47 changes: 0 additions & 47 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,3 @@ type App interface {
// cleanly, closing all open windows.
Quit()
}

type fyneApp struct {
}

func (app *fyneApp) NewWindow(title string) Window {
return GetDriver().CreateWindow(title)
}

func (app *fyneApp) Run() {
GetDriver().Run()
}

func (app *fyneApp) Quit() {
GetDriver().Quit()
}

func (app *fyneApp) applyTheme(Settings) {
for _, window := range GetDriver().AllWindows() {
content := window.Content()

switch themed := content.(type) {
case ThemedObject:
themed.ApplyTheme()
window.Canvas().Refresh(content)
}
}
}

// NewAppWithDriver initialises a new Fyne application using the specified driver
// and returns a handle to that App.
// As this package has no default driver one must be provided.
// Helpers are available - see desktop.NewApp() and test.NewApp().
func NewAppWithDriver(d Driver) App {
newApp := &fyneApp{}
setDriver(d)

listener := make(chan Settings)
GetSettings().AddChangeListener(listener)
go func() {
for {
settings := <-listener
newApp.applyTheme(settings)
}
}()

return newApp
}
54 changes: 54 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package app

import (
"github.com/fyne-io/fyne"
)

type fyneApp struct {
driver fyne.Driver
}

func (app *fyneApp) NewWindow(title string) fyne.Window {
return app.driver.CreateWindow(title)
}

func (app *fyneApp) Run() {
app.driver.Run()
}

func (app *fyneApp) Quit() {
app.driver.Quit()
}

func (app *fyneApp) applyTheme(fyne.Settings) {
for _, window := range app.driver.AllWindows() {
content := window.Content()

switch themed := content.(type) {
case fyne.ThemedObject:
themed.ApplyTheme()
window.Canvas().Refresh(content)
}
}
}

// NewAppWithDriver initialises a new Fyne application using the specified driver
// and returns a handle to that App.
// As this package has no default driver one must be provided.
// Helpers are available - see desktop.NewApp() and test.NewApp().
func NewAppWithDriver(d fyne.Driver) fyne.App {
newApp := &fyneApp{}
newApp.driver = d
fyne.SetDriver(d)

listener := make(chan fyne.Settings)
fyne.GetSettings().AddChangeListener(listener)
go func() {
for {
settings := <-listener
newApp.applyTheme(settings)
}
}()

return newApp
}
2 changes: 1 addition & 1 deletion app_bsd.go → app/app_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// +build openbsd freebsd netbsd

package fyne
package app

import "os/exec"

Expand Down
13 changes: 13 additions & 0 deletions app/app_ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build ci

package app

import (
"github.com/fyne-io/fyne"
"github.com/fyne-io/fyne/test"
)

// New returns a new app instance using the test (headless) driver.
func New() fyne.App {
return NewAppWithDriver(test.NewTestDriver())
}
2 changes: 1 addition & 1 deletion app_darwin.go → app/app_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package fyne
package app

import "os/exec"

Expand Down
11 changes: 11 additions & 0 deletions app/app_efl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !ci,!gl

package app

import "github.com/fyne-io/fyne"
import "github.com/fyne-io/fyne/driver/efl"

// New returns a new app instance using the EFL driver.
func New() fyne.App {
return NewAppWithDriver(efl.NewEFLDriver())
}
2 changes: 1 addition & 1 deletion app_linux.go → app/app_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package fyne
package app

import "os/exec"

Expand Down
2 changes: 1 addition & 1 deletion app_other.go → app/app_other.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build ci !linux,!darwin,!windows,!freebsd,!openbsd,!netbsd

package fyne
package app

import "log"

Expand Down
15 changes: 9 additions & 6 deletions app_test.go → app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fyne
package app

import "testing"
import (
"github.com/fyne-io/fyne"
"testing"
)

func TestDummyApp(t *testing.T) {
app := NewAppWithDriver(new(dummyDriver))
Expand All @@ -11,16 +14,16 @@ func TestDummyApp(t *testing.T) {
type dummyDriver struct {
}

func (d *dummyDriver) CreateWindow(string) Window {
func (d *dummyDriver) CreateWindow(string) fyne.Window {
return nil
}

func (d *dummyDriver) AllWindows() []Window {
func (d *dummyDriver) AllWindows() []fyne.Window {
return nil
}

func (d *dummyDriver) RenderedTextSize(text string, size int, _ TextStyle) Size {
return NewSize(len(text)*size, size)
func (d *dummyDriver) RenderedTextSize(text string, size int, _ fyne.TextStyle) fyne.Size {
return fyne.NewSize(len(text)*size, size)
}

func (d *dummyDriver) Run() {
Expand Down
2 changes: 1 addition & 1 deletion app_windows.go → app/app_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package fyne
package app

import "os/exec"

Expand Down
11 changes: 0 additions & 11 deletions cmd/fyne_demo/driver-desktop.go

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/fyne_demo/driver-headless.go

This file was deleted.

9 changes: 2 additions & 7 deletions cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "errors"
import "fmt"

import "github.com/fyne-io/fyne"
import "github.com/fyne-io/fyne/app"
import "github.com/fyne-io/fyne/layout"
import "github.com/fyne-io/fyne/theme"
import "github.com/fyne-io/fyne/dialog"
Expand All @@ -31,18 +32,12 @@ func formApp(app fyne.App) {
w.Show()
}

func appButton(app fyne.App, label string, onClick func(fyne.App)) *widget.Button {
return widget.NewButton(label, func() {
onClick(app)
})
}

func confirmCallback(response bool) {
fmt.Println("Responded with", response)
}

func main() {
app := NewApp()
app := app.New()

w := app.NewWindow("Fyne Demo")
entry := widget.NewEntry()
Expand Down
13 changes: 9 additions & 4 deletions desktop/app.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// +build !ci

// Package desktop provides a full implementation of the Fyne APIs for desktop
// applications. This supports Windows, Mac OS X and Linux using the EFL (Evas)
// render pipeline.
// Package desktop is a legacy package which provided a an EFL based driver.
// This supports Windows, Mac OS X and Linux using the EFL (Evas) render pipeline.
// The replacement app package should be used by calling app.New() to create a new desktop application.
package desktop

import "log"

import "github.com/fyne-io/fyne"
import "github.com/fyne-io/fyne/app"
import "github.com/fyne-io/fyne/driver/efl"

// NewApp returns a new app instance using the desktop (EFL) driver.
func NewApp() fyne.App {
return fyne.NewAppWithDriver(NewEFLDriver())
log.Println("desktop.NewApp() is deprecated - please use app.New()")
return app.NewAppWithDriver(efl.NewEFLDriver())
}
4 changes: 2 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func GetDriver() Driver {
return driver
}

// setDriver sets the application driver.
// SetDriver sets the application driver.
// This bridges internal modularity - do not call this method directly.
func setDriver(d Driver) {
func SetDriver(d Driver) {
driver = d
}
2 changes: 1 addition & 1 deletion desktop/canvas.go → driver/efl/canvas.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

// #cgo pkg-config: eina evas ecore-evas
// #include <Eina.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/cfuncs.go → driver/efl/cfuncs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

/*
#cgo pkg-config: ecore-evas ecore-input
Expand Down
4 changes: 3 additions & 1 deletion desktop/driver.go → driver/efl/driver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// +build !ci

package desktop
// Package efl provides a full Fyne render implementation using an EFL installation.
// This supports Windows, Mac OS X and Linux using the EFL (Evas) render pipeline.
package efl

// #cgo pkg-config: ecore
// #include <Ecore.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/efl_bsd.go → driver/efl/efl_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// +build freebsd openbsd netbsd

package desktop
package efl

// #cgo pkg-config: ecore-evas
// #include <Ecore_Evas.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/efl_darwin.go → driver/efl/efl_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

func oSEngineName() string {
return "opengl_cocoa"
Expand Down
2 changes: 1 addition & 1 deletion desktop/efl_linux.go → driver/efl/efl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// +build !wayland

package desktop
package efl

// #cgo pkg-config: ecore-evas
// #include <Ecore_Evas.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/efl_other.go → driver/efl/efl_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// +build !linux,!darwin,!windows,!freebsd,!openbsd,!netbsd

package desktop
package efl

func oSEngineName() string {
return oSEngineOther
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// +build wayland

package desktop
package efl

// #cgo pkg-config: ecore-evas ecore-wl2
// #include <Ecore_Evas.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/efl_windows.go → driver/efl/efl_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

func oSEngineName() string {
return "software_gdi"
Expand Down
2 changes: 1 addition & 1 deletion desktop/loop.go → driver/efl/loop.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

// #cgo pkg-config: eina evas ecore-evas ecore-input
// #cgo CFLAGS: -DEFL_BETA_API_SUPPORT=master-compatibility-hack
Expand Down
2 changes: 1 addition & 1 deletion desktop/text.go → driver/efl/text.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

// #cgo pkg-config: ecore evas
// #include <Ecore.h>
Expand Down
2 changes: 1 addition & 1 deletion desktop/window.go → driver/efl/window.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !ci

package desktop
package efl

// #cgo pkg-config: ecore ecore-evas ecore-input evas
// #include <Ecore.h>
Expand Down
Loading

0 comments on commit fdbb239

Please sign in to comment.