|
@@ -7,14 +7,15 @@ from typing import List, Optional
|
|
|
|
|
|
from PyQt6.QtNetwork import QLocalServer, QLocalSocket
|
|
|
|
|
|
-from UM.Qt.QtApplication import QtApplication #For typing.
|
|
|
+from UM.Qt.QtApplication import QtApplication # For typing.
|
|
|
from UM.Logger import Logger
|
|
|
|
|
|
|
|
|
class SingleInstance:
|
|
|
- def __init__(self, application: QtApplication, files_to_open: Optional[List[str]]) -> None:
|
|
|
+ def __init__(self, application: QtApplication, files_to_open: Optional[List[str]], url_to_open: Optional[List[str]]) -> None:
|
|
|
self._application = application
|
|
|
self._files_to_open = files_to_open
|
|
|
+ self._url_to_open = url_to_open
|
|
|
|
|
|
self._single_instance_server = None
|
|
|
|
|
@@ -33,7 +34,7 @@ class SingleInstance:
|
|
|
return False
|
|
|
|
|
|
# We only send the files that need to be opened.
|
|
|
- if not self._files_to_open:
|
|
|
+ if not self._files_to_open or not self._url_to_open:
|
|
|
Logger.log("i", "No file need to be opened, do nothing.")
|
|
|
return True
|
|
|
|
|
@@ -46,18 +47,21 @@ class SingleInstance:
|
|
|
|
|
|
if self._application.getPreferences().getValue("cura/single_instance_clear_before_load"):
|
|
|
payload = {"command": "clear-all"}
|
|
|
- single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding = "ascii"))
|
|
|
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ascii"))
|
|
|
|
|
|
payload = {"command": "focus"}
|
|
|
- single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding = "ascii"))
|
|
|
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ascii"))
|
|
|
|
|
|
for filename in self._files_to_open:
|
|
|
- Logger.log("i",f"Filename isxxx {os.path(filename)}")
|
|
|
payload = {"command": "open", "filePath": os.path.abspath(filename)}
|
|
|
- single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding = "ascii"))
|
|
|
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ascii"))
|
|
|
+
|
|
|
+ for filename in self._url_to_open:
|
|
|
+ payload = {"command": "open", "urlPath": os.path.abspath(filename)}
|
|
|
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ascii"))
|
|
|
|
|
|
payload = {"command": "close-connection"}
|
|
|
- single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding = "ascii"))
|
|
|
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ascii"))
|
|
|
|
|
|
single_instance_socket.flush()
|
|
|
single_instance_socket.waitForDisconnected()
|
|
@@ -73,7 +77,7 @@ class SingleInstance:
|
|
|
|
|
|
def _onClientConnected(self) -> None:
|
|
|
Logger.log("i", "New connection received on our single-instance server")
|
|
|
- connection = None #type: Optional[QLocalSocket]
|
|
|
+ connection = None # type: Optional[QLocalSocket]
|
|
|
if self._single_instance_server:
|
|
|
connection = self._single_instance_server.nextPendingConnection()
|
|
|
|
|
@@ -82,10 +86,9 @@ class SingleInstance:
|
|
|
|
|
|
def __readCommands(self, connection: QLocalSocket) -> None:
|
|
|
line = connection.readLine()
|
|
|
- Logger.log("i", f"line read is {line}")
|
|
|
- while len(line) != 0: # There is also a .canReadLine()
|
|
|
+ while len(line) != 0: # There is also a .canReadLine()
|
|
|
try:
|
|
|
- payload = json.loads(str(line, encoding = "ascii").strip())
|
|
|
+ payload = json.loads(str(line, encoding="ascii").strip())
|
|
|
command = payload["command"]
|
|
|
|
|
|
# Command: Remove all models from the build plate.
|
|
@@ -96,8 +99,8 @@ class SingleInstance:
|
|
|
elif command == "open":
|
|
|
if payload["filePath"].file():
|
|
|
self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f))
|
|
|
- if payload["filePath"].url():
|
|
|
- self._application.callLater(lambda f= payload["filepath"]: self._application._openUrl(f))
|
|
|
+ if payload["urlPath"].url():
|
|
|
+ self._application.callLater(lambda f = payload["urlPath"]: self._application._openUrl(f))
|
|
|
|
|
|
|
|
|
# Command: Activate the window and bring it to the top.
|
|
@@ -106,7 +109,7 @@ class SingleInstance:
|
|
|
# 'alert' or flashing the icon in the taskbar is the best thing we do now.
|
|
|
main_window = self._application.getMainWindow()
|
|
|
if main_window is not None:
|
|
|
- self._application.callLater(lambda: main_window.alert(0)) # type: ignore # I don't know why MyPy complains here
|
|
|
+ self._application.callLater(lambda: main_window.alert(0)) # type: ignore # I don't know why MyPy complains here
|
|
|
|
|
|
# Command: Close the socket connection. We're done.
|
|
|
elif command == "close-connection":
|