Beispiel #1
0
 def another_instance_wants_to_talk(self):
     s = self.local_server.nextPendingConnection()
     if s is None:
         return
     s.waitForReadyRead(1000)
     stream = QTextStream(s)
     stream.setCodec('UTF-8')
     raw = stream.readAll()
     try:
         command = json.loads(raw)
     except Exception as e:
         self.error('Invalid data from other instance: %s' % e)
         return
     finally:
         s.close()
         del s
     if not isinstance(command, dict):
         self.error('Invalid data from other instance: %r' % command)
         return
     ac = command.get('action')
     if ac == 'shutdown':
         return self.shutdown()
     urls = command.get('open', [])
     if not isinstance(urls, list):
         self.error('Invalid data from other instance: %r' % command)
         return
     urls = [x for x in urls if isinstance(x, str)]
     if urls:
         self.open_urls(urls, in_current_tab='dynamic', switch_to_tab=True)
Beispiel #2
0
 def another_instance_wants_to_talk(self):
     s = self.local_server.nextPendingConnection()
     if s is None:
         return
     s.waitForReadyRead(1000)
     stream = QTextStream(s)
     stream.setCodec('UTF-8')
     raw = stream.readAll()
     try:
         command = json.loads(raw)
     except Exception as e:
         self.error('Invalid data from other instance: %s' % e)
         return
     finally:
         s.close()
         del s
     if not isinstance(command, dict):
         self.error('Invalid data from other instance: %r' % command)
         return
     ac = command.get('action')
     if ac == 'shutdown':
         return self.shutdown()
     urls = command.get('open', [])
     if not isinstance(urls, list):
         self.error('Invalid data from other instance: %r' % command)
         return
     urls = [x for x in urls if isinstance(x, str)]
     if urls:
         self.open_urls(urls, in_current_tab='dynamic', switch_to_tab=True)
Beispiel #3
0
 def run_local_server(self, urls, new_instance, shutdown):
     if shutdown:
         new_instance = False
     server_name = local_socket_address()
     s = QLocalSocket()
     s.connectToServer(server_name)
     if s.waitForConnected(500):
         if new_instance:
             return
         stream = QTextStream(s)
         stream.setCodec('UTF-8')
         if shutdown:
             cargs = json.dumps({'action': 'shutdown'})
         else:
             cargs = json.dumps({'open': urls}, ensure_ascii=False)
         stream << cargs
         stream.flush()
         s.waitForBytesWritten()
         raise SystemExit(0)
     if shutdown:
         raise SystemExit('No running vise instance found')
     self.local_server = ls = QLocalServer(self)
     ls.newConnection.connect(self.another_instance_wants_to_talk)
     if not ls.listen(server_name):
         if ls.serverError() == QAbstractSocket.AddressInUseError:
             try:
                 os.remove(server_name)
             except FileNotFoundError:
                 pass
         if not ls.listen(server_name):
             raise SystemExit(
                 'Failed to establish local listening socket at: %s with error: %s'
                 % (server_name, ls.errorString()))
Beispiel #4
0
 def run_local_server(self, urls, new_instance, shutdown):
     if shutdown:
         new_instance = False
     server_name = local_socket_address()
     s = QLocalSocket()
     s.connectToServer(server_name)
     if s.waitForConnected(500):
         if new_instance:
             return
         stream = QTextStream(s)
         stream.setCodec('UTF-8')
         if shutdown:
             cargs = json.dumps({'action': 'shutdown'})
         else:
             cargs = json.dumps({'open': urls}, ensure_ascii=False)
         stream << cargs
         stream.flush()
         s.waitForBytesWritten()
         raise SystemExit(0)
     if shutdown:
         raise SystemExit('No running vise instance found')
     self.local_server = ls = QLocalServer(self)
     ls.newConnection.connect(self.another_instance_wants_to_talk)
     if not ls.listen(server_name):
         if ls.serverError() == QAbstractSocket.AddressInUseError:
             try:
                 os.remove(server_name)
             except FileNotFoundError:
                 pass
         if not ls.listen(server_name):
             raise SystemExit('Failed to establish local listening socket at: %s with error: %s' % (
                 server_name, ls.errorString()))