-
-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathapp.go
More file actions
71 lines (58 loc) · 1.72 KB
/
Copy pathapp.go
File metadata and controls
71 lines (58 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"strings"
"installer/types"
"installer/utils"
"github.com/pkg/browser"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
func (a *App) SetContext(ctx context.Context) {
a.ctx = ctx
}
func (a *App) GetVersion() string {
return version
}
func (a *App) CheckForUpdate() {
// If the version doesn't start with "v" then it's a
// development build, so we don't check for updates
if !strings.HasPrefix(version, "v") || strings.HasSuffix(version, "-dev") {
return
}
// Get latest installer version from GitHub API
apiData, err := utils.DownloadJSON[types.GitHubRelease]("https://api.github.com/repos/BetterDiscord/Installer/releases/latest")
if err != nil {
// Offline or GitHub API error — skip the update check silently.
return
}
// If the current version is greater than or equal
// to the latest version, no update is needed
if utils.CompareVersions(version, apiData.TagName) >= 0 {
return
}
result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Update Available",
Message: fmt.Sprintf("A new version (%s) of the installer is available. Would you like to download it now?", apiData.TagName),
// Explicit buttons are required on macOS: its dialog maps the result
// back through Buttons, returning "" when none are set. The other
// platforms ignore Buttons and return Yes/No on their own.
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
})
if err != nil {
// Dialog failed to display — don't block startup over it.
return
}
if result == "Yes" {
browser.OpenURL(apiData.HTMLURL)
}
}