use ferrokit_core::kept::{UiCell, UiLocal};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use block2::RcBlock;
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, Bool, NSObject, NSObjectProtocol, ProtocolObject};
use objc2::{AnyThread, DefinedClass, MainThreadOnly, define_class, msg_send, sel};
use objc2_app_kit::{NSButton, NSImage, NSPrintInfo, NSPrintOperation, NSPrintingPaginationMode, NSSharingServicePicker, NSView, NSWindow};
use objc2_foundation::{NSArray, NSBundle, NSError, NSOperationQueue, NSRectEdge, NSSize, NSString, NSURL};
use objc2_user_notifications::{
UNAuthorizationOptions, UNMutableNotificationContent, UNNotification, UNNotificationPresentationOptions, UNNotificationRequest, UNNotificationResponse,
UNNotificationSound, UNUserNotificationCenter, UNUserNotificationCenterDelegate,
};
use crate::appkit_views::ActionTarget;
use crate::view::{AnyView, Cx, Node, Size, View};
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum ShareItem {
Text(String),
Url(String),
File(PathBuf),
}
pub(crate) fn share_objects(items: &[ShareItem]) -> Retained<NSArray<AnyObject>> {
let objects: Vec<Retained<AnyObject>> = items
.iter()
.filter_map(|i| match i {
ShareItem::Text(t) => Some(Retained::into_super(Retained::into_super(NSString::from_str(t)))),
ShareItem::Url(u) => NSURL::URLWithString(&NSString::from_str(u)).map(|u| Retained::into_super(Retained::into_super(u))),
ShareItem::File(p) => Some(Retained::into_super(Retained::into_super(NSURL::fileURLWithPath(&NSString::from_str(&p.to_string_lossy()))))),
})
.collect();
NSArray::from_retained_slice(&objects)
}
pub struct ShareButton {
items: Items,
title: Option<String>,
}
impl ShareButton {
pub fn title(mut self, title: &str) -> Self {
self.title = Some(title.into());
self
}
}
type Items = Rc<dyn Fn() -> Vec<ShareItem>>;
thread_local! {
static SHARES: UiCell<Vec<(objc2::rc::Weak<NSButton>, Items)>> = const { UiCell::new(Vec::new()) };
}
pub(crate) fn shared_by(button: &NSButton) -> Option<Vec<ShareItem>> {
let f = SHARES.with_borrow(|s| s.iter().find(|(b, _)| b.load().is_some_and(|b| std::ptr::eq(&*b, button))).map(|(_, f)| f.clone()))?;
Some(f())
}
impl View for ShareButton {
fn build(self, cx: &mut Cx) -> Node {
let mtm = cx.mtm;
let image = NSImage::imageWithSystemSymbolName_accessibilityDescription(&NSString::from_str("square.and.arrow.up"), Some(&NSString::from_str("Share")));
let button = match (&self.title, image) {
(None, Some(img)) => {
unsafe { NSButton::buttonWithImage_target_action(&img, None, None, mtm) }
}
(title, _) => {
unsafe { NSButton::buttonWithTitle_target_action(&NSString::from_str(title.as_deref().unwrap_or("Share…")), None, None, mtm) }
}
};
let picker: Rc<RefCell<Option<Retained<NSSharingServicePicker>>>> = Rc::default();
let (items, b, held) = (self.items.clone(), objc2::rc::Weak::from_retained(&button), picker.clone());
let target = ActionTarget::new(mtm, move || {
let Some(b) = b.load() else { return };
let p = unsafe { NSSharingServicePicker::initWithItems(NSSharingServicePicker::alloc(), &share_objects(&items())) };
p.showRelativeToRect_ofView_preferredEdge(b.bounds(), &b, NSRectEdge::MinY);
*held.borrow_mut() = Some(p);
});
unsafe {
button.setTarget(Some(&target));
button.setAction(Some(sel!(fire:)));
}
SHARES.with_borrow_mut(|s| {
s.retain(|(b, _)| b.load().is_some());
s.push((objc2::rc::Weak::from_retained(&button), self.items));
});
let (mut node, _) = Node::leaf(cx, Retained::into_super(Retained::into_super(button)), (false, false), Size::default());
node.keep(Retained::into_super(target));
node.hold(picker);
node
}
}
pub fn share_button(items: impl Fn() -> Vec<ShareItem> + 'static) -> ShareButton {
ShareButton { items: Rc::new(items), title: None }
}
fn printable(view: AnyView, info: &NSPrintInfo) -> Retained<NSView> {
let paper = info.paperSize();
let width = (paper.width - info.leftMargin() - info.rightMargin()).max(100.0);
let (root, size) = crate::host_view(view);
if let Some(light) = objc2_app_kit::NSAppearance::appearanceNamed(unsafe { objc2_app_kit::NSAppearanceNameAqua }) {
objc2_app_kit::NSAppearanceCustomization::setAppearance(&*root, Some(&light));
}
crate::signal::run_pending();
let height = crate::hosted_ideal(&root).map_or(size.height, |s| s.height);
root.setFrameSize(NSSize::new(width, height));
crate::signal::run_pending();
root
}
fn print_info() -> Retained<NSPrintInfo> {
let info = NSPrintInfo::sharedPrintInfo();
let info: Retained<NSPrintInfo> = unsafe { msg_send![&*info, copy] };
if info.leftMargin() < 18.0 {
info.setLeftMargin(36.0);
info.setRightMargin(36.0);
}
if info.topMargin() < 18.0 {
info.setTopMargin(36.0);
info.setBottomMargin(36.0);
}
info.setHorizontalPagination(NSPrintingPaginationMode::Fit);
info.setVerticalPagination(NSPrintingPaginationMode::Automatic);
info.setHorizontallyCentered(false);
info.setVerticallyCentered(false);
info
}
define_class!(
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[name = "FerrokitPrintDone"]
#[ivars = RefCell<Option<Retained<NSView>>>]
struct PrintDone;
impl PrintDone {
#[unsafe(method(printOperationDidRun:success:contextInfo:))]
fn done(&self, _op: &NSPrintOperation, _ok: Bool, _info: *mut std::ffi::c_void) {
if let Some(root) = self.ivars().borrow_mut().take() {
crate::drop_hosted(&root);
}
PRINTING.with_borrow_mut(|p| p.retain(|d| !std::ptr::eq(&**d, self)));
}
}
);
thread_local! {
static PRINTING: UiCell<Vec<Retained<PrintDone>>> = const { UiCell::new(Vec::new()) };
}
pub fn print(window: &NSWindow, title: &str, view: impl View) {
let info = print_info();
let root = printable(AnyView::new(view), &info);
let op = NSPrintOperation::printOperationWithView_printInfo(&root, &info);
op.setJobTitle(Some(&NSString::from_str(title)));
let done = PrintDone::alloc(crate::mtm()).set_ivars(RefCell::new(Some(root)));
let done: Retained<PrintDone> = unsafe { msg_send![super(done), init] };
PRINTING.with_borrow_mut(|p| p.push(done.clone()));
unsafe { op.runOperationModalForWindow_delegate_didRunSelector_contextInfo(window, Some(&done), Some(sel!(printOperationDidRun:success:contextInfo:)), std::ptr::null_mut()) };
}
pub fn save_pdf(view: impl View, path: impl AsRef<Path>) -> std::io::Result<()> {
let path = std::path::absolute(path)?;
let info = print_info();
unsafe {
info.setJobDisposition(objc2_app_kit::NSPrintSaveJob);
let url = NSURL::fileURLWithPath(&NSString::from_str(&path.to_string_lossy()));
info.dictionary().setObject_forKey(&*url, objc2::runtime::ProtocolObject::from_ref(objc2_app_kit::NSPrintJobSavingURL));
}
let root = printable(AnyView::new(view), &info);
let op = NSPrintOperation::printOperationWithView_printInfo(&root, &info);
op.setShowsPrintPanel(false);
op.setShowsProgressPanel(false);
let ok = op.runOperation();
crate::drop_hosted(&root);
if ok && path.exists() { Ok(()) } else { Err(std::io::Error::other("printing to PDF failed")) }
}
pub fn pdf_data(view: impl View) -> Vec<u8> {
thread_local!(static N: Cell<u32> = const { Cell::new(0) });
let n = N.with(|c| c.replace(c.get() + 1));
let path = std::env::temp_dir().join(format!("ferrokit-print-{}-{n}.pdf", std::process::id()));
let data = save_pdf(view, &path).and_then(|()| std::fs::read(&path)).unwrap_or_default();
let _ = std::fs::remove_file(&path);
data
}
pub struct Notification {
id: String,
title: String,
subtitle: String,
body: String,
sound: bool,
daily: Option<(u32, u32)>,
on_click: Option<Rc<dyn Fn()>>,
}
impl Notification {
pub fn new(title: &str) -> Self {
thread_local!(static NEXT: Cell<u64> = const { Cell::new(1) });
let n = NEXT.with(|c| c.replace(c.get() + 1));
Notification { id: format!("ferrokit-{n}"), title: title.into(), subtitle: String::new(), body: String::new(), sound: false, daily: None, on_click: None }
}
pub fn subtitle(mut self, text: &str) -> Self {
self.subtitle = text.into();
self
}
pub fn body(mut self, text: &str) -> Self {
self.body = text.into();
self
}
pub fn sound(mut self) -> Self {
self.sound = true;
self
}
pub fn id(mut self, id: &str) -> Self {
self.id = id.into();
self
}
pub fn daily_at(mut self, hour: u32, minute: u32) -> Self {
self.daily = Some((hour.min(23), minute.min(59)));
self
}
pub fn on_click(mut self, action: impl Fn() + 'static) -> Self {
self.on_click = Some(Rc::new(crate::signal::with_current_owner(action)));
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SentNotification {
pub id: String,
pub title: String,
pub subtitle: String,
pub body: String,
pub sound: bool,
pub daily: Option<(u32, u32)>,
}
thread_local! {
static CLICKS: UiCell<HashMap<String, Rc<dyn Fn()>>> = UiCell::new(HashMap::new());
static DELEGATE: UiCell<Option<Retained<NotificationDelegate>>> = const { UiCell::new(None) };
pub(crate) static HOLD: Cell<bool> = const { Cell::new(false) };
pub(crate) static SENT: UiCell<Vec<SentNotification>> = const { UiCell::new(Vec::new()) };
}
define_class!(
#[unsafe(super(NSObject))]
#[name = "FerrokitNotifications"]
struct NotificationDelegate;
unsafe impl NSObjectProtocol for NotificationDelegate {}
unsafe impl UNUserNotificationCenterDelegate for NotificationDelegate {
#[unsafe(method(userNotificationCenter:willPresentNotification:withCompletionHandler:))]
fn will_present(&self, _c: &UNUserNotificationCenter, _n: &UNNotification, done: &block2::DynBlock<dyn Fn(UNNotificationPresentationOptions)>) {
done.call((UNNotificationPresentationOptions::Banner | UNNotificationPresentationOptions::List | UNNotificationPresentationOptions::Sound,));
}
#[unsafe(method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:))]
fn received(&self, _c: &UNUserNotificationCenter, response: &UNNotificationResponse, done: &block2::DynBlock<dyn Fn()>) {
let id = response.notification().request().identifier().to_string();
let block = RcBlock::new(move || {
crate::failure::guard("a notification's click", false, || click(&id));
});
unsafe { NSOperationQueue::mainQueue().addOperationWithBlock(&block) };
done.call(());
}
}
);
pub(crate) fn click(id: &str) -> bool {
let action = CLICKS.with_borrow(|c| c.get(id).cloned());
if let Some(a) = &action {
crate::signal::batch(|| a());
}
action.is_some()
}
pub fn notifications_supported() -> bool {
NSBundle::mainBundle().bundleIdentifier().is_some()
}
pub fn notify(notification: Notification) {
if let Some(a) = ¬ification.on_click {
CLICKS.with_borrow_mut(|c| c.insert(notification.id.clone(), a.clone()));
}
if HOLD.with(Cell::get) {
let n = ¬ification;
SENT.with_borrow_mut(|s| s.retain(|old| old.id != n.id));
SENT.with_borrow_mut(|s| s.push(SentNotification { id: n.id.clone(), title: n.title.clone(), subtitle: n.subtitle.clone(), body: n.body.clone(), sound: n.sound, daily: n.daily }));
return;
}
if !notifications_supported() {
return;
}
let center = UNUserNotificationCenter::currentNotificationCenter();
DELEGATE.with_borrow_mut(|d| {
if d.is_none() {
let delegate: Retained<NotificationDelegate> = unsafe { msg_send![NotificationDelegate::alloc(), init] };
center.setDelegate(Some(ProtocolObject::from_ref(&*delegate)));
*d = Some(delegate);
}
});
let content = UNMutableNotificationContent::new();
content.setTitle(&NSString::from_str(¬ification.title));
content.setSubtitle(&NSString::from_str(¬ification.subtitle));
content.setBody(&NSString::from_str(¬ification.body));
if notification.sound {
content.setSound(Some(&UNNotificationSound::defaultSound()));
}
let trigger = notification.daily.map(|(hour, minute)| {
let when = objc2_foundation::NSDateComponents::new();
when.setHour(hour as isize);
when.setMinute(minute as isize);
Retained::into_super(objc2_user_notifications::UNCalendarNotificationTrigger::triggerWithDateMatchingComponents_repeats(&when, true))
});
let request = UNNotificationRequest::requestWithIdentifier_content_trigger(&NSString::from_str(¬ification.id), &content, trigger.as_deref());
let block = RcBlock::new(move |granted: Bool, _e: *mut NSError| {
if granted.as_bool() {
UNUserNotificationCenter::currentNotificationCenter().addNotificationRequest_withCompletionHandler(&request, None);
}
});
center.requestAuthorizationWithOptions_completionHandler(UNAuthorizationOptions::Alert | UNAuthorizationOptions::Sound, &block);
}
pub fn cancel_notification(id: &str) {
CLICKS.with_borrow_mut(|c| c.remove(id));
if HOLD.with(Cell::get) {
SENT.with_borrow_mut(|s| s.retain(|n| n.id != id));
return;
}
if !notifications_supported() {
return;
}
let center = UNUserNotificationCenter::currentNotificationCenter();
let ids = NSArray::from_retained_slice(&[NSString::from_str(id)]);
center.removePendingNotificationRequestsWithIdentifiers(&ids);
center.removeDeliveredNotificationsWithIdentifiers(&ids);
}
thread_local! {
static REVEALS: UiCell<Option<Vec<Vec<PathBuf>>>> = const { UiCell::new(None) };
}
pub(crate) fn capture_reveals(on: bool) {
REVEALS.with_borrow_mut(|r| *r = on.then(Vec::new));
}
pub(crate) fn take_reveals() -> Vec<Vec<PathBuf>> {
REVEALS.with_borrow_mut(|r| r.as_mut().map(std::mem::take).unwrap_or_default())
}
pub fn reveal_in_finder<P: AsRef<Path>>(paths: &[P]) {
let paths: Vec<PathBuf> = paths.iter().map(|p| p.as_ref().to_path_buf()).collect();
if REVEALS.with_borrow_mut(|r| r.as_mut().map(|r| r.push(paths.clone())).is_some()) {
return;
}
let urls: Vec<Retained<NSURL>> = paths.iter().map(|p| NSURL::fileURLWithPath(&NSString::from_str(&p.to_string_lossy()))).collect();
objc2_app_kit::NSWorkspace::sharedWorkspace().activateFileViewerSelectingURLs(&NSArray::from_retained_slice(&urls));
}
pub fn move_to_trash(path: impl AsRef<Path>) -> std::io::Result<PathBuf> {
let path = path.as_ref();
if std::fs::symlink_metadata(path).is_err() {
return Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("{} doesn't exist", path.display())));
}
let url = NSURL::fileURLWithPath(&NSString::from_str(&path.to_string_lossy()));
let mut result: Option<Retained<NSURL>> = None;
objc2_foundation::NSFileManager::defaultManager()
.trashItemAtURL_resultingItemURL_error(&url, Some(&mut result))
.map_err(|e| std::io::Error::other(e.localizedDescription().to_string()))?;
result.and_then(|u| u.path()).map(|p| PathBuf::from(p.to_string())).ok_or_else(|| std::io::Error::other("the Trash didn't say where the item went"))
}
pub fn open_url(url: &str) -> bool {
match NSURL::URLWithString(&NSString::from_str(url)) {
Some(url) => objc2_app_kit::NSWorkspace::sharedWorkspace().openURL(&url),
None => false,
}
}
pub const FULL_DISK_ACCESS_SETTINGS: &str = "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles";
pub fn has_full_disk_access() -> bool {
real_home().is_some_and(|h| std::fs::File::open(h.join("Library/Application Support/com.apple.TCC/TCC.db")).is_ok())
}
pub fn asks_before_reading(path: impl AsRef<Path>, full_disk_access: bool) -> bool {
real_home().is_some_and(|home| asks(path.as_ref(), &home, full_disk_access))
}
fn asks(path: &Path, home: &Path, full_disk_access: bool) -> bool {
const MEDIA: [&str; 5] = ["Music/Music", "Music/iTunes", "Music/GarageBand", "Movies/TV", "Pictures/Photo Booth Library"];
const LIBRARIES: [&str; 4] = ["photoslibrary", "photolibrary", "musiclibrary", "tvlibrary"];
if MEDIA.iter().any(|m| path.starts_with(home.join(m))) || path.components().any(|c| Path::new(c.as_os_str()).extension().is_some_and(|e| LIBRARIES.iter().any(|l| e.eq_ignore_ascii_case(l)))) {
return true;
}
if full_disk_access {
return false;
}
const PROTECTED: [&str; 5] = ["Desktop", "Documents", "Downloads", ".Trash", "Library"];
PROTECTED.iter().any(|p| path.starts_with(home.join(p))) || (path.starts_with("/Volumes") && path.components().count() > 2 && !is_boot_volume(path))
}
fn is_boot_volume(path: &Path) -> bool {
let volume: PathBuf = path.components().take(3).collect();
std::fs::canonicalize(&volume).is_ok_and(|v| v == Path::new("/"))
}
fn real_home() -> Option<PathBuf> {
use std::os::unix::ffi::OsStrExt;
unsafe {
let mut pw: libc::passwd = std::mem::zeroed();
let mut buf = vec![0 as libc::c_char; 4096];
let mut out: *mut libc::passwd = std::ptr::null_mut();
if libc::getpwuid_r(libc::getuid(), &mut pw, buf.as_mut_ptr(), buf.len(), &mut out) != 0 || out.is_null() || pw.pw_dir.is_null() {
return None;
}
Some(PathBuf::from(std::ffi::OsStr::from_bytes(std::ffi::CStr::from_ptr(pw.pw_dir).to_bytes())))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct FileDates {
pub modified: Option<std::time::SystemTime>,
pub created: Option<std::time::SystemTime>,
pub added: Option<std::time::SystemTime>,
pub last_opened: Option<std::time::SystemTime>,
}
pub fn file_dates(path: impl AsRef<Path>) -> std::io::Result<FileDates> {
use std::os::unix::ffi::OsStrExt;
let path = path.as_ref();
let meta = std::fs::symlink_metadata(path)?;
let c = std::ffi::CString::new(path.as_os_str().as_bytes()).map_err(std::io::Error::other)?;
let at = |secs: i64| (secs > 0).then(|| std::time::UNIX_EPOCH + std::time::Duration::from_secs(secs as u64));
Ok(FileDates { modified: meta.modified().ok(), created: meta.created().ok(), added: date_added(&c).and_then(at), last_opened: last_opened(&c).and_then(at) })
}
const LAST_USED: &std::ffi::CStr = c"com.apple.lastuseddate#PS";
fn last_opened(path: &std::ffi::CStr) -> Option<i64> {
let mut value = [0u8; 16];
let n = unsafe { libc::getxattr(path.as_ptr(), LAST_USED.as_ptr(), value.as_mut_ptr().cast(), value.len(), 0, libc::XATTR_NOFOLLOW) };
(n >= 8).then(|| i64::from_le_bytes(value[..8].try_into().expect("8 bytes")))
}
fn date_added(path: &std::ffi::CStr) -> Option<i64> {
#[repr(C, packed(4))]
struct Reply {
length: u32,
added: libc::timespec,
}
let mut list: libc::attrlist = unsafe { std::mem::zeroed() };
list.bitmapcount = libc::ATTR_BIT_MAP_COUNT;
list.commonattr = libc::ATTR_CMN_ADDEDTIME;
let mut reply: Reply = unsafe { std::mem::zeroed() };
let r = unsafe { libc::getattrlist(path.as_ptr(), (&raw mut list).cast(), (&raw mut reply).cast(), size_of::<Reply>(), libc::FSOPT_NOFOLLOW) };
let (length, secs) = (reply.length, reply.added.tv_sec);
(r == 0 && length as usize >= size_of::<Reply>()).then_some(secs)
}
pub(crate) fn set_last_opened(path: &Path, secs: Option<i64>) -> std::io::Result<()> {
use std::os::unix::ffi::OsStrExt;
let c = std::ffi::CString::new(path.as_os_str().as_bytes()).map_err(std::io::Error::other)?;
let r = match secs {
Some(s) => {
let mut value = [0u8; 16];
value[..8].copy_from_slice(&s.to_le_bytes());
unsafe { libc::setxattr(c.as_ptr(), LAST_USED.as_ptr(), value.as_ptr().cast(), value.len(), 0, libc::XATTR_NOFOLLOW) }
}
None => unsafe { libc::removexattr(c.as_ptr(), LAST_USED.as_ptr(), libc::XATTR_NOFOLLOW) },
};
if r == 0 { Ok(()) } else { Err(std::io::Error::last_os_error()) }
}
#[cfg(test)]
mod file_tests {
use super::*;
#[test]
fn dates_of_a_file() {
let dir = std::env::temp_dir().join(format!("ferrokit-dates-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let file = dir.join("a.txt");
std::fs::write(&file, "a").unwrap();
let fresh = file_dates(&file).unwrap();
let now = std::time::SystemTime::now();
let recent = |t: Option<std::time::SystemTime>| t.is_some_and(|t| now.duration_since(t).map_or(true, |d| d.as_secs() < 60));
assert!(recent(fresh.modified) && recent(fresh.created) && recent(fresh.added), "{fresh:?}");
assert_eq!(fresh.last_opened, None);
set_last_opened(&file, Some(1_600_000_000)).unwrap();
assert_eq!(file_dates(&file).unwrap().last_opened, Some(std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_600_000_000)));
assert!(file_dates(dir.join("missing")).is_err());
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn reveals_are_captured() {
capture_reveals(true);
reveal_in_finder(&["/tmp/a", "/tmp/b"]);
assert_eq!(take_reveals(), vec![vec![PathBuf::from("/tmp/a"), PathBuf::from("/tmp/b")]]);
capture_reveals(false);
}
#[test]
fn trashing_a_missing_file_fails() {
assert_eq!(move_to_trash("/nonexistent/ferrokit-nothing").unwrap_err().kind(), std::io::ErrorKind::NotFound);
}
}
#[cfg(test)]
mod access_tests {
use super::*;
#[test]
fn folders_that_ask() {
let home = Path::new("/Users/someone");
let asks = |p: &str, fda: bool| asks(Path::new(p), home, fda);
for p in ["/Users/someone/Documents", "/Users/someone/Desktop/a", "/Users/someone/Downloads", "/Users/someone/.Trash", "/Users/someone/Library/Containers/x", "/Volumes/Backup/photos"] {
assert!(asks(p, false), "{p} asks without access");
assert!(!asks(p, true), "{p} is readable with access");
}
for p in ["/Users/someone", "/Users/someone/Projects/app", "/Users/someone/DocumentsOld", "/Applications", "/Library/Fonts", "/Volumes"] {
assert!(!asks(p, false), "{p} doesn't ask");
}
for p in ["/Users/someone/Music/Music", "/Users/someone/Music/GarageBand/x", "/Users/someone/Movies/TV", "/Users/someone/Pictures/Photo Booth Library", "/Users/someone/Pictures/Photos Library.photoslibrary", "/Users/someone/Projects/Old.PhotosLibrary/masters"] {
assert!(asks(p, true), "{p} asks even with access");
}
assert!(!asks("/Users/someone/Music/Loops", true));
assert!(real_home().is_some_and(|h| h.is_absolute()));
let _ = has_full_disk_access();
}
}