This commit is contained in:
partisan 2025-02-03 15:52:19 +01:00
commit d9dae02ffc
17 changed files with 1742 additions and 0 deletions

70
spm/run.go Normal file
View file

@ -0,0 +1,70 @@
package spm
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
)
// Run locates and starts the installed Spitfire browser without waiting for it to exit.
func Run() error {
installDir, err := GetInstallDir()
if err != nil {
return err
}
exePath := filepath.Join(installDir, "browser", "spitfire.exe")
if runtime.GOOS != "windows" {
exePath = filepath.Join(installDir, "browser", "spitfire")
}
cmd := exec.Command(exePath)
return cmd.Start()
}
// RunAndWait locates and starts the installed Spitfire browser and waits for it to exit.
func RunAndWait() error {
installDir, err := GetInstallDir()
if err != nil {
return fmt.Errorf("failed to get install directory: %w", err)
}
// Construct the browser executable path
exePath := filepath.Join(installDir, "browser", "spitfire.exe")
if runtime.GOOS != "windows" {
exePath = filepath.Join(installDir, "browser", "spitfire")
}
// Check if the browser executable exists
if _, err := os.Stat(exePath); err != nil {
return fmt.Errorf("browser executable not found at %s: %w", exePath, err)
}
// Create the command
cmd := exec.Command(exePath)
// Attach standard output and error for debugging
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Start the browser process
fmt.Printf("Starting browser: %s\n", exePath)
err = cmd.Start()
if err != nil {
return fmt.Errorf("failed to start browser: %w", err)
}
// Print the PID for debugging
fmt.Printf("Browser process started with PID %d\n", cmd.Process.Pid)
// Wait for the process to exit
err = cmd.Wait()
if err != nil {
return fmt.Errorf("browser exited with error: %w", err)
}
fmt.Println("Browser exited successfully.")
return nil
}