Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Sources/macOS/SystemMac.swift3// Description: macOS system integration: the Services menu entry « Nouveau message SP Mail avec la sélection », the Dock menu (new message,4// unread count — a number, never a sender or a subject).5import AppKit6import SPMailCore7import SPMailSystem8import SwiftUI910/// The object behind the app's entry in the Services menu (declared under NSServices in Info.plist, message `newMessageWithSelection`).11@MainActor12final class ServicesProvider: NSObject {13 static let shared = ServicesProvider()1415 /// The selected text of any app becomes the body of a new message.16 @objc func newMessageWithSelection(_ pboard: NSPasteboard, userData: String, error: AutoreleasingUnsafeMutablePointer<NSString>) {17 guard let text = pboard.string(forType: .string)?.trimmingCharacters(in: .whitespacesAndNewlines), !text.isEmpty else {18 error.pointee = L("Aucun texte sélectionné.") as NSString19 return20 }21 AppRuntime.model.system.router.deliver(.compose(MailtoLink(body: String(text.prefix(200_000)))))22 }23}2425enum DockMenu {26 @MainActor27 static func make(_ app: AppModel, target: AnyObject, compose: Selector, open: Selector) -> NSMenu {28 let menu = NSMenu()29 if app.phase == .ready {30 let unread = BadgeMath.badge(inboxUnread: app.inboxUnread, prefs: app.system.push.prefs)31 let count = NSMenuItem(title: unread == 0 ? L("Aucun message non lu") : unread == 1 ? L("1 message non lu") : L("\(unread) messages non lus"), action: nil, keyEquivalent: "")32 count.isEnabled = false33 menu.addItem(count)34 menu.addItem(.separator())35 let new = NSMenuItem(title: L("Nouveau message"), action: compose, keyEquivalent: "")36 new.target = target37 menu.addItem(new)38 } else if app.phase == .locked {39 let locked = NSMenuItem(title: L("SP Mail est verrouillé"), action: nil, keyEquivalent: "")40 locked.isEnabled = false41 menu.addItem(locked)42 }43 let inbox = NSMenuItem(title: L("Ouvrir la boîte de réception"), action: open, keyEquivalent: "")44 inbox.target = target45 menu.addItem(inbox)46 return menu47 }48}49