This commit is contained in:
Florian Bruhin 2015-05-01 14:44:41 +02:00
parent d3a7b2e4ca
commit f499fd85d0
2 changed files with 13 additions and 12 deletions

View File

@ -74,7 +74,10 @@ def run(args):
if sent: if sent:
sys.exit(0) sys.exit(0)
log.init.debug("Starting IPC server...") log.init.debug("Starting IPC server...")
ipc.init() server = ipc.IPCServer(qApp)
objreg.register('ipc-server', server)
server.got_args.connect(lambda args, cwd:
process_pos_args(args, cwd=cwd, via_ipc=True))
except ipc.AddressInUseError as e: except ipc.AddressInUseError as e:
# This could be a race condition... # This could be a race condition...
log.init.debug("Got AddressInUseError, trying again.") log.init.debug("Got AddressInUseError, trying again.")

View File

@ -24,11 +24,11 @@ import json
import getpass import getpass
import binascii import binascii
from PyQt5.QtCore import pyqtSlot, QObject from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
from qutebrowser.utils import log, objreg, usertypes from qutebrowser.utils import log, usertypes
SOCKETNAME = 'qutebrowser-{}'.format(getpass.getuser()) SOCKETNAME = 'qutebrowser-{}'.format(getpass.getuser())
@ -80,8 +80,14 @@ class IPCServer(QObject):
_timer: A timer to handle timeouts. _timer: A timer to handle timeouts.
_server: A QLocalServer to accept new connections. _server: A QLocalServer to accept new connections.
_socket: The QLocalSocket we're currently connected to. _socket: The QLocalSocket we're currently connected to.
Signals:
got_args: Emitted when there was an IPC connection and arguments were
passed.
""" """
got_args = pyqtSignal(list, str)
def __init__(self, parent=None): def __init__(self, parent=None):
"""Start the IPC server and listen to commands.""" """Start the IPC server and listen to commands."""
super().__init__(parent) super().__init__(parent)
@ -187,8 +193,7 @@ class IPCServer(QObject):
log.ipc.debug("no args: {}".format(decoded.strip())) log.ipc.debug("no args: {}".format(decoded.strip()))
return return
cwd = json_data.get('cwd', None) cwd = json_data.get('cwd', None)
app = objreg.get('app') self.got_args.emit(args, cwd)
app.process_pos_args(args, via_ipc=True, cwd=cwd)
@pyqtSlot() @pyqtSlot()
def on_timeout(self): def on_timeout(self):
@ -207,13 +212,6 @@ class IPCServer(QObject):
self._remove_server() self._remove_server()
def init():
"""Initialize the global IPC server."""
app = objreg.get('app')
server = IPCServer(app)
objreg.register('ipc-server', server)
def _socket_error(action, socket): def _socket_error(action, socket):
"""Raise an Error based on an action and a QLocalSocket. """Raise an Error based on an action and a QLocalSocket.