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:
sys.exit(0)
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:
# This could be a race condition...
log.init.debug("Got AddressInUseError, trying again.")

View File

@ -24,11 +24,11 @@ import json
import getpass
import binascii
from PyQt5.QtCore import pyqtSlot, QObject
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket
from PyQt5.QtWidgets import QMessageBox
from qutebrowser.utils import log, objreg, usertypes
from qutebrowser.utils import log, usertypes
SOCKETNAME = 'qutebrowser-{}'.format(getpass.getuser())
@ -80,8 +80,14 @@ class IPCServer(QObject):
_timer: A timer to handle timeouts.
_server: A QLocalServer to accept new connections.
_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):
"""Start the IPC server and listen to commands."""
super().__init__(parent)
@ -187,8 +193,7 @@ class IPCServer(QObject):
log.ipc.debug("no args: {}".format(decoded.strip()))
return
cwd = json_data.get('cwd', None)
app = objreg.get('app')
app.process_pos_args(args, via_ipc=True, cwd=cwd)
self.got_args.emit(args, cwd)
@pyqtSlot()
def on_timeout(self):
@ -207,13 +212,6 @@ class IPCServer(QObject):
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):
"""Raise an Error based on an action and a QLocalSocket.