feat: wire gui instance start and delete confirmation

This commit is contained in:
QiuSW
2026-07-22 17:02:59 +08:00
parent 46578c8743
commit 176e3cdad2
12 changed files with 600 additions and 59 deletions
+7 -4
View File
@@ -50,15 +50,18 @@ func (s LaunchSpec) Normalize() (LaunchSpec, error) {
return LaunchSpec{}, fmt.Errorf("%w: user data dir must be absolute", ErrInvalidLaunchSpec)
}
target := strings.TrimSpace(s.TargetURL)
parsed, err := url.Parse(target)
if err != nil || parsed.Host == "" || parsed.User != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") {
return LaunchSpec{}, fmt.Errorf("%w: target URL must be absolute http or https", ErrInvalidLaunchSpec)
if target != "" {
parsed, err := url.Parse(target)
if err != nil || parsed.Host == "" || parsed.User != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") {
return LaunchSpec{}, fmt.Errorf("%w: target URL must be absolute http or https", ErrInvalidLaunchSpec)
}
target = parsed.String()
}
normalized := s
normalized.Executable = strings.TrimSpace(s.Executable)
normalized.UserDataDir = filepath.Clean(userDataDir)
normalized.ProfileDirectory = strings.TrimSpace(s.ProfileDirectory)
normalized.TargetURL = parsed.String()
normalized.TargetURL = target
normalized.ProxyServer = strings.TrimSpace(s.ProxyServer)
normalized.ExtraArgs = append([]string(nil), s.ExtraArgs...)
return normalized, nil
+11
View File
@@ -42,3 +42,14 @@ func TestLaunchSpecNormalizeRejectsUnsafeValues(t *testing.T) {
}
}
}
func TestLaunchSpecNormalizeAllowsAnEmptyTargetURL(t *testing.T) {
profile := filepath.Join(t.TempDir(), "profile")
normalized, err := (LaunchSpec{Kind: BrowserChrome, UserDataDir: profile}).Normalize()
if err != nil {
t.Fatal(err)
}
if normalized.TargetURL != "" {
t.Fatalf("target URL = %q, want empty", normalized.TargetURL)
}
}