Files
magpie/internal/gui/terminal_apps.go
T
Karenandyetone 2693cd8828 feat(gui): choose macOS session terminal (#241)
* feat(gui): choose macOS session terminal

* session terminal: build the darwin CLI without cgo, drop the dead macOS 11 path, and open Terminal when the .command default is not a terminal

- terminal_apps_darwin.go imports "C" but had no cgo tag, and terminal_apps_other.go was !darwin only, so `CGO_ENABLED=0 GOOS=darwin go build -tags nogui .` (make release-cli's darwin targets) failed with undefined discoverTerminals. The cgo file and its test are now darwin && cgo; the stub is !darwin || !cgo.
- magpie needs macOS 12 (LSMinimumSystemVersion, -mmacosx-version-min=12.0), so the macOS 11 branch (temp .command file, deprecated LSCopyApplicationURLsForURL, CFRelease) never ran; it is gone along with the CoreServices link.
- With no saved choice, a default .command handler that is not a listed terminal, or a failed lookup, now opens Terminal as before the PR instead of failing; Settings labels the system option "System default (Terminal)" then, and the unused "System default (unavailable)" string is dropped.
- session-terminal.test.cjs covers an editor as the default in Chromium and WebKit, en and zh, and is on the README's node --test line.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-09-30 02:36:12 +08:00

46 lines
1.2 KiB
Go

package gui
import "fmt"
const terminalBundleID = "com.apple.Terminal"
// terminalApp is an installed app that explicitly claims .command files.
type terminalApp struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
}
type terminalChoice struct {
ID string `json:"id"`
Name string `json:"name"`
}
type terminalDiscovery struct {
Apps []terminalApp `json:"apps"`
Default string `json:"default"`
}
// terminalOpenArgs chooses the app for one already validated resume script.
func terminalOpenArgs(choice string, found terminalDiscovery) ([]string, error) {
if choice == terminalBundleID {
return []string{"-a", "Terminal"}, nil
}
if choice == "" || choice == "system" {
for _, app := range found.Apps {
if app.ID == found.Default {
return []string{"-a", app.Path}, nil
}
}
// no default, or one that is not a terminal (an editor): Terminal,
// as before there was a choice
return []string{"-a", "Terminal"}, nil
}
for _, app := range found.Apps {
if app.ID == choice {
return []string{"-a", app.Path}, nil
}
}
return nil, fmt.Errorf("the selected terminal app %q is no longer available", choice)
}