Mos/Components/Toast/README.md
Lightweight floating toast notification for macOS apps.
A modular, dependency-free component that displays non-intrusive, auto-dismissing notifications. Designed for menu bar apps and background utilities where system notifications are too heavy. Supports multiple simultaneous toasts, draggable positioning, and an interactive debug panel.
NSPanel with .nonactivatingPanel, never steals focusNSVisualEffectView with per-OS-version material selection.info, .success, .warning, .error with accent color indicators.fullScreenAuxiliary collection behaviorUserDefaults suite, not the host app's// Basic
Toast.show("Operation completed")
// With style
Toast.show("Settings saved", style: .success)
Toast.show("Device does not support this feature", style: .warning)
Toast.show("Connection failed", style: .error)
// Full customization
Toast.show("Custom message",
style: .info,
duration: 5.0,
icon: NSImage(named: "custom-icon"))
// Hide icon entirely
Toast.show("Plain message",
style: .warning,
showsIcon: false)
// Dismiss all visible toasts
Toast.dismissAll()
// Add debug panel to a menu (one line)
menu.addItem(Toast.debugMenuItem())
struct Toast {
enum Style: CaseIterable {
case info // Neutral, default icon
case success // Green accent
case warning // Orange accent
case error // Red accent
}
/// Show a toast notification.
static func show(_ message: String,
style: Style = .info,
duration: TimeInterval = 2.5,
icon: NSImage? = nil,
showsIcon: Bool = true)
/// Dismiss all visible toasts.
static func dismissAll()
/// Open the interactive debug panel.
static func showTestPanel()
/// Create a self-contained NSMenuItem for the debug panel.
/// Target, action, icon, and title are all built-in.
static func debugMenuItem() -> NSMenuItem
}
Toast/ directory
├── Toast.swift Public API (show, dismissAll, showTestPanel, debugMenuItem)
├── ToastManager.swift Multi-toast lifecycle, stacking, dedup, eviction
├── ToastWindow.swift Container NSPanel, drag-to-reposition, hit-test passthrough
├── ToastContentView.swift Visual rendering (frosted glass, icon, label, accent)
├── ToastStorage.swift Independent UserDefaults persistence
└── ToastPanel.swift Product-grade debug panel (NSObject, menu target)
Dependency flow: Toast → ToastManager → ToastWindow → ToastContentView, ToastManager → ToastStorage, ToastPanel → Toast (public API)
All types except Toast are internal -- consumers only interact with the Toast struct.
| macOS Version | Material | Icons |
|---|---|---|
| 10.13 | .dark | System built-in (NSImage.cautionName, etc.) |
| 10.14+ | .hudWindow + .vibrantDark | System built-in |
| 11.0+ | .hudWindow + .vibrantDark | SF Symbols |
Call Toast.showTestPanel() or add Toast.debugMenuItem() to a menu. The panel provides:
Configuration:
Send Toast:
Quick Tests:
Copy the Toast/ directory into any macOS project. No frameworks, no packages, no configuration. Persistence uses UserDefaults(suiteName: "\(bundleID).toast") so it won't conflict with your app's settings.
Part of the Mos project. Licensed under CC BY-NC 4.0.