added update check, save set path
This commit is contained in:
@@ -2,5 +2,5 @@
|
|||||||
Icon = "Icon.png"
|
Icon = "Icon.png"
|
||||||
Name = "TurtleSilicon"
|
Name = "TurtleSilicon"
|
||||||
ID = "com.tairasu.turtlesilicon"
|
ID = "com.tairasu.turtlesilicon"
|
||||||
Version = "1.0.5"
|
Version = "1.0.6"
|
||||||
Build = 12
|
Build = 12
|
||||||
|
33
main.go
33
main.go
@@ -1,20 +1,45 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"turtlesilicon/pkg/ui"
|
||||||
|
"turtlesilicon/pkg/utils" /
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"turtlesilicon/pkg/ui" // Updated import path
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
const appVersion = "1.0.5"
|
const appVersion = "1.0.6"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
myApp := app.NewWithID("com.tairasu.turtlesilicon")
|
myApp := app.NewWithID("com.tairasu.turtlesilicon")
|
||||||
myWindow := myApp.NewWindow("TurtleSilicon v" + appVersion) // Updated title
|
myWindow := myApp.NewWindow("TurtleSilicon v" + appVersion)
|
||||||
myWindow.Resize(fyne.NewSize(650, 450))
|
myWindow.Resize(fyne.NewSize(650, 450))
|
||||||
myWindow.SetFixedSize(true)
|
myWindow.SetFixedSize(true)
|
||||||
|
|
||||||
content := ui.CreateUI(myWindow) // Use the CreateUI function from the ui package
|
// Check for updates
|
||||||
|
go func() {
|
||||||
|
prefs, _ := utils.LoadPrefs()
|
||||||
|
latest, notes, update, err := utils.CheckForUpdate(appVersion)
|
||||||
|
if err == nil && update && prefs.SuppressedUpdateVersion != latest {
|
||||||
|
checkbox := widget.NewCheck("Do not show this anymore", func(bool) {})
|
||||||
|
content := container.NewVBox(
|
||||||
|
widget.NewLabel("A new version ("+latest+") is available!"),
|
||||||
|
widget.NewLabel("Release notes:\n\n"+notes),
|
||||||
|
checkbox,
|
||||||
|
)
|
||||||
|
dialog.ShowCustomConfirm("Update Available", "OK", "Cancel", content, func(ok bool) {
|
||||||
|
if checkbox.Checked {
|
||||||
|
prefs.SuppressedUpdateVersion = latest
|
||||||
|
utils.SavePrefs(prefs)
|
||||||
|
}
|
||||||
|
}, myWindow)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
content := ui.CreateUI(myWindow)
|
||||||
myWindow.SetContent(content)
|
myWindow.SetContent(content)
|
||||||
|
|
||||||
myWindow.ShowAndRun()
|
myWindow.ShowAndRun()
|
||||||
|
@@ -6,11 +6,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"turtlesilicon/pkg/utils"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"turtlesilicon/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultCrossOverPath = "/Applications/CrossOver.app"
|
const DefaultCrossOverPath = "/Applications/CrossOver.app"
|
||||||
@@ -38,6 +39,10 @@ func SelectCrossOverPath(myWindow fyne.Window, crossoverPathLabel *widget.RichTe
|
|||||||
CrossoverPath = selectedPath
|
CrossoverPath = selectedPath
|
||||||
PatchesAppliedCrossOver = false
|
PatchesAppliedCrossOver = false
|
||||||
log.Println("CrossOver path set to:", CrossoverPath)
|
log.Println("CrossOver path set to:", CrossoverPath)
|
||||||
|
// Save to prefs
|
||||||
|
prefs, _ := utils.LoadPrefs()
|
||||||
|
prefs.CrossOverPath = selectedPath
|
||||||
|
utils.SavePrefs(prefs)
|
||||||
} else {
|
} else {
|
||||||
dialog.ShowError(fmt.Errorf("invalid selection: '%s'. Please select a valid .app bundle", selectedPath), myWindow)
|
dialog.ShowError(fmt.Errorf("invalid selection: '%s'. Please select a valid .app bundle", selectedPath), myWindow)
|
||||||
log.Println("Invalid CrossOver path selected:", selectedPath)
|
log.Println("Invalid CrossOver path selected:", selectedPath)
|
||||||
@@ -62,6 +67,10 @@ func SelectTurtleWoWPath(myWindow fyne.Window, turtlewowPathLabel *widget.RichTe
|
|||||||
TurtlewowPath = selectedPath
|
TurtlewowPath = selectedPath
|
||||||
PatchesAppliedTurtleWoW = false
|
PatchesAppliedTurtleWoW = false
|
||||||
log.Println("TurtleWoW path set to:", TurtlewowPath)
|
log.Println("TurtleWoW path set to:", TurtlewowPath)
|
||||||
|
// Save to prefs
|
||||||
|
prefs, _ := utils.LoadPrefs()
|
||||||
|
prefs.TurtleWoWPath = selectedPath
|
||||||
|
utils.SavePrefs(prefs)
|
||||||
} else {
|
} else {
|
||||||
dialog.ShowError(fmt.Errorf("invalid selection: '%s' is not a valid directory", selectedPath), myWindow)
|
dialog.ShowError(fmt.Errorf("invalid selection: '%s' is not a valid directory", selectedPath), myWindow)
|
||||||
log.Println("Invalid TurtleWoW path selected:", selectedPath)
|
log.Println("Invalid TurtleWoW path selected:", selectedPath)
|
||||||
|
38
pkg/ui/ui.go
38
pkg/ui/ui.go
@@ -7,28 +7,29 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"turtlesilicon/pkg/launcher" // Corrected import path
|
||||||
|
"turtlesilicon/pkg/patching" // Corrected import path
|
||||||
|
"turtlesilicon/pkg/paths" // Corrected import path
|
||||||
|
"turtlesilicon/pkg/utils" // Corrected import path
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"turtlesilicon/pkg/launcher" // Corrected import path
|
|
||||||
"turtlesilicon/pkg/patching" // Corrected import path
|
|
||||||
"turtlesilicon/pkg/paths" // Corrected import path
|
|
||||||
"turtlesilicon/pkg/utils" // Corrected import path
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
crossoverPathLabel *widget.RichText
|
crossoverPathLabel *widget.RichText
|
||||||
turtlewowPathLabel *widget.RichText
|
turtlewowPathLabel *widget.RichText
|
||||||
turtlewowStatusLabel *widget.RichText
|
turtlewowStatusLabel *widget.RichText
|
||||||
crossoverStatusLabel *widget.RichText
|
crossoverStatusLabel *widget.RichText
|
||||||
launchButton *widget.Button
|
launchButton *widget.Button
|
||||||
patchTurtleWoWButton *widget.Button
|
patchTurtleWoWButton *widget.Button
|
||||||
patchCrossOverButton *widget.Button
|
patchCrossOverButton *widget.Button
|
||||||
unpatchTurtleWoWButton *widget.Button
|
unpatchTurtleWoWButton *widget.Button
|
||||||
unpatchCrossOverButton *widget.Button
|
unpatchCrossOverButton *widget.Button
|
||||||
metalHudCheckbox *widget.Check
|
metalHudCheckbox *widget.Check
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateAllStatuses() {
|
func UpdateAllStatuses() {
|
||||||
@@ -138,6 +139,15 @@ func UpdateAllStatuses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateUI(myWindow fyne.Window) fyne.CanvasObject {
|
func CreateUI(myWindow fyne.Window) fyne.CanvasObject {
|
||||||
|
// Load saved paths from prefs
|
||||||
|
prefs, _ := utils.LoadPrefs()
|
||||||
|
if prefs.TurtleWoWPath != "" {
|
||||||
|
paths.TurtlewowPath = prefs.TurtleWoWPath
|
||||||
|
}
|
||||||
|
if prefs.CrossOverPath != "" {
|
||||||
|
paths.CrossoverPath = prefs.CrossOverPath
|
||||||
|
}
|
||||||
|
|
||||||
crossoverPathLabel = widget.NewRichText()
|
crossoverPathLabel = widget.NewRichText()
|
||||||
turtlewowPathLabel = widget.NewRichText()
|
turtlewowPathLabel = widget.NewRichText()
|
||||||
turtlewowStatusLabel = widget.NewRichText()
|
turtlewowStatusLabel = widget.NewRichText()
|
||||||
|
50
pkg/utils/prefs.go
Normal file
50
pkg/utils/prefs.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserPrefs struct {
|
||||||
|
SuppressedUpdateVersion string `json:"suppressed_update_version"`
|
||||||
|
TurtleWoWPath string `json:"turtlewow_path"`
|
||||||
|
CrossOverPath string `json:"crossover_path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPrefsPath() (string, error) {
|
||||||
|
dir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return filepath.Join(dir, "TurtleSilicon", "prefs.json"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadPrefs() (*UserPrefs, error) {
|
||||||
|
path, err := getPrefsPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return &UserPrefs{}, nil // default prefs if not found
|
||||||
|
}
|
||||||
|
var prefs UserPrefs
|
||||||
|
if err := json.Unmarshal(data, &prefs); err != nil {
|
||||||
|
return &UserPrefs{}, nil
|
||||||
|
}
|
||||||
|
return &prefs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SavePrefs(prefs *UserPrefs) error {
|
||||||
|
path, err := getPrefsPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.MkdirAll(filepath.Dir(path), 0755)
|
||||||
|
data, err := json.MarshalIndent(prefs, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.WriteFile(path, data, 0644)
|
||||||
|
}
|
@@ -1,9 +1,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -117,3 +119,21 @@ func QuotePathForShell(path string) string {
|
|||||||
return fmt.Sprintf(`"%s"`, path)
|
return fmt.Sprintf(`"%s"`, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckForUpdate(currentVersion string) (latestVersion, releaseNotes string, updateAvailable bool, err error) {
|
||||||
|
resp, err := http.Get("https://api.github.com/repos/tairasu/TurtleSilicon/releases/latest")
|
||||||
|
if err != nil {
|
||||||
|
return "", "", false, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var data struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||||
|
return "", "", false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
latest := strings.TrimPrefix(data.TagName, "v")
|
||||||
|
return latest, data.Body, latest != currentVersion, nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user