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

View File

@ -17,10 +17,15 @@
const appGreeting = "welcome to go-xkcdreader"
var a fyne.App
// RunApp performs sets up and runs the main application
func RunApp() {
a := app.New()
w := a.NewWindow(cmd.GetAppName())
// initialize the fyne application
newApp()
goxkcdreader := getApp()
w := goxkcdreader.NewWindow(cmd.GetAppName())
centered := container.New(
layout.NewHBoxLayout(),
@ -40,6 +45,15 @@ func RunApp() {
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
func makeGreeting() *widget.Label {
w := widget.NewLabel(appGreeting)

View File

@ -92,3 +92,26 @@ func TestTabs(t *testing.T) {
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()")
}
}