Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
af129cb59d | |||
b31ea5f3cc | |||
c84170d615 |
3 changed files with 27 additions and 12 deletions
9
go.mod
9
go.mod
|
@ -1,7 +1,12 @@
|
||||||
module weforge.xyz/Spitfire/SPM
|
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
|
require github.com/stretchr/testify v1.10.0 // indirect
|
||||||
|
|
2
go.sum
2
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/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 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
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 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|
28
run_win.go
28
run_win.go
|
@ -9,7 +9,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run locates and starts the installed Spitfire browser without waiting for it to exit.
|
// 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)
|
return fmt.Errorf("failed to get install directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the browser executable path
|
|
||||||
exePath := filepath.Join(installDir, "browser", "spitfire.exe")
|
exePath := filepath.Join(installDir, "browser", "spitfire.exe")
|
||||||
if _, err := os.Stat(exePath); err != nil {
|
if _, err := os.Stat(exePath); err != nil {
|
||||||
return fmt.Errorf("browser executable not found at %s: %w", exePath, err)
|
return fmt.Errorf("browser executable not found at %s: %w", exePath, err)
|
||||||
|
@ -42,23 +44,29 @@ func RunAndWait() error {
|
||||||
cmd := exec.Command(exePath)
|
cmd := exec.Command(exePath)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = filepath.Join(installDir, "browser")
|
||||||
|
|
||||||
// Use CREATE_NEW_PROCESS_GROUP flag for Windows
|
// Create job object starting the process
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
job, err := windows.CreateJobObject(nil, nil)
|
||||||
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create job object: %w", err)
|
||||||
}
|
}
|
||||||
|
defer windows.CloseHandle(job)
|
||||||
|
|
||||||
fmt.Printf("Starting browser: %s\n", exePath)
|
fmt.Printf("Starting browser: %s\n", exePath)
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return fmt.Errorf("failed to start browser: %w", err)
|
return fmt.Errorf("failed to start browser: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Browser process started with PID %d\n", cmd.Process.Pid)
|
for {
|
||||||
|
cmd := exec.Command("tasklist", "/FI", "IMAGENAME eq spitfire.exe")
|
||||||
if err := cmd.Wait(); err != nil {
|
output, _ := cmd.Output()
|
||||||
return fmt.Errorf("browser exited with error: %w", err)
|
if !strings.Contains(string(output), "spitfire.exe") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Browser exited successfully.")
|
fmt.Println("Browser exited.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue