-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowser_tabs.rb
64 lines (52 loc) · 1.37 KB
/
browser_tabs.rb
1
2
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
# Allow for local testing without having the gem installed
$:.unshift File.dirname(__FILE__)
require 'browser_tabs/version'
require 'browser_tabs/tab'
require 'browser_tabs/processes'
require 'browser_tabs/commands/list_tabs'
require 'browser_tabs/commands/close_tab'
require 'browser_tabs/commands/activate_tab'
module BrowserTabs
class << self
def supported_browsers
@supported_browsers ||= [
'Safari',
'WebKit',
'Google Chrome Beta',
'Google Chrome',
'Google Chrome Canary',
'Chromium'
]
end
def tabs
run_command(@tab_lister ||= ListTabs.new)
end
alias_method :list, :tabs
def close(url)
run_command(@tab_closer ||= CloseTab.new, :url => url)
end
def activate(url)
run_command(@tab_activator ||= ActivateTab.new, :url => url)
end
def browser_running?(app_name)
processes.app_running?(app_name)
end
def running_browsers
@running_browsers ||= supported_browsers.select do |app|
browser_running?(app)
end
end
private
def run_command(command, opts = {})
refresh_processes
command.run({:running_browsers => running_browsers}.merge(opts))
end
def processes
@processes || refresh_processes
end
def refresh_processes
@running_browsers = nil
@processes = Processes.new
end
end
end