mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
2861fd90ab
* fix(launcher): hide console flashes in all Windows child processes PR #2654 only applied HideWindow to child processes in gateway.go (powershell, tasklist, ps). Several other files still use exec.Command directly, causing visible console windows on Windows. - startup.go: reg query/add/delete for autostart registry - version.go: picoclaw version subcommand - runtime.go: rundll32 for browser launch - onboard.go: picoclaw onboard subcommand Add launcherExecCommand to the utils package (matching the api package pattern) and replace all bare exec.Command calls on Windows paths. * refactor: consolidate launcherExecCommand into utils package Export LauncherExecCommand and ApplyLauncherProcAttrs from the utils package as the single source of truth. The api package now imports and delegates to these exported functions, eliminating code duplication. Addresses review feedback from imguoguo on PR #3061.
44 lines
946 B
Go
44 lines
946 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
var execCommand = LauncherExecCommand
|
|
|
|
func EnsureOnboarded(configPath string) error {
|
|
_, err := os.Stat(configPath)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if !os.IsNotExist(err) {
|
|
return fmt.Errorf("stat config: %w", err)
|
|
}
|
|
|
|
cmd := execCommand(FindPicoclawBinary(), "onboard")
|
|
cmd.Env = append(os.Environ(), config.EnvConfig+"="+configPath)
|
|
cmd.Stdin = strings.NewReader("n\n")
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
trimmed := strings.TrimSpace(string(output))
|
|
if trimmed == "" {
|
|
return fmt.Errorf("run onboard: %w", err)
|
|
}
|
|
return fmt.Errorf("run onboard: %w: %s", err, trimmed)
|
|
}
|
|
|
|
if _, err := os.Stat(configPath); err != nil {
|
|
if os.IsNotExist(err) {
|
|
return fmt.Errorf("onboard completed but did not create config %s", configPath)
|
|
}
|
|
return fmt.Errorf("verify config after onboard: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|