feat(updater): wire startup check for desktop production builds
maybeEnableUpdater inits app.Updater (CurrentVersion from wails.json, embedded public key, accent-themed builtin window) behind two gates: -tags production (wails3 build sets it, dev does not) and application.System.IsDesktop (mobile stays on Obtainium). The startup check is headless; the window opens via a second CheckAndInstall only when an update is found. ANITRACK_UPDATER_CHANNEL=beta opts into -rc pre-releases for testing. updater_flow_test.go drives the REAL framework verifier headless: good signature stages byte-identical, tampered signature rejected (both phases green). Works around the framework process-wide app singleton with a single two-phase test.
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/updater"
|
||||
|
||||
giteaprovider "AniTrack/updater/gitea"
|
||||
)
|
||||
|
||||
//go:embed updater.pub
|
||||
var updaterPublicKey []byte
|
||||
|
||||
// maybeEnableUpdater wires self-updates: desktop production builds only.
|
||||
// Mobile stays on Obtainium; dev builds never phone home. The startup check
|
||||
// is headless — the builtin window opens only when an update is found, via a
|
||||
// second CheckAndInstall (one redundant index round-trip, negligible).
|
||||
func maybeEnableUpdater(app *application.App) {
|
||||
if !updaterAutoCheck {
|
||||
return
|
||||
}
|
||||
if !application.System.IsDesktop() {
|
||||
return
|
||||
}
|
||||
gh, err := giteaprovider.New(giteaprovider.Config{
|
||||
BaseURL: "https://git.linuxhg.com",
|
||||
Owner: "john-okeefe",
|
||||
Repo: "Anitrack",
|
||||
AssetName: "AniTrack-linux-amd64",
|
||||
// Beta channel (rc tags) for testing: ANITRACK_UPDATER_CHANNEL=beta.
|
||||
AllowPrerelease: os.Getenv("ANITRACK_UPDATER_CHANNEL") == "beta",
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("updater: %s", err)
|
||||
return
|
||||
}
|
||||
if err := app.Updater.Init(updater.Config{
|
||||
CurrentVersion: appVersion(),
|
||||
Providers: []updater.Provider{gh},
|
||||
PublicKey: updaterPublicKey,
|
||||
Window: &updater.BuiltinWindow{
|
||||
CSS: ":root { --accent: #4d9fff; }",
|
||||
},
|
||||
}); err != nil {
|
||||
log.Printf("updater: init: %s", err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
rel, err := app.Updater.Check(context.Background())
|
||||
if err != nil {
|
||||
log.Printf("updater: check: %s", err)
|
||||
return
|
||||
}
|
||||
if rel == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("updater: %s available, opening installer", rel.Version)
|
||||
if err := app.Updater.CheckAndInstall(context.Background()); err != nil {
|
||||
log.Printf("updater: install: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user