From d8f84fa97bbe21467f91fce5f9dbcedd93609e0d Mon Sep 17 00:00:00 2001 From: Eliott Appleford Date: Wed, 2 Jul 2014 18:26:18 +0100 Subject: [PATCH] Update listen code --- .../lib/middleman-core/preview_server.rb | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index d93b98a6..d848fda9 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -111,18 +111,15 @@ module Middleman end def start_file_watcher - return if @options[:disable_watcher] + return if @listener or @options[:disable_watcher] - first_run = !@listener + # Watcher Library + require 'listen' - if first_run - # Watcher Library - require 'listen' - @listener = Listen.to(Dir.pwd, relative_paths: true, force_polling: @options[:force_polling]) - @listener.latency(@options[:latency]) - end + options = {force_polling: @options[:force_polling]} + options[:latency] = @options[:latency] if @options[:latency] - @listener.change do |modified, added, removed| + @listener = Listen.to(Dir.pwd, options) do |modified, added, removed| added_and_modified = (modified + added) # See if the changed file is config.rb or lib/*.rb @@ -131,19 +128,21 @@ module Middleman @webrick.stop else added_and_modified.each do |path| - next if app.files.ignored?(path) - app.files.did_change(path) + relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s + next if app.files.ignored?(relative_path) + app.files.did_change(relative_path) end removed.each do |path| - next if app.files.ignored?(path) - app.files.did_delete(path) + relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s + next if app.files.ignored?(relative_path) + app.files.did_delete(relative_path) end end end # Don't block this thread - @listener.start if first_run + @listener.start end # Trap some interupt signals and shut down smoothly