app(xkcdreader): init,get fyne.App from anywhere
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-05-23 17:56:24 +02:00
parent 8c72ee9443
commit 5cb040b7a8
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 39 additions and 2 deletions

@ -17,10 +17,15 @@ import (
const appGreeting = "welcome to go-xkcdreader" const appGreeting = "welcome to go-xkcdreader"
var a fyne.App
// RunApp performs sets up and runs the main application // RunApp performs sets up and runs the main application
func RunApp() { func RunApp() {
a := app.New() // initialize the fyne application
w := a.NewWindow(cmd.GetAppName()) newApp()
goxkcdreader := getApp()
w := goxkcdreader.NewWindow(cmd.GetAppName())
centered := container.New( centered := container.New(
layout.NewHBoxLayout(), layout.NewHBoxLayout(),
@ -40,6 +45,15 @@ func RunApp() {
w.ShowAndRun() w.ShowAndRun()
} }
func newApp() {
a = app.New()
log.Println("Created a new fyne application")
}
func getApp() fyne.App {
return a
}
// makeGreeting creates a greeting label // makeGreeting creates a greeting label
func makeGreeting() *widget.Label { func makeGreeting() *widget.Label {
w := widget.NewLabel(appGreeting) w := widget.NewLabel(appGreeting)

@ -92,3 +92,26 @@ func TestTabs(t *testing.T) {
FAIL FAIL
*/ */
} }
func TestNewApp(t *testing.T) {
// init the application
newApp()
// get the application from var a
testA := a
if testA == nil {
t.Error("Failed to init application")
}
}
func TestGetApp(t *testing.T) {
// init the application
newApp()
got := getApp()
if got == nil {
t.Error("Failed to get application pointer using getApp()")
}
}