Skip to content

Commit

Permalink
Faster startup
Browse files Browse the repository at this point in the history
  • Loading branch information
libsgh committed Sep 20, 2024
1 parent b0d26a5 commit e73b9b6
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,18 @@ func settingsScreen(a fyne.App, win fyne.Window, data *SettingsData) fyne.Canvas
}
themeRadio.Selected = getString(data.themeSettings)
themeRadio.Horizontal = true
hasNew, url := chromeUpdaterNew(data, getString(data.ghProxy))
updateUrl := binding.NewString()
updateBtnText := binding.NewString()
updateBtnText.Set(LoadString("UpdaterCheckBtnLabel"))
newBtn := widget.NewButton(getString(updateBtnText), func() {
//_ = a.OpenURL(parseURL(url))
UpdateSelf(a, data, url, updateBtnText)
UpdateSelf(a, data, getString(updateUrl), updateBtnText)
})
go chromeUpdaterNew(data, getString(data.ghProxy), updateUrl, newBtn)
updateBtnText.AddListener(binding.NewDataListener(func() {
newBtn.SetText(getString(updateBtnText))
}))
if hasNew {
newBtn.Show()
} else {
newBtn.Hide()
}

return container.NewCenter(container.NewVBox(
widget.NewLabelWithStyle(LoadString("BaseSettingLabel"), fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
container.NewGridWithColumns(3, installFileConfig, historyVersionConfig),
Expand Down Expand Up @@ -130,31 +127,33 @@ func UpdateSelf(a fyne.App, sd *SettingsData, url string, btnText binding.String
a.Quit()
_ = cmd.Start()
}
func chromeUpdaterNew(sd *SettingsData, proxy string) (bool, string) {
func chromeUpdaterNew(sd *SettingsData, proxy string, updateUrl binding.String, newBtn *widget.Button) {
apiUrl := "https://raw.githubusercontent.com/libsgh/ghapi-json-generator/output/v2/repos/libsgh/chrome_updater/releases%3Fper_page%3D10/data.json"
client, reqUrl := setProxy(sd, apiUrl)
response, err := client.Get(reqUrl)
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, asset.BrowserDownloadURL
if len(githubReleases) != 0 {
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)) {
updateUrl.Set(asset.BrowserDownloadURL)
}
}
hasNew := ver != lastedVer
if hasNew {
newBtn.Show()
} else {
newBtn.Hide()
}
}
return ver != lastedVer, pathJoin(proxy, githubReleases[0].Assets[0].BrowserDownloadURL)
}

0 comments on commit e73b9b6

Please sign in to comment.