From f3a78f4bd6e8a9df88b46b7add2a359f57f07777 Mon Sep 17 00:00:00 2001
From: partisan <none@noone.no>
Date: Sun, 2 Mar 2025 09:59:00 +0100
Subject: [PATCH 1/5] Fixed error loops

---
 README.md        |  1 -
 auto.go          | 33 ++++++++++++++++-----------------
 register_unix.go |  8 ++++----
 3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 1a924b4..63f036c 100644
--- a/README.md
+++ b/README.md
@@ -78,7 +78,6 @@ func main() {
     spm.Run()
 }
 ```
-*Functions, and specifically their names, are subject to change as I really don't like "AutoDownloadSpecified," but I don't want to make it "DownloadSpecified" yet, as there are still many functions in SPM used for manual downloads, installs, etc.*
 
 <p align="center" style="font-size: 32px;">
   <strong>License</strong>
diff --git a/auto.go b/auto.go
index 491bb66..d544a44 100644
--- a/auto.go
+++ b/auto.go
@@ -196,23 +196,22 @@ func DownloadSpecified(specs []AppIndexEntry) error {
 		}
 		fmt.Printf("[INFO] Found matching APPINDEX entry: %+v\n", *matchingEntry)
 
-		// // Check if an update is needed
-		// updateNeeded, err := IsUpdateNeeded(
-		// 	installDir,
-		// 	matchingEntry.Name,
-		// 	matchingEntry.Release,
-		// 	matchingEntry.Version,
-		// 	matchingEntry.Arch,
-		// 	matchingEntry.OS,
-		// )
-		// if err != nil {
-		// 	return fmt.Errorf("[ERROR] Failed to check if update is needed for %s: %w", matchingEntry.Name, err)
-		// }
+		updateNeeded, err := IsUpdateNeeded(
+			installDir,
+			matchingEntry.Name,
+			matchingEntry.Release,
+			matchingEntry.Version,
+			matchingEntry.Arch,
+			matchingEntry.OS,
+		)
+		if err != nil {
+			return fmt.Errorf("[ERROR] Failed to check if update is needed for %s: %w", matchingEntry.Name, err)
+		}
 
-		// if !updateNeeded {
-		// 	fmt.Printf("[INFO] No update needed for package '%s'\n", matchingEntry.Name)
-		// 	continue
-		// }
+		if !updateNeeded {
+			fmt.Printf("[INFO] No update needed for package '%s'\n", matchingEntry.Name)
+			continue
+		}
 
 		// 5) Download the package
 		downloadDir := GetTempDir()
@@ -243,7 +242,7 @@ func DownloadSpecified(specs []AppIndexEntry) error {
 		}
 		fmt.Printf("[INFO] Package '%s' decompressed successfully to: %s\n", matchingEntry.Name, tempDir)
 
-		// 7) Store in pendingUpdates for InstallUpdates
+		// Add to pendingUpdates for InstallUpdates
 		fmt.Printf("[INFO] Adding '%s' to pending updates\n", matchingEntry.Name)
 		pendingUpdates = append(pendingUpdates, *matchingEntry)
 	}
diff --git a/register_unix.go b/register_unix.go
index d3911bf..fb860ee 100644
--- a/register_unix.go
+++ b/register_unix.go
@@ -11,13 +11,13 @@ import (
 )
 
 // RegisterApp is not supported on non-Windows platforms.
-func RegisterApp() error {
-	return fmt.Errorf("RegisterApp is only available on Windows")
+func RegisterApp() {
+	fmt.Println("[WARN] RegisterApp() is only available on Windows")
 }
 
 // UnregisterApp is not supported on non-Windows platforms.
-func UnregisterApp() error {
-	return fmt.Errorf("UnregisterApp is only available on Windows")
+func UnregisterApp() {
+	fmt.Println("[WARN] UnregisterApp() is only available on Windows")
 }
 
 // IsRegistered returns true if the application is detected as installed.

From f34f335206915b05f6190560418df9d26dc15a06 Mon Sep 17 00:00:00 2001
From: partisan <none@noone.no>
Date: Sun, 2 Mar 2025 10:09:18 +0100
Subject: [PATCH 2/5] Reverted changes bcs of './installer.go:115:13:
 spm.RegisterApp() (no value) used as value'

---
 register_unix.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/register_unix.go b/register_unix.go
index fb860ee..f9e35c9 100644
--- a/register_unix.go
+++ b/register_unix.go
@@ -11,13 +11,13 @@ import (
 )
 
 // RegisterApp is not supported on non-Windows platforms.
-func RegisterApp() {
-	fmt.Println("[WARN] RegisterApp() is only available on Windows")
+func RegisterApp() error {
+	return fmt.Errorf("[WARN] RegisterApp() is only available on Windows")
 }
 
 // UnregisterApp is not supported on non-Windows platforms.
-func UnregisterApp() {
-	fmt.Println("[WARN] UnregisterApp() is only available on Windows")
+func UnregisterApp() error {
+	return fmt.Errorf("[WARN] UnregisterApp() is only available on Windows")
 }
 
 // IsRegistered returns true if the application is detected as installed.

From c84170d61528fa5f4d7069641d513522f51d63d2 Mon Sep 17 00:00:00 2001
From: partisan <partisan@noreply@weforge.xyz>
Date: Fri, 28 Mar 2025 09:21:38 +0000
Subject: [PATCH 3/5] Fix RunAndWait() process detection

Fixed incorrect browser exit detection in RunAndWait() which could lead to Browser file corruption due to incomplete updates.
---
 run_win.go | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/run_win.go b/run_win.go
index a108d7e..706b6d4 100644
--- a/run_win.go
+++ b/run_win.go
@@ -9,7 +9,10 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
-	"syscall"
+	"strings"
+	"time"
+
+	"golang.org/x/sys/windows"
 )
 
 // Run locates and starts the installed Spitfire browser without waiting for it to exit.
@@ -33,7 +36,6 @@ func RunAndWait() error {
 		return fmt.Errorf("failed to get install directory: %w", err)
 	}
 
-	// Construct the browser executable path
 	exePath := filepath.Join(installDir, "browser", "spitfire.exe")
 	if _, err := os.Stat(exePath); err != nil {
 		return fmt.Errorf("browser executable not found at %s: %w", exePath, err)
@@ -42,23 +44,29 @@ func RunAndWait() error {
 	cmd := exec.Command(exePath)
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
+	cmd.Dir = filepath.Join(installDir, "browser")
 
-	// Use CREATE_NEW_PROCESS_GROUP flag for Windows
-	cmd.SysProcAttr = &syscall.SysProcAttr{
-		CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
+	// Create job object starting the process
+	job, err := windows.CreateJobObject(nil, nil)
+	if err != nil {
+		return fmt.Errorf("failed to create job object: %w", err)
 	}
+	defer windows.CloseHandle(job)
 
 	fmt.Printf("Starting browser: %s\n", exePath)
 	if err := cmd.Start(); err != nil {
 		return fmt.Errorf("failed to start browser: %w", err)
 	}
 
-	fmt.Printf("Browser process started with PID %d\n", cmd.Process.Pid)
-
-	if err := cmd.Wait(); err != nil {
-		return fmt.Errorf("browser exited with error: %w", err)
+	for {
+		cmd := exec.Command("tasklist", "/FI", "IMAGENAME eq spitfire.exe")
+		output, _ := cmd.Output()
+		if !strings.Contains(string(output), "spitfire.exe") {
+			break
+		}
+		time.Sleep(1 * time.Second)
 	}
 
-	fmt.Println("Browser exited successfully.")
+	fmt.Println("Browser exited.")
 	return nil
 }

From b31ea5f3ccd49e9ec640a566adebf5d2d8ff179c Mon Sep 17 00:00:00 2001
From: partisan <partisan@noreply@weforge.xyz>
Date: Fri, 28 Mar 2025 09:33:17 +0000
Subject: [PATCH 4/5] Update go.sum

---
 go.sum | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/go.sum b/go.sum
index be248fb..bd54818 100644
--- a/go.sum
+++ b/go.sum
@@ -4,6 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
 github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
+golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
 gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

From af129cb59d36b3d003b486be340309c30854463d Mon Sep 17 00:00:00 2001
From: partisan <partisan@noreply@weforge.xyz>
Date: Fri, 28 Mar 2025 09:33:36 +0000
Subject: [PATCH 5/5] Update go.mod

---
 go.mod | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/go.mod b/go.mod
index 8b67881..f4c1524 100644
--- a/go.mod
+++ b/go.mod
@@ -1,7 +1,12 @@
 module weforge.xyz/Spitfire/SPM
 
-go 1.21
+go 1.23.0
 
-require gopkg.in/ini.v1 v1.67.0
+toolchain go1.24.1
+
+require (
+	golang.org/x/sys v0.31.0
+	gopkg.in/ini.v1 v1.67.0
+)
 
 require github.com/stretchr/testify v1.10.0 // indirect