Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: examples #10

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.
59 changes: 59 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down