mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-28 23:04:34 +08:00
Fix QDesktopServices.openUrl() for AppImage on Linux
This commit is contained in:
parent
53efad7e6f
commit
f4dc9cc6a2
@ -3,6 +3,7 @@
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from urllib.parse import urlencode
|
||||
|
||||
@ -13,6 +14,7 @@ from PyQt5.QtGui import QDesktopServices
|
||||
|
||||
from UM.Logger import Logger
|
||||
from UM.Message import Message
|
||||
from UM.Platform import Platform
|
||||
from UM.Signal import Signal
|
||||
|
||||
from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer
|
||||
@ -164,9 +166,24 @@ class AuthorizationService:
|
||||
"code_challenge_method": "S512"
|
||||
})
|
||||
|
||||
# GITHUB issue #6194: https://github.com/Ultimaker/Cura/issues/6194
|
||||
# With AppImage 2 on Linux, the current working directory will be somewhere in /tmp/<rand>/usr, which is owned
|
||||
# by root. For some reason, QDesktopServices.openUrl() requires to have a usable current working directory,
|
||||
# otherwise it doesn't work. This is a workaround on Linux that before we call QDesktopServices.openUrl(), we
|
||||
# switch to a directory where the user has the ownership.
|
||||
old_work_dir = ""
|
||||
if Platform.isLinux():
|
||||
# Change the working directory to user home
|
||||
old_work_dir = os.getcwd()
|
||||
os.chdir(os.path.expanduser("~"))
|
||||
|
||||
# Open the authorization page in a new browser window.
|
||||
QDesktopServices.openUrl(QUrl("{}?{}".format(self._auth_url, query_string)))
|
||||
|
||||
if Platform.isLinux():
|
||||
# Change the working directory back
|
||||
os.chdir(old_work_dir)
|
||||
|
||||
# Start a local web server to receive the callback URL on.
|
||||
self._server.start(verification_code)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user