mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
adding files in single instance in case of url
CURA-11596
This commit is contained in:
parent
8073bc0e50
commit
eff4584203
4 changed files with 21 additions and 20 deletions
|
@ -356,7 +356,7 @@ class CuraApplication(QtApplication):
|
||||||
self._machine_action_manager.initialize()
|
self._machine_action_manager.initialize()
|
||||||
|
|
||||||
def __sendCommandToSingleInstance(self):
|
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 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.
|
# If we cannot find an existing single instance server, this is the only instance, so just keep going.
|
||||||
|
|
|
@ -12,9 +12,10 @@ from UM.Logger import Logger
|
||||||
|
|
||||||
|
|
||||||
class SingleInstance:
|
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._application = application
|
||||||
self._files_to_open = files_to_open
|
self._files_to_open = files_to_open
|
||||||
|
self._url_to_open = url_to_open
|
||||||
|
|
||||||
self._single_instance_server = None
|
self._single_instance_server = None
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ class SingleInstance:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# We only send the files that need to be opened.
|
# 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.")
|
Logger.log("i", "No file need to be opened, do nothing.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -52,10 +53,13 @@ class SingleInstance:
|
||||||
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:
|
for filename in self._files_to_open:
|
||||||
Logger.log("i",f"Filename isxxx {os.path(filename)}")
|
|
||||||
payload = {"command": "open", "filePath": os.path.abspath(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"}
|
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"))
|
||||||
|
|
||||||
|
@ -82,7 +86,6 @@ class SingleInstance:
|
||||||
|
|
||||||
def __readCommands(self, connection: QLocalSocket) -> None:
|
def __readCommands(self, connection: QLocalSocket) -> None:
|
||||||
line = connection.readLine()
|
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:
|
try:
|
||||||
payload = json.loads(str(line, encoding="ascii").strip())
|
payload = json.loads(str(line, encoding="ascii").strip())
|
||||||
|
@ -96,8 +99,8 @@ class SingleInstance:
|
||||||
elif command == "open":
|
elif command == "open":
|
||||||
if payload["filePath"].file():
|
if payload["filePath"].file():
|
||||||
self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f))
|
self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f))
|
||||||
if payload["filePath"].url():
|
if payload["urlPath"].url():
|
||||||
self._application.callLater(lambda f= payload["filepath"]: self._application._openUrl(f))
|
self._application.callLater(lambda f = payload["urlPath"]: self._application._openUrl(f))
|
||||||
|
|
||||||
|
|
||||||
# Command: Activate the window and bring it to the top.
|
# Command: Activate the window and bring it to the top.
|
||||||
|
|
|
@ -156,7 +156,7 @@ WriteRegStr HKCR "slicer" "" "URL:slicer"
|
||||||
WriteRegStr HKCR "slicer" "URL Protocol" ""
|
WriteRegStr HKCR "slicer" "URL Protocol" ""
|
||||||
WriteRegStr HKCR "slicer\DefaultIcon" "" "$INSTDIR\${MAIN_APP_EXE},1"
|
WriteRegStr HKCR "slicer\DefaultIcon" "" "$INSTDIR\${MAIN_APP_EXE},1"
|
||||||
WriteRegStr HKCR "slicer\shell" "" "open"
|
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
|
SectionEnd
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -165,9 +165,7 @@
|
||||||
<RegistryValue Type="string" Value="URL:Cura Protocol"/>
|
<RegistryValue Type="string" Value="URL:Cura Protocol"/>
|
||||||
<RegistryValue Type="string" Name="URL Protocol" Value=""/>
|
<RegistryValue Type="string" Name="URL Protocol" Value=""/>
|
||||||
<RegistryValue Type="string" Key="DefaultIcon" Value="[APPLICATIONFOLDER]\{{ main_app }},1"/>
|
<RegistryValue Type="string" Key="DefaultIcon" Value="[APPLICATIONFOLDER]\{{ main_app }},1"/>
|
||||||
<RegistryValue Type="string" Key="shell\open\command" Value=""[APPLICATIONFOLDER]\{{ main_app }}" --single-instance "%1""/>
|
<RegistryValue Type="string" Key="shell\open\command" Value=""[APPLICATIONFOLDER]\{{ main_app }}" "%1""/>
|
||||||
<Verb Id="open_url" Command="Open" Argument='"%1"' />
|
|
||||||
<MIME Advertise="yes" ContentType="application/url" Default="yes" />
|
|
||||||
</RegistryKey>
|
</RegistryKey>
|
||||||
</Component>
|
</Component>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue