UPDATE: Add self update
This commit is contained in:
22
internal/app-serrvice.go
Normal file
22
internal/app-serrvice.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"firefly-launcher/pkg/constant"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
type AppService struct{}
|
||||
|
||||
func (a *AppService) GetCurrentLauncherVersion() (bool, string) {
|
||||
return true, constant.CurrentLauncherVersion
|
||||
}
|
||||
|
||||
func (a *AppService) CloseAppAfterTimeout(timeout int) (bool, string) {
|
||||
go func() {
|
||||
time.Sleep(time.Duration(timeout) * time.Second)
|
||||
application.Get().Quit()
|
||||
}()
|
||||
return true, ""
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
@@ -140,3 +139,4 @@ func (f *FSService) FileExistsInZip(archivePath, fileInside string) (bool, strin
|
||||
}
|
||||
return exists, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/minio/selfupdate"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
type GitService struct{}
|
||||
|
||||
func (g *GitService) GetLatestServerVersion(oldVersion string) (bool, string, string) {
|
||||
func (g *GitService) GetLatestServerVersion() (bool, string, string) {
|
||||
resp, err := http.Get(constant.ServerGitUrl)
|
||||
if err != nil {
|
||||
return false, "", err.Error()
|
||||
@@ -38,7 +39,6 @@ func (g *GitService) GetLatestServerVersion(oldVersion string) (bool, string, st
|
||||
}
|
||||
|
||||
func (g *GitService) DownloadServerProgress(version string) (bool, string) {
|
||||
|
||||
resp, err := http.Get(constant.ServerGitUrl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -109,7 +109,7 @@ func (g *GitService) UnzipServer() {
|
||||
os.Remove(filepath.Join(constant.ServerStorageUrl, constant.ServerZipFile))
|
||||
}
|
||||
|
||||
func (g *GitService) GetLatestProxyVersion(oldVersion string) (bool, string, string) {
|
||||
func (g *GitService) GetLatestProxyVersion() (bool, string, string) {
|
||||
resp, err := http.Get(constant.ProxyGitUrl)
|
||||
if err != nil {
|
||||
return false, "", err.Error()
|
||||
@@ -201,3 +201,82 @@ func (g *GitService) UnzipProxy() {
|
||||
unzipParallel(filepath.Join(constant.ProxyStorageUrl, constant.ProxyZipFile), constant.ProxyStorageUrl)
|
||||
os.Remove(filepath.Join(constant.ProxyStorageUrl, constant.ProxyZipFile))
|
||||
}
|
||||
|
||||
func (g *GitService) GetLatestLauncherVersion() (bool, string, string) {
|
||||
resp, err := http.Get(constant.LauncherGitUrl)
|
||||
if err != nil {
|
||||
return false, "", err.Error()
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
var releases []models.ReleaseType
|
||||
err = json.Unmarshal(body, &releases)
|
||||
if err != nil {
|
||||
return false, "", err.Error()
|
||||
}
|
||||
|
||||
if len(releases) == 0 {
|
||||
return false, "", "no releases found"
|
||||
}
|
||||
|
||||
return true, releases[0].TagName, ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (g *GitService) UpdateLauncherProgress(version string) (bool, string) {
|
||||
resp, err := http.Get(constant.LauncherGitUrl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
var releases []*models.ReleaseType
|
||||
err = json.Unmarshal(body, &releases)
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
if len(releases) == 0 {
|
||||
return false, "no releases found"
|
||||
}
|
||||
|
||||
var releaseData *models.ReleaseType
|
||||
for _, release := range releases {
|
||||
if release.TagName == version {
|
||||
releaseData = release
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if releaseData == nil || releaseData.TagName == "" {
|
||||
return false, "no release found"
|
||||
}
|
||||
|
||||
var assetWin models.AssetType
|
||||
for _, asset := range releaseData.Assets {
|
||||
if asset.Name == constant.LauncherFile {
|
||||
assetWin = asset
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if assetWin.Name == "" {
|
||||
return false, "no assets found"
|
||||
}
|
||||
|
||||
resp, err = http.Get(assetWin.BrowserDownloadURL)
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
err = selfupdate.Apply(resp.Body, selfupdate.Options{})
|
||||
if err != nil {
|
||||
return false, err.Error()
|
||||
}
|
||||
return true, ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user