3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/pave/reload.rb', line 3
def self.live_reload(browser="chrome")
trap("SIGINT") { exit }
puts "Watching #{watch_folder} and subfolders for changes in project files..."
while true do
files = []
filetypes.each {|type|
files += Dir.glob( File.join( watch_folder, "**", "*.#{type}" ) )
}
new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }
hash ||= new_hash
diff_hash = new_hash - hash
unless diff_hash.empty?
hash = new_hash
diff_hash.each do |df|
print "Detected change in #{df[0]}, refreshing"
if browser == "chrome"
print " Chrome"
%x{osascript<<ENDGAME
tell application "Google Chrome"
set windowList to every window
repeat with aWindow in windowList
set tabList to every tab of aWindow
repeat with atab in tabList
if (URL of atab contains "#{keyword}") then
tell atab to reload
end if
end repeat
end repeat
end tell
}
elsif browser == "safari"
print " Safari"
%x{osascript<<ENDGAME
tell application "Safari"
set windowList to every window
repeat with aWindow in windowList
set tabList to every tab of aWindow
repeat with atab in tabList
if (URL of atab contains "#{keyword}") then
tell atab to set its URL to (get its URL)
end if
end repeat
end repeat
end tell
}
elsif browser == "firefox"
print " Firefox"
%x{osascript<<ENDGAME
tell app "Firefox" to activate
tell app "System Events"
keystroke "r" using command down
end tell
}
else
puts "#{browser} is not supported yet. Feel free to add it and create a pull request!"
end
puts ""
end
end
sleep 1
end
end
|