Files
magpie/internal/gui/terminal_apps_darwin.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

31 lines
693 B
Go

//go:build darwin && cgo
package gui
/*
#cgo LDFLAGS: -framework AppKit -framework UniformTypeIdentifiers
#include <stdlib.h>
char *magpieTerminalAppsJSON(void);
*/
import "C"
import (
"encoding/json"
"errors"
"unsafe"
)
// discoverTerminals asks Launch Services for apps that claim .command files.
func discoverTerminals() (terminalDiscovery, error) {
raw := C.magpieTerminalAppsJSON()
if raw == nil {
return terminalDiscovery{}, errors.New("could not find apps for .command files")
}
defer C.free(unsafe.Pointer(raw))
var found terminalDiscovery
if err := json.Unmarshal([]byte(C.GoString(raw)), &found); err != nil {
return terminalDiscovery{}, err
}
return found, nil
}