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
fb79cc8d5c
commit
0137168c66
112 files changed
+18438
-2
No files matched your search
@@ -0,0 +1,41 @@
|
||||
//! `Helpers/Extensions/NSAppearance+Extension.swift`.
|
||||
|
||||
use objc2::rc::Retained;
|
||||
use objc2_app_kit::{NSAppearance, NSAppearanceNameAqua, NSAppearanceNameDarkAqua};
|
||||
|
||||
use super::os_color;
|
||||
use crate::ghostty::config::Config;
|
||||
|
||||
pub trait NSAppearanceExt {
|
||||
/// Returns true if the appearance is some kind of dark.
|
||||
fn is_dark(&self) -> bool;
|
||||
}
|
||||
|
||||
impl NSAppearanceExt for NSAppearance {
|
||||
fn is_dark(&self) -> bool {
|
||||
self.name().to_string().to_lowercase().contains("dark")
|
||||
}
|
||||
}
|
||||
|
||||
/// `NSAppearance(ghosttyConfig:)`: the desired NSAppearance for the Ghostty
|
||||
/// configuration (`window-theme`), if any.
|
||||
#[must_use]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn appearance_from_ghostty_config(config: &Config) -> Option<Retained<NSAppearance>> {
|
||||
let theme = config.window_theme()?;
|
||||
// SAFETY: reading AppKit's immutable appearance name constants.
|
||||
let (aqua, dark) = unsafe { (NSAppearanceNameAqua, NSAppearanceNameDarkAqua) };
|
||||
match theme.as_str() {
|
||||
"dark" => NSAppearance::appearanceNamed(dark),
|
||||
"light" => NSAppearance::appearanceNamed(aqua),
|
||||
"auto" => {
|
||||
let c = config.background_color();
|
||||
if os_color::is_light_color(c.red, c.green, c.blue) {
|
||||
NSAppearance::appearanceNamed(aqua)
|
||||
} else {
|
||||
NSAppearance::appearanceNamed(dark)
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user