From 56eb880505d1b9d4021ebd62935ec6575d2d5a12 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 14 Oct 2025 14:08:33 +1300 Subject: [PATCH] Fix FSEventStreamScheduleWithRunLoop deprecation warning on macOS 13+ Replace the deprecated FSEventStreamScheduleWithRunLoop API with the modern FSEventStreamSetDispatchQueue API that uses Grand Central Dispatch. This eliminates the deprecation warning while maintaining the same functionality for file system event monitoring on macOS. --- watch_darwin.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/watch_darwin.go b/watch_darwin.go index ba124a6..9e1a444 100644 --- a/watch_darwin.go +++ b/watch_darwin.go @@ -7,6 +7,7 @@ package changes /* #cgo LDFLAGS: -framework CoreServices #include +#include FSEventStreamRef fswatch_new( FSEventStreamContext*, CFMutableArrayRef, @@ -16,6 +17,9 @@ FSEventStreamRef fswatch_new( static CFMutableArrayRef fswatch_make_mutable_array() { return CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } +static dispatch_queue_t fswatch_dispatch_queue() { + return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); +} */ import "C" @@ -58,11 +62,8 @@ func startScanner(dir string) { stream := C.fswatch_new(&ctx, cpaths, now, C.CFTimeInterval(interval/time.Second), cflags) - go func() { - C.FSEventStreamScheduleWithRunLoop(stream, C.CFRunLoopGetCurrent(), C.kCFRunLoopCommonModes) - C.FSEventStreamStart(stream) - C.CFRunLoopRun() - }() + C.FSEventStreamSetDispatchQueue(stream, C.fswatch_dispatch_queue()) + C.FSEventStreamStart(stream) } func waitForNextScan(dir string) {