forked from gcollazo/BrowserRefresh-Sublime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserRefresh.py
96 lines (72 loc) · 2.71 KB
/
BrowserRefresh.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import sys
import platform
import sublime
import sublime_plugin
# Fix windows imports
__file__ = os.path.normpath(os.path.abspath(__file__))
__path__ = os.path.dirname(__file__)
if __path__ not in sys.path:
sys.path.insert(0, __path__)
_pywinauto = os.path.join(__path__ + os.path.sep + 'win')
if _pywinauto not in sys.path:
sys.path.insert(0, _pywinauto)
# Cache user operating system
_os = platform.system()
class BrowserRefreshCommand(sublime_plugin.TextCommand):
def run(self, args, activate_browser=True,
browser_name='all', auto_save=True, delay=None):
# Auto-save
if auto_save and self.view and self.view.is_dirty():
self.view.run_command('save')
# Detect OS and import
if _os == 'Darwin':
from mac import MacBrowserRefresh
from mac.utils import running_browsers
refresher = MacBrowserRefresh(activate_browser, running_browsers())
elif _os == 'Windows':
from win import WinBrowserRefresh
refresher = WinBrowserRefresh(activate_browser)
elif _os == 'Linux':
from linux import LinuxBrowserRefresh
refresher = LinuxBrowserRefresh(activate_browser)
else:
sublime.error_message('Your operating system is not supported')
# Delay refresh
if delay is not None:
import time
time.sleep(delay)
# Actually refresh browsers
if browser_name == 'Google Chrome':
refresher.chrome()
elif browser_name == 'Google Chrome Canary' and _os == 'Darwin':
refresher.canary()
elif browser_name == 'yandex' and _os == 'Darwin':
refresher.yandex()
elif browser_name == 'Safari':
refresher.safari()
elif browser_name == 'WebKit' and _os == 'Darwin':
refresher.webkit()
elif browser_name == 'Firefox':
refresher.firefox()
elif browser_name == 'Opera':
refresher.opera()
elif browser_name == 'IE' and _os == 'Windows':
refresher.ie()
elif browser_name == 'Iron' and _os == 'Windows':
refresher.iron()
elif browser_name == 'Pale Moon' and _os == 'Windows':
refresher.palemoon()
elif browser_name == 'all':
refresher.chrome()
refresher.safari()
refresher.firefox()
refresher.opera()
if _os == 'Darwin':
refresher.canary()
refresher.yandex()
refresher.webkit()
if _os == 'Windows':
refresher.ie()
refresher.iron()
refresher.palemoon()