mirror of
https://github.com/BigMarc/grammargem.git
synced 2026-10-13 17:01:55 +02:00
Native SwiftUI menu-bar app: global hotkey → capture selected text (AX API / clipboard fallback) → grammar (Harper) / local AI (MLX) → replace in place. Free/paid entitlement gate + Lemon Squeezy device-cap licensing, $0 marginal cost per user. Heavyweight engines behind protocol stubs so it builds out of the box. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
27 lines
918 B
Swift
27 lines
918 B
Swift
import Foundation
|
|
import AppKit
|
|
|
|
/// Reports the frontmost application so App-Aware mode switching can pick the
|
|
/// right Writing Mode. Pure local introspection — no network, no logging of content.
|
|
@MainActor
|
|
final class AppDetector {
|
|
struct FrontApp: Equatable {
|
|
let bundleID: String
|
|
let name: String
|
|
}
|
|
|
|
/// The app currently in the foreground (the one the hotkey will act on).
|
|
func frontmost() -> FrontApp? {
|
|
guard let app = NSWorkspace.shared.frontmostApplication else { return nil }
|
|
return FrontApp(
|
|
bundleID: app.bundleIdentifier ?? "unknown",
|
|
name: app.localizedName ?? "App")
|
|
}
|
|
|
|
/// The Writing Mode App-Aware would auto-apply for the current frontmost app.
|
|
func suggestedMode() -> WritingMode? {
|
|
guard let front = frontmost() else { return nil }
|
|
return ModeRegistry.mode(forBundleID: front.bundleID)
|
|
}
|
|
}
|