added --silent and register values in windows registry keys
All checks were successful
/ test-on-windows (push) Successful in 20s
/ test-on-alpine (push) Successful in 4s

This commit is contained in:
partisan 2025-02-16 22:57:24 +01:00
parent 48473f98c5
commit ca57775f8f
7 changed files with 402 additions and 165 deletions

136
main.go
View file

@ -1,9 +1,11 @@
package main
import (
"flag"
"fmt"
"math"
"os"
"time"
"spitfire-installer/spm"
rl "github.com/gen2brain/raylib-go/raylib"
@ -30,7 +32,14 @@ var (
const finalStep = 3
func main() {
spm.Run()
// Check for the --silent flag.
silent := flag.Bool("silent", false, "run installer without GUI")
flag.Parse()
if *silent {
runSilent()
return
}
monitor := rl.GetCurrentMonitor()
if monitor < 0 {
@ -96,8 +105,8 @@ func main() {
radius := float32(30)
dx := mousePos.X - topRightX
dy := mousePos.Y - topRightY
dist := float32(math.Sqrt(float64(dx*dx + dy*dy)))
if dist < radius+30 {
dist := float32((dx*dx + dy*dy))
if dist < (radius+30)*(radius+30) {
textHoverFade += 0.1
if textHoverFade > 1 {
textHoverFade = 1
@ -161,6 +170,36 @@ func main() {
}
}
func runSilent() {
fmt.Println("Running installer in silent mode (default values will be used).")
// Start the download+decompress phase.
installer.StartDownloadDecompress()
// Poll until the download/decompression phase is done.
for !installer.DoneDownload {
time.Sleep(1 * time.Second)
}
// Start the final installation.
installer.FinalInstall()
// Poll until installation is finished.
for !installer.DoneInstall {
time.Sleep(1 * time.Second)
}
if installer.LastError != nil {
fmt.Printf("Installation failed: %v\n", installer.LastError)
os.Exit(1)
}
fmt.Println("Installation complete!")
// Optionally launch the app after install:
// spm.Run() or another function if needed.
os.Exit(0)
}
func handleInput(mousePos rl.Vector2, screenW, screenH, buttonW, buttonH int, prevX, prevY, nextX, nextY int32) {
switch currentStep {
case 0:
@ -211,7 +250,7 @@ func drawHeader(screenW int) {
}
// Now we pass "displayProgress" (0..100) as a float, "posAlpha" in [0..1],
// plus "doneInstall" to show the "Run App" button
// plus "doneInstall" to show the "Run App" button.
func drawInstallCircle(screenW, screenH int, posAlpha, displayProgress float32, doneInstall bool, hoverAlpha float32) {
// Lerp position/radius
topRight := rl.Vector2{X: float32(screenW - 80), Y: 100}
@ -251,7 +290,7 @@ func drawInstallCircle(screenW, screenH int, posAlpha, displayProgress float32,
}
}
// "Run App" button logic is the same
// "Run App" button logic is the same.
func drawRunAppButton(cx, cy float32) {
w := float32(180)
h := float32(50)
@ -259,7 +298,8 @@ func drawRunAppButton(cx, cy float32) {
hovered := overRect(rl.GetMousePosition(), rect)
drawRoundedRectButton(rect, "Start Spitfire", 1.0, hovered)
if hovered && rl.IsMouseButtonPressed(rl.MouseLeftButton) {
fmt.Println("Launching the app (placeholder)...")
fmt.Println("Launching...")
spm.Run()
os.Exit(0)
}
}
@ -346,85 +386,3 @@ func startTransition(from, to int) {
targetStep = to
transition.Start(from, to)
}
// SPM example
// package main
// import (
// "fmt"
// "os"
// "path/filepath"
// "spitfire-installer/spm"
// "time"
// )
// func main() {
// // Start a goroutine to display progress updates
// done := make(chan bool)
// go func() {
// for {
// select {
// case <-done:
// return
// default:
// percentage, task := spm.GetProgress()
// fmt.Printf("\r[%3d%%] %s", percentage, task)
// time.Sleep(500 * time.Millisecond)
// }
// }
// }()
// // Set up the download directory
// downloadDir := spm.GetTempDownloadDir()
// fmt.Println("\nTemporary download directory:", downloadDir)
// // Download the APPINDEX
// appIndexPath := filepath.Join(downloadDir, "APPINDEX")
// spm.UpdateProgress(0, "Starting APPINDEX download")
// if err := spm.DownloadAppIndex(appIndexPath); err != nil {
// fmt.Println("\nError downloading APPINDEX:", err)
// done <- true
// os.Exit(1)
// }
// // Download the desired package version (e.g., nightly)
// packageName := "spitfire-browser"
// release := "nightly"
// spm.UpdateProgress(0, "Starting package download")
// if err := spm.DownloadPackageFromAppIndex(appIndexPath, packageName, release, downloadDir); err != nil {
// fmt.Println("\nError downloading package:", err)
// done <- true
// os.Exit(1)
// }
// // Decompress and install
// packagePath := filepath.Join(downloadDir, "browser-amd64-nightly-linux.tar.gz")
// spm.UpdateProgress(0, "Starting decompression")
// tempDir, err := spm.DecompressToTemp(packagePath)
// if err != nil {
// fmt.Println("\nError decompressing package:", err)
// done <- true
// os.Exit(1)
// }
// fmt.Println("\nDecompressed package to:", tempDir)
// // Generate default install directory
// installDir, err := spm.GetDefaultInstallDir()
// if err != nil {
// inst.LastError = fmt.Errorf("failed to determine default install directory: %w", err)
// return
// }
// spm.UpdateProgress(0, "Starting installation")
// if err := spm.MoveFilesToInstallDir(tempDir, installDir); err != nil {
// fmt.Println("\nError installing package:", err)
// done <- true
// os.Exit(1)
// }
// // Notify progress display to stop and finalize
// done <- true
// fmt.Printf("\nSuccessfully installed %s (%s) to %s\n", packageName, release, installDir)
// }