Skip to content

Commit

Permalink
Removed user-data-dir arguments for linux, spawned windows now share …
Browse files Browse the repository at this point in the history
…the same context (and thus localstorage), added xdotool dependency, added --disable-infobars to remove "restore current session" messages that sometimes spawn
  • Loading branch information
foxxyz committed Jul 19, 2016
1 parent 2b45470 commit 6c846bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Requirements
------------

* Python 3
* xdotool (Linux Only)
* Install with Apt: `sudo apt-get install xdotool`
* Install with Pacman: `sudo pacman -S xdotool`

Usage
-----
Expand Down
2 changes: 1 addition & 1 deletion multibrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from systems import *

__version__ = '1.1.0'
__version__ = '1.2.0'


# Startup procedure
Expand Down
38 changes: 34 additions & 4 deletions systems/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import re
from subprocess import call, check_output, Popen, DEVNULL
import sys
from time import sleep
from uuid import uuid4

from . import System


class LinuxSystem(System):

def __init__(self):
self.open_windows = set()

@classmethod
def is_current(self):
try:
Expand All @@ -36,18 +40,44 @@ def displays(self):
return connected

def open_browser(self, url, display_num=0):
# Get current display
try:
display = self.displays[display_num]
except IndexError:
print('Error: No display number {}'.format(display_num + 1), file=sys.stderr)
return
Popen([

# Open browser window
args = [
self.browser_path,
url,
'--new-window',
'--kiosk',
'--disable-infobars',
'--disable-session-crashed-bubble',
'--window-position={},{}'.format(display['offset_x'], display['offset_y']),
'--user-data-dir=/tmp/{}'.format(uuid4()), # Create a random user data dir so chrome will see every instance as independent and not open them in the same window
'--no-first-run', # Skip dialog boxes asking for default browser and sending usage statistics to google
], stdout=DEVNULL, stderr=DEVNULL)
]
proc = Popen(args, stdout=DEVNULL, stderr=DEVNULL)
sleep(1)

# Find browser process handle
# This will always return a number of window IDs, but only one of them is the actual window, so compare
# them to window_ids we're seen earlier to find the new one
try:
window_ids = check_output(['xdotool', 'search', '--class', 'Chrome']).decode('utf-8').split('\n')
except FileNotFoundError:
print('Looks like xdotool is not installed. Install it with `sudo apt-get install xdotool`', file=sys.stderr)
return
if not self.open_windows:
self.open_windows = set(window_ids)
win_id = window_ids[0]
else:
win_id = next(iter(set(window_ids) - self.open_windows))
self.open_windows.add(win_id)

# Move to correct position
call(['xdotool', 'windowmove', win_id, display['offset_x'], display['offset_y']])

# Set to full screen and refresh
for key in ['F11', 'F5']:
call(['xdotool', 'windowactivate', '--sync', win_id, 'key', key])
3 changes: 2 additions & 1 deletion systems/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def open_browser(self, url, display_num=0):
subprocess.Popen([
self.browser_path,
url,
'--disable-infobars',
'--new-window',
'--no-first-run',
'--disable-session-crashed-bubble',
Expand Down Expand Up @@ -95,8 +96,8 @@ def process_handler(handle, _):
cb_size = ctypes.c_int(ctypes.sizeof(INPUT))
user.SendInput(n_inputs, p_inputs, cb_size)

# Windows Ctypes for interacting with the Windows API

# Windows Ctypes for interacting with the Windows API
class RECT(ctypes.Structure):
_fields_ = (
('left', ctypes.c_ulong),
Expand Down

0 comments on commit 6c846bf

Please sign in to comment.