forked from libsgh/chrome_updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.go
104 lines (102 loc) · 3.83 KB
/
setting.go
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
jsoniter "github.com/json-iterator/go"
"io"
"log"
"net/http"
"runtime"
"strings"
)
func settingsScreen(a fyne.App, win fyne.Window, data *SettingsData) fyne.CanvasObject {
installFileConfig := widget.NewCheckWithData(LoadString("BaseRemainInstallFiles"), data.remainInstallFileSettings)
historyVersionConfig := widget.NewCheckWithData(LoadString("BaseRemainHistoryFiles"), data.remainHistoryFileSettings)
ghProxyEntry := widget.NewEntryWithData(data.ghProxy)
ghProxyEntry.PlaceHolder = LoadString("BaseGhProxy")
themeRadio := widget.NewRadioGroup([]string{"System", "Light", "Dark"}, func(value string) {
data.themeSettings.Set(value)
fyne.CurrentApp().Settings().SetTheme(&MyTheme{data.themeSettings, data.langSettings})
})
langRadio := widget.NewRadioGroup([]string{
"System",
"en-US",
"zh-CN"}, func(value string) {
data.langSettings.Set(value)
win.Content().Refresh()
})
if getString(data.langSettings) == "" {
data.langSettings.Set(LoadString("SystemOption"))
}
langRadio.Selected = getString(data.langSettings)
langRadio.Horizontal = true
if getString(data.themeSettings) == "" {
data.themeSettings.Set(LoadString("SystemOption"))
}
themeRadio.Selected = getString(data.themeSettings)
themeRadio.Horizontal = true
hasNew, url := chromeUpdaterNew(getString(data.ghProxy))
newBtn := widget.NewButton(LoadString("UpdaterCheckBtnLabel"), func() {
_ = a.OpenURL(parseURL(url))
})
if hasNew {
newBtn.Show()
} else {
newBtn.Hide()
}
return container.NewCenter(container.NewVBox(
widget.NewLabelWithStyle(LoadString("BaseSettingLabel"), fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
container.NewGridWithColumns(2, installFileConfig, historyVersionConfig),
ghProxyEntry,
widget.NewSeparator(),
widget.NewLabelWithStyle(LoadString("ThemeLabel"), fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
container.NewHBox(themeRadio),
widget.NewSeparator(),
widget.NewLabelWithStyle(LoadString("LangLabel"), fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
container.NewHBox(langRadio),
widget.NewSeparator(),
widget.NewLabelWithStyle(LoadString("AboutLabel"), fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
container.NewHBox(
widget.NewLabel(LoadString("VersionLabel")+": v"+fyne.CurrentApp().Metadata().Version),
newBtn,
widget.NewButton(LoadString("IssuesLabel"), func() {
_ = a.OpenURL(parseURL("https://github.com/libsgh/chrome_updater/issues"))
}),
),
container.NewHBox(
widget.NewHyperlink(LoadString("OfflinePkgLabel"), parseURL("https://chrome.noki.eu.org")),
widget.NewLabel("-"),
widget.NewHyperlink("GitHub", parseURL("https://github.com/libsgh/chrome_updater")),
widget.NewLabel("-"),
widget.NewHyperlink("LICENSE", parseURL("https://github.com/libsgh/chrome_updater/blob/main/LICENSE")),
),
))
}
func chromeUpdaterNew(proxy string) (bool, string) {
response, err := http.Get(pathJoin(proxy, "https://raw.githubusercontent.com/libsgh/ghapi-json-generator/output/v2/repos/libsgh/chrome_updater/releases%3Fper_page%3D10/data.json"))
if err != nil {
log.Println(err)
return false, ""
}
defer response.Body.Close()
data, err := io.ReadAll(response.Body)
var githubReleases []GithubRelease
jsoniter.UnmarshalFromString(string(data), &githubReleases)
if err != nil {
log.Println(err)
return false, ""
}
if len(githubReleases) == 0 {
return false, ""
}
ver := "v" + fyne.CurrentApp().Metadata().Version
lastedVer := githubReleases[0].TagName
for _, asset := range githubReleases[0].Assets {
if strings.Contains(asset.BrowserDownloadURL, fmt.Sprintf("chrome_updater-windows-%s.zip", runtime.GOARCH)) {
return ver != lastedVer, pathJoin(proxy, asset.BrowserDownloadURL)
}
}
return ver != lastedVer, pathJoin(proxy, githubReleases[0].Assets[0].BrowserDownloadURL)
}