diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 67c420028b..bae609c07b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -356,7 +356,7 @@ class CuraApplication(QtApplication): self._machine_action_manager.initialize() def __sendCommandToSingleInstance(self): - self._single_instance = SingleInstance(self, self._files_to_open) + self._single_instance = SingleInstance(self, self._files_to_open, self._open_url_queue) # If we use single instance, try to connect to the single instance server, send commands, and then exit. # If we cannot find an existing single instance server, this is the only instance, so just keep going. diff --git a/cura/SingleInstance.py b/cura/SingleInstance.py index fb85e258db..02fa6622aa 100644 --- a/cura/SingleInstance.py +++ b/cura/SingleInstance.py @@ -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": diff --git a/packaging/NSIS/Ultimaker-Cura.nsi.jinja b/packaging/NSIS/Ultimaker-Cura.nsi.jinja index 2106c47312..0a2ce0f517 100644 --- a/packaging/NSIS/Ultimaker-Cura.nsi.jinja +++ b/packaging/NSIS/Ultimaker-Cura.nsi.jinja @@ -156,7 +156,7 @@ WriteRegStr HKCR "slicer" "" "URL:slicer" WriteRegStr HKCR "slicer" "URL Protocol" "" WriteRegStr HKCR "slicer\DefaultIcon" "" "$INSTDIR\${MAIN_APP_EXE},1" WriteRegStr HKCR "slicer\shell" "" "open" -WriteRegStr HKCR "slicer\shell\open\command" "" '"$INSTDIR\${MAIN_APP_EXE}" --single-instance "%1"' +WriteRegStr HKCR "slicer\shell\open\command" "" '"$INSTDIR\${MAIN_APP_EXE}" "%1"' SectionEnd ###################################################################### diff --git a/packaging/msi/UltiMaker-Cura.wxs.jinja b/packaging/msi/UltiMaker-Cura.wxs.jinja index 1f22dcc8bc..21f017c813 100644 --- a/packaging/msi/UltiMaker-Cura.wxs.jinja +++ b/packaging/msi/UltiMaker-Cura.wxs.jinja @@ -165,9 +165,7 @@ - - - +