Skip to content

Commit

Permalink
Linux Fix and improvements
Browse files Browse the repository at this point in the history
Fix the deadlock issue caused by --sync (removed --sync since it is useless)
Fix the Chromebased since it needs focus before send input
Fix Firefox bug with xdotool since invisible window is returned by xdotool --visible-only
Added Opera support
Added Chromium support

Added Firefox Nightly builds support (should be the same on mac, linux and windows)

Fix Regex Application title
Fix to only catch application name not openned webpages

sudo apt-get install xdotool wmctrl

Fixed regex to match no titled window
(Firefox only, or Firefox Developper Edition with <title>)

Added Missing opera for linux in Readme

Added Missing chromium in readme
  • Loading branch information
Kwaadpepper committed Sep 23, 2015
1 parent daee0ed commit de67da8
Showing 3 changed files with 70 additions and 20 deletions.
3 changes: 3 additions & 0 deletions BrowserRefresh.py
Original file line number Diff line number Diff line change
@@ -65,6 +65,9 @@ def run(self, args, activate=True,
if 'firefox' in browsers:
refresher.firefox()

if 'nightly' in browsers:
refresher.nightly()

if 'firefoxdev' in browsers and _os == 'Darwin':
refresher.firefox_dev()

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ git clone https://github.com/gcollazo/BrowserRefresh-Sublime.git "Browser Refres
Install xdotool:

```
sudo apt-get install xdotool
sudo apt-get install xdotool wmctrl
```

### 2. Configure Key Bindings
@@ -64,11 +64,13 @@ Specify which browsers to refresh on command. The default is `chrome` which will
|---------------------------|--------------|-----------------|
| Google Chrome | `chrome` | Mac, Win, Linux |
| Google Chrome Canary | `canary` | Mac, Win |
| Chromium | `chromium | Linux |
| Safari | `safari` | Mac, Win |
| WebKit | `webkit` | Mac |
| Firefox | `firefox` | Mac, Win, Linux |
| Firefox Developer Edition | `firefoxdev` | Mac |
| Opera | `opera` | Mac, Win |
| Firefox Nightly | `nightly` | Mac, Win, Linux |
| Opera | `opera` | Mac, Win, Linux |
| Internet Explorer | `ie` | Win |
| SRWare Iron | `iron` | Win |
| Yandex | `yandex` | Mac |
81 changes: 63 additions & 18 deletions linux/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sublime
from subprocess import call

from subprocess import call, Popen, PIPE, STDOUT

class LinuxBrowserRefresh:
def __init__(self, activate_browser):
# activate_browser is always true on Windows since you can't
# send keys to an inactive window programmatically. We ignore it.
self.activate_browser = activate_browser

def chrome(self):
self.SendKeysToAllWindows('google-chrome', 'F5')
self.SendKeyToAllWebkitBasedNavigators('google-chrome', 'ctrl+F5')

def chromium(self):
self.SendKeyToAllWebkitBasedNavigators('chromium-browser', 'ctrl+F5')

def iron(self):
pass
@@ -26,28 +26,73 @@ def safari64(self):
def firefox(self):
self.SendKeysToAllWindows('firefox', 'F5')

def nightly(self):
self.SendKeysToAllWindows('nightly', 'F5')

def opera(self):
pass
# except NotImplemented("Opera support not implemented yet.")
self.SendKeyToAllWebkitBasedNavigators('opera', 'ctrl+F5')

def ie(self):
pass
# except NotImplemented("IE support not implemented yet.")

def SendKeyToAllWebkitBasedNavigators(self, cls, key):
cmd = ['xdotool', 'search', '--onlyvisible', '--class', cls, 'windowactivate', 'key', key]

if self.activate_browser:
cmd += ['windowactivate']
else:
# trick to bring sublime text back to front
# this avoids the webkit bug where you have
# to activatewindow before inputing key
call(['subl'])

try:
call(cmd)
except Exception:
self.print_error(cmd)

def SendKeysToAllWindows(self, cls, key):
"Sends the keystroke to all windows whose title matches the regex"

cmd = ['xdotool', 'search', '--sync', '--onlyvisible', '--class', cls, 'windowfocus', 'key', key]
cmd = ['wmctrl', '-l']
try:
process = Popen(cmd, stdout=PIPE)
out, err = process.communicate()
except Exception:
self.print_error(cmd)
return

if self.activate_browser:
cmd += ['windowactivate']
process = Popen(['grep', '-ie', '[-]\?[a-z0-9 ]*%s[a-z0-9 ]*$' % cls], stdout=PIPE, stdin=PIPE)
process.stdin.write(out)
out, err = process.communicate()

status_code = call(cmd)
wID = ""
try:
wID = out.split()[0].decode(encoding='UTF-8')
except Exception:
# no window found
return

cmd = ['xdotool', 'key', '--window', wID, key]
try:
call(cmd)
except Exception:
self.print_error(cmd)
return

if self.activate_browser:
cmd = ['xdotool', 'windowactivate', wID]
try:
call(cmd)
except Exception:
self.print_error(cmd)
return

if status_code != 0:
sublime.error_message(
'Browser Refresh cannot execute the specified program.\n\n'
'%s\n\n'
'If program \'xdotool\' is currently not installed '
'you can install it by typing:\n\n'
'sudo apt-get install xdotool' % " ".join(cmd))
def print_error(prog, cmd):
sublime.error_message(
'Browser Refresh cannot execute the specified program.\n\n'
'%s\n\n'
'If program \'%s\' is currently not installed '
'you can install it by typing:\n\n'
'sudo apt-get install %s' % (' '.join(cmd), cmd[0], cmd[0]))

0 comments on commit de67da8

Please sign in to comment.