Skip to content

Commit

Permalink
show warning when no browsers are connected
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Oct 26, 2015
1 parent 3b9d19d commit f15aa80
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/guard/livereload/reactor.rb
Expand Up @@ -32,7 +32,6 @@ def initialize(options)
@sockets = Sockets.new
@options = options
@thread = Thread.new { _start_reactor }
@connections_count = 0
end

def sockets
Expand All @@ -59,6 +58,11 @@ def stop

def reload_browser(paths = [])
msg = "Reloading browser: #{paths.join(' ')}"

if sockets.empty?
Compat::UI.warning "No browsers connected at this time! Browser won't refresh!"
end

Compat::UI.info msg
if options[:notify]
Compat::UI.notify(msg, title: 'Reloading browser', image: :success)
Expand Down
4 changes: 4 additions & 0 deletions lib/guard/livereload/reactor/sockets.rb
Expand Up @@ -29,6 +29,10 @@ def add(socket)
def delete(socket)
@mutex.synchronize { @sockets.delete(socket) }
end

def empty?
@mutex.synchronize { @sockets.empty? }
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/guard/livereload/reactor_spec.rb
Expand Up @@ -15,6 +15,7 @@
describe '#reload_browser(paths = [])' do
before do
allow(sockets).to receive(:broadcast)
allow(sockets).to receive(:empty?).and_return(false)
end

it 'displays a message' do
Expand Down Expand Up @@ -64,6 +65,20 @@
subject.reload_browser(paths)
end
end

end

context 'with no connected browsers' do
subject { new_live_reactor }

before do
allow(sockets).to receive(:empty?).and_return(true)
end

it 'shows a warning' do
expect(Guard::Compat::UI).to receive(:warning).with(/No browsers connected at this time!/)
subject.reload_browser(paths)
end
end
end

Expand Down

0 comments on commit f15aa80

Please sign in to comment.