From 421533db2fe62f59b302a124df20cfb11689163e Mon Sep 17 00:00:00 2001 From: Adam Bouqdib Date: Tue, 5 Dec 2023 22:02:30 +0000 Subject: [PATCH] chore: examples --- README.md | 21 +++++++++--------- example/main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b3e8f5d..acc75a6 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,22 @@ # WinSparkle Go Bindings -[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/abemedia/go-winsparkle?tab=doc) +[![Go Reference](https://pkg.go.dev/badge/github.com/abemedia/go-winsparkle.svg)](https://pkg.go.dev/github.com/abemedia/go-winsparkle) -This package provides go bindings for -[WinSparkle](https://github.com/vslavik/winsparkle) created by Vaclav Slavik. +This package provides go bindings for [WinSparkle](https://github.com/vslavik/winsparkle) created by +Vaclav Slavik. -WinSparkle is a plug-and-forget software update library for Windows applications. -It is heavily inspired by the Sparkle framework for OS X written by Andy -Matuschak and others, to the point of sharing the same updates format -(appcasts) and having very similar user interface. +WinSparkle is a plug-and-forget software update library for Windows applications. It is heavily +inspired by the Sparkle framework for OS X written by Andy Matuschak and others, to the point of +sharing the same updates format (appcasts) and having very similar user interface. See https://winsparkle.org for more information about WinSparkle. ## Documentation -See the [WinSparkle wiki](https://github.com/vslavik/winsparkle/wiki) -and the [GoDoc](https://pkg.go.dev/github.com/abemedia/go-winsparkle?tab=doc). +See the [WinSparkle wiki](https://github.com/vslavik/winsparkle/wiki) and the +[GoDoc](https://pkg.go.dev/github.com/abemedia/go-winsparkle?tab=doc). ## Important -WinSparkle.dll must be placed into the same directory as your app executable. -Depending on your architecture use the version from `dll/x64` or `dll/x86`. +WinSparkle.dll must be placed into the same directory as your app executable. Depending on your +architecture use the version from `dll/x64` or `dll/x86`. diff --git a/example/main.go b/example/main.go index e782520..cba984e 100644 --- a/example/main.go +++ b/example/main.go @@ -22,6 +22,18 @@ func main() { c := make(chan struct{}) + sparkle.SetErrorCallback(func() { + log.Println("received an error") + }) + + sparkle.SetDidFindUpdateCallback(func() { + log.Println("did find update") + }) + + sparkle.SetDidNotFindUpdateCallback(func() { + log.Println("did not find update") + }) + sparkle.SetShutdownRequestCallback(func() { log.Println("installing update") close(c) @@ -32,9 +44,31 @@ func main() { close(c) }) + sparkle.SetUpdateSkippedCallback(func() { + log.Println("skipped update") + }) + + sparkle.SetUpdateDismissedCallback(func() { + log.Println("dismissed update") + }) + + sparkle.SetUpdatePostponedCallback(func() { + log.Println("postponed update") + }) + + sparkle.SetUserRunInstallerCallback(func(s string) (bool, error) { + log.Println("installer callback: " + s) + return true, nil + }) + + config := &store{data: make(map[string]string)} + sparkle.SetConfigMethods(config) + sparkle.Init() defer sparkle.Cleanup() + time.Sleep(time.Second) + sparkle.CheckUpdateWithUI() // waits until update is installed or cancelled (10min timeout) @@ -45,6 +79,31 @@ func main() { log.Println("shutting down") } +type store struct { + data map[string]string +} + +func (c *store) Read(name string) (string, bool) { + log.Println("reading config: " + name) + v, ok := c.data[name] + if !ok { + return "", false + } + return v, true +} + +func (c *store) Write(name, value string) bool { + log.Printf("writing config: %s=%q\n", name, value) + c.data[name] = value + return true +} + +func (c *store) Delete(name string) bool { + log.Println("deleting config: " + name) + delete(c.data, name) + return true +} + const pem = `-----BEGIN PUBLIC KEY----- MIIGRjCCBDkGByqGSM44BAEwggQsAoICAQCS7frykSttT+BkjHTeY/BZMWN6Fxg3 nYg1gDHb+QxQElEikI/70f7oJ9f/UIijyFMZgUcdP2D28X2Wg/gFkvJkWric2HJL