updated spm package
This commit is contained in:
parent
b403befe74
commit
48473f98c5
16 changed files with 1454 additions and 505 deletions
71
spm/run.go
Normal file
71
spm/run.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
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)
|
||||
cmd.Dir = filepath.Join(installDir, "browser")
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue