Easy selfupdate deployment for go application

by | Nov 17, 2022 | Uncategorized | 0 comments

For the past few months FyneLabs has been working on an automated tool to build and distribute Fyne application in the easiest possible way. We released this as Geoffrey, an online tool that can access your application from GitHub or GitLab and in a few clicks build it for all the platforms supported by Fyne. Now we are adding to this product our earlier work on selfupdate. This enables delivery of self updating application for Windows, MacOS, Linux and BSD with just a simple code copy and paste.

Let’s just pick a project and enable self updating in it. I have created a private fork of nomad to do this demonstration, but you can do it for any project. First, let’s enable Self Update support for this project. You either do it when adding the project to Geoffrey or by using Edit Project in the following screen:

Then select the application you just enabled Self Update on and in the project menu select Self Update.

This will now show a screen with the code you need to add to your project for enabling self update. In our case for our private nomad demonstration it looks like this:

Now just follow the instruction. Add the new file and call selfManage() just before you are ready to ShowAndRun() your main window application is created. In our case, this one line looks like this in our main.go file:

package main

import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
)

type nomad struct {
    main    fyne.Window
    store   *cityStore
    session *unsplashSession
}

func main() {
    a := app.NewWithID("com.fynelabs.nomad")
    w := a.NewWindow("Nomad")

    store := newCityStore(a.Preferences())
    session := newUnsplashSession(a.Storage(), store)
    ui := &nomad{main: w, store: store, session: session}

    var _ fyne.Theme = (*myTheme)(nil)
    a.Settings().SetTheme(&myTheme{})

    splash := makeSplash()
    w.SetContent(container.NewMax(ui.makeHome(), splash))
    w.SetPadded(false)
    w.Resize(fyne.NewSize(300, 500))
    w.SetIcon(resourceIconPng)

    go fadeSplash(splash)

    selfManage(a, w) 
    w.ShowAndRun()
}

You can push this to your github or gitlab repository (don’t forget to git add the newly added file!). Back in Geoffrey, you can now build your first version with self update enabled. Once the build is done, you can publish and share the binary.

Every time you press the Publish button, the build will be deployed and applications that have been distributed with self update support will automatically pick it up. And that’s all there is to do, to distribute applications that are kept up to date at all times.

Have fun!

 

 

 

0 Comments

Leave a Reply

%d bloggers like this: