Documentation
¶
Overview ¶
Package system provides internal system-level utilities for macgo.
Index ¶
- Constants
- func AllMacgoEnvVars() []string
- func CalculateFileSHA256(filePath string) (string, error)
- func CleanAppName(name string) string
- func ClearAllMacgoEnv()
- func CompareFileSHA256(filePath, expectedHash string) (bool, error)
- func CopyFile(src, dst string) error
- func DirExists(path string) bool
- func EnsureDir(path string, perm os.FileMode) error
- func ExtractAppNameFromPath(execPath string) string
- func FileExists(path string) bool
- func GetBool(key string) bool
- func GetBundleContentsPath(bundlePath string) string
- func GetBundleEntitlementsPath(bundlePath string) string
- func GetBundleExecutablePath(bundlePath, execName string) string
- func GetBundleID(bundlePath string) string
- func GetBundleInfoPlistPath(bundlePath string) string
- func GetEnabledPermissions() []string
- func GetInt(key string, defaultValue int) int
- func GetLaunchMode() string
- func GetMacgoEnvSnapshot() map[string]string
- func GetPermissionFlags() map[string]bool
- func GetString(key, defaultValue string) string
- func GetStringSlice(key string) []string
- func HasAnyPermissionFlags() bool
- func InferBundleID(appName string) string
- func IsAppBundle(path string) bool
- func IsDebugEnabled() bool
- func IsInAppBundle() bool
- func IsRelaunchDisabled() bool
- func IsResetPermissionsEnabled() bool
- func LimitAppNameLength(name string, maxLength int) string
- func RestoreEnv(saved map[string]string)
- func SafeWriteFile(filename string, data []byte, perm os.FileMode) error
- func SaveEnv(keys []string) map[string]string
- func SetBool(key string, value bool) error
- func ValidateAppName(name string) error
- func ValidateBundleID(bundleID string) error
- type MacOSVersion
- func (v MacOSVersion) IsAtLeast(major, minor, patch int) bool
- func (v MacOSVersion) IsSequoiaOrLater() bool
- func (v MacOSVersion) IsSonomaOrLater() bool
- func (v MacOSVersion) IsVenturaOrLater() bool
- func (v MacOSVersion) ReleaseName() string
- func (v MacOSVersion) String() string
- func (v MacOSVersion) UseSystemSettings() bool
Constants ¶
const ( // Core configuration EnvAppName = "MACGO_APP_NAME" EnvBundleID = "MACGO_BUNDLE_ID" EnvDebug = "MACGO_DEBUG" EnvKeepBundle = "MACGO_KEEP_BUNDLE" EnvVersion = "MACGO_VERSION" // Code signing EnvCodeSignIdentity = "MACGO_CODE_SIGN_IDENTITY" EnvAutoSign = "MACGO_AUTO_SIGN" EnvAdHocSign = "MACGO_AD_HOC_SIGN" // Launch behavior EnvNoRelaunch = "MACGO_NO_RELAUNCH" EnvForceLaunchServices = "MACGO_FORCE_LAUNCH_SERVICES" EnvForceDirectExecution = "MACGO_FORCE_DIRECT" // Permission flags EnvCamera = "MACGO_CAMERA" EnvMicrophone = "MACGO_MICROPHONE" EnvLocation = "MACGO_LOCATION" EnvFiles = "MACGO_FILES" EnvNetwork = "MACGO_NETWORK" EnvSandbox = "MACGO_SANDBOX" // TCC and permissions EnvResetPermissions = "MACGO_RESET_PERMISSIONS" // Testing and development EnvTestIntegration = "MACGO_TEST_INTEGRATION" )
Environment variable constants for macgo
Variables ¶
This section is empty.
Functions ¶
func AllMacgoEnvVars ¶
func AllMacgoEnvVars() []string
AllMacgoEnvVars returns a list of all known macgo environment variables.
func CalculateFileSHA256 ¶
CalculateFileSHA256 calculates the SHA256 hash of a file. Returns the hexadecimal string representation of the hash.
func CleanAppName ¶
CleanAppName removes problematic characters from app names. It replaces filesystem-problematic characters with hyphens and removes non-printable ASCII characters.
func ClearAllMacgoEnv ¶
func ClearAllMacgoEnv()
ClearAllMacgoEnv removes all macgo environment variables. Useful for testing to ensure clean state.
func CompareFileSHA256 ¶
CompareFileSHA256 compares the SHA256 hash of a file with an expected hash. Returns true if they match, false otherwise.
func CopyFile ¶
CopyFile copies a file from src to dst. It handles error cases gracefully and preserves file permissions.
func ExtractAppNameFromPath ¶
ExtractAppNameFromPath extracts a reasonable app name from an executable path.
func FileExists ¶
FileExists checks if a file exists and is not a directory.
func GetBool ¶
GetBool returns the boolean value of an environment variable. Returns true if the variable is set to "1", "true", "yes", or "on" (case-insensitive). Returns false otherwise.
func GetBundleContentsPath ¶
GetBundleContentsPath constructs the path to the Contents directory in an app bundle.
func GetBundleEntitlementsPath ¶
GetBundleEntitlementsPath constructs the path to the entitlements.plist in an app bundle.
func GetBundleExecutablePath ¶
GetBundleExecutablePath constructs the path to the executable inside an app bundle.
func GetBundleID ¶
GetBundleID extracts the bundle identifier from an app bundle's Info.plist
func GetBundleInfoPlistPath ¶
GetBundleInfoPlistPath constructs the path to the Info.plist in an app bundle.
func GetEnabledPermissions ¶
func GetEnabledPermissions() []string
GetEnabledPermissions returns a slice of permission names that are enabled via environment variables.
func GetInt ¶
GetInt returns the integer value of an environment variable. Returns the defaultValue if the variable is not set, empty, or cannot be parsed.
func GetLaunchMode ¶
func GetLaunchMode() string
GetLaunchMode determines the launch mode based on environment variables. Returns "launch_services", "direct", or "auto" (default).
func GetMacgoEnvSnapshot ¶
GetMacgoEnvSnapshot returns a snapshot of all current macgo environment variables.
func GetPermissionFlags ¶
GetPermissionFlags returns a map of permission names to their enabled status.
func GetString ¶
GetString returns the string value of an environment variable. Returns the defaultValue if the variable is not set or empty.
func GetStringSlice ¶
GetStringSlice returns a slice of strings from an environment variable. The value should be comma-separated. Empty values are filtered out.
func HasAnyPermissionFlags ¶
func HasAnyPermissionFlags() bool
HasAnyPermissionFlags returns true if any permission environment variables are set.
func InferBundleID ¶
InferBundleID creates a reasonable bundle ID from the Go module path and app name. It uses the module path from build info to create meaningful, unique bundle IDs that reflect the actual Go module and program name.
func IsAppBundle ¶
IsAppBundle checks if the given path appears to be an app bundle.
func IsDebugEnabled ¶
func IsDebugEnabled() bool
IsDebugEnabled checks if debug mode is enabled via environment variable.
func IsInAppBundle ¶
func IsInAppBundle() bool
IsInAppBundle checks if we're already running inside an app bundle. This is determined by checking if the executable path contains ".app/Contents/MacOS/".
func IsRelaunchDisabled ¶
func IsRelaunchDisabled() bool
IsRelaunchDisabled checks if app bundle relaunch is disabled.
func IsResetPermissionsEnabled ¶
func IsResetPermissionsEnabled() bool
IsResetPermissionsEnabled checks if TCC permission reset is enabled.
func LimitAppNameLength ¶
LimitAppNameLength truncates an app name to a reasonable length, reserving space for the .app extension.
func RestoreEnv ¶
RestoreEnv restores environment variables from a saved state. Use with SaveEnv for temporary environment modifications.
func SafeWriteFile ¶
SafeWriteFile writes data to a file safely by writing to a temporary file first, then moving it to the final location. This prevents partial writes in case of errors.
func SaveEnv ¶
SaveEnv saves current environment variable values for later restoration. Returns a map that can be passed to RestoreEnv.
func SetBool ¶
SetBool sets an environment variable to a boolean value. Sets to "1" for true, "0" for false.
func ValidateAppName ¶
ValidateAppName checks if an app name is reasonable for macOS.
func ValidateBundleID ¶
ValidateBundleID checks if a bundle ID follows Apple's naming conventions.
Types ¶
type MacOSVersion ¶
MacOSVersion represents a parsed macOS version
func GetMacOSVersion ¶
func GetMacOSVersion() (MacOSVersion, error)
GetMacOSVersion retrieves the current macOS version
func MustGetMacOSVersion ¶
func MustGetMacOSVersion() MacOSVersion
MustGetMacOSVersion retrieves the macOS version and panics on error This is useful for initialization code where the version must be available
func ParseMacOSVersion ¶
func ParseMacOSVersion(version string) (MacOSVersion, error)
ParseMacOSVersion parses a version string like "14.2.1" or "15.0"
func (MacOSVersion) IsAtLeast ¶
func (v MacOSVersion) IsAtLeast(major, minor, patch int) bool
IsAtLeast checks if this version is at least the specified version
func (MacOSVersion) IsSequoiaOrLater ¶
func (v MacOSVersion) IsSequoiaOrLater() bool
IsSequoiaOrLater returns true if running macOS 15 (Sequoia) or later
func (MacOSVersion) IsSonomaOrLater ¶
func (v MacOSVersion) IsSonomaOrLater() bool
IsSonomaOrLater returns true if running macOS 14 (Sonoma) or later
func (MacOSVersion) IsVenturaOrLater ¶
func (v MacOSVersion) IsVenturaOrLater() bool
IsVenturaOrLater returns true if running macOS 13 (Ventura) or later
func (MacOSVersion) ReleaseName ¶
func (v MacOSVersion) ReleaseName() string
ReleaseName returns the marketing name for the macOS version
func (MacOSVersion) String ¶
func (v MacOSVersion) String() string
String returns the version as a string
func (MacOSVersion) UseSystemSettings ¶
func (v MacOSVersion) UseSystemSettings() bool
UseSystemSettings returns true if this version uses "System Settings" instead of "System Preferences" (Ventura and later)