feat(macos): foundation of the macOS app ported from Swift to Rust
Phase 9, MA1: crates/ghostty-macos (AppKit via objc2; empty stub on non-Apple targets) ports the foundation of Ghostty 1.3.1's Swift macOS app (ghostty/macos): main, AppDelegate (+Ghostty) with lifecycle, dock menu, open-file, notifications, shortcut sync and quit/reopen paths; MainMenu.xib as generated menu tables built into NSMenus; the Ghostty.App/Config/Surface wrappers driving libghostty in-process via ghostty-lib; the generic helpers; scripts/macos-bundle.sh to assemble Ghostty.app (dry-run on Linux). Feature areas are stubbed for MA2-MA5. Design and type mapping: docs/rewrite/notes/macos-app-design.md (App Intents is a Swift-only framework and cannot be ported). Compile-checked only (no macOS here): just check-macos passes for aarch64/x86_64-apple-darwin with -D warnings; 125 platform-independent tests run on Linux. Test Plan: - just check-macos - cargo test -p ghostty-macos
This commit is contained in:
1 parent
feacba2d69
commit
4861015105
112 files changed
+18438
-2
No files matched your search
@@ -0,0 +1,58 @@
|
||||
//! Uniform type identifier lookups shared by `NSPasteboard+Extension` and
|
||||
//! `NSWorkspace+Extension` (Swift uses `UTType(mimeType:)`,
|
||||
//! `UTType(filenameExtension:)`, `UTType.plainText`, `.unixExecutable`).
|
||||
//!
|
||||
//! `UniformTypeIdentifiers.UTType` is a Swift-first API; the CoreServices C
|
||||
//! functions below give the same identifiers.
|
||||
|
||||
// SAFETY: every `unsafe` block in this module carries its own justification (FFI / objc2 calls).
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use objc2_core_foundation::{CFRetained, CFString};
|
||||
|
||||
#[link(name = "CoreServices", kind = "framework")]
|
||||
unsafe extern "C" {
|
||||
static kUTTagClassFilenameExtension: &'static CFString;
|
||||
static kUTTagClassMIMEType: &'static CFString;
|
||||
fn UTTypeCreatePreferredIdentifierForTag(
|
||||
tag_class: &CFString,
|
||||
tag: &CFString,
|
||||
conforming_to_uti: Option<&CFString>,
|
||||
) -> *const CFString;
|
||||
}
|
||||
|
||||
/// `UTType.plainText.identifier`.
|
||||
pub const PLAIN_TEXT: &str = "public.plain-text";
|
||||
/// `UTType.unixExecutable.identifier`.
|
||||
pub const UNIX_EXECUTABLE: &str = "public.unix-executable";
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn identifier_for_tag(class: &CFString, tag: &str) -> Option<String> {
|
||||
let tag = CFString::from_str(tag);
|
||||
// SAFETY: both arguments are valid CFStrings; the result is +1 retained
|
||||
// or null and adopted by `CFRetained`.
|
||||
let raw = unsafe { UTTypeCreatePreferredIdentifierForTag(class, &tag, None) };
|
||||
let raw = std::ptr::NonNull::new(raw.cast_mut())?;
|
||||
// SAFETY: see above, ownership transferred.
|
||||
let s: CFRetained<CFString> = unsafe { CFRetained::from_raw(raw) };
|
||||
Some(s.to_string())
|
||||
}
|
||||
|
||||
/// `UTType(filenameExtension:)?.identifier` (unknown extensions yield a
|
||||
/// `dyn.*` identifier like `UTType` does).
|
||||
#[allow(unsafe_code)]
|
||||
#[must_use]
|
||||
pub fn identifier_for_extension(ext: &str) -> Option<String> {
|
||||
// SAFETY: reading an immutable constant exported by CoreServices.
|
||||
identifier_for_tag(unsafe { kUTTagClassFilenameExtension }, ext)
|
||||
}
|
||||
|
||||
/// `UTType(mimeType:)?.identifier`. Identifiers CoreServices makes up for
|
||||
/// undeclared types (`dyn.*`) are reported as `None`, so callers use their
|
||||
/// "unknown MIME type" fallback.
|
||||
#[allow(unsafe_code)]
|
||||
#[must_use]
|
||||
pub fn identifier_for_mime_type(mime: &str) -> Option<String> {
|
||||
// SAFETY: reading an immutable constant exported by CoreServices.
|
||||
identifier_for_tag(unsafe { kUTTagClassMIMEType }, mime).filter(|id| !id.starts_with("dyn."))
|
||||
}
|
||||
Reference in new issue
Block a user