Sha256: 95bbd9bd193d89ea27d957e3afd57db6943e3ae427880475c4e30329ec0e14f9

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

class Listener
  def initialize(path = nil, &block)
    require 'osx/foundation'

    OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'

    callback = proc do |stream, context, count, paths, marks, events|
      yield
    end

    flags     = 0
    path      = [path || Dir.pwd]
    since     = OSX::KFSEventStreamEventIdSinceNow
    context   = nil
    latency   = 1.0
    allocator = OSX::KCFAllocatorDefault

    unless stream = OSX::FSEventStreamCreate(allocator, callback, context, path, since, latency, flags)
      puts 'Failed to create stream...'
      exit
    end

    OSX::FSEventStreamScheduleWithRunLoop(stream, OSX::CFRunLoopGetCurrent(), OSX::KCFRunLoopDefaultMode)

    unless OSX::FSEventStreamStart(stream)
      puts 'Failed to start stream...'
      exit
    end

    OSX::CFRunLoopRun()
  rescue Interrupt
    OSX::FSEventStreamStop(stream)
    OSX::FSEventStreamInvalidate(stream)
    OSX::FSEventStreamRelease(stream)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
as3-autocompile-0.1.0 lib/listener.rb