mirror of
https://github.com/dkmstr/openuds.git
synced 2025-08-25 13:49:59 +03:00
Simplifying for M1
This commit is contained in:
@ -31,9 +31,11 @@
|
|||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
import sys
|
import sys
|
||||||
|
import platform
|
||||||
|
import time
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import typing
|
|
||||||
import threading
|
import threading
|
||||||
|
import typing
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
from PyQt5.QtCore import QSettings
|
from PyQt5.QtCore import QSettings
|
||||||
@ -62,9 +64,11 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
animInverted: bool = False
|
animInverted: bool = False
|
||||||
api: RestApi
|
api: RestApi
|
||||||
|
|
||||||
def __init__(self, api: RestApi):
|
def __init__(self, api: RestApi, ticket: str, scrambler: str):
|
||||||
QtWidgets.QMainWindow.__init__(self)
|
QtWidgets.QMainWindow.__init__(self)
|
||||||
self.api = api
|
self.api = api
|
||||||
|
self.ticket = ticket
|
||||||
|
self.scrambler = scrambler
|
||||||
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # type: ignore
|
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # type: ignore
|
||||||
|
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
@ -82,7 +86,7 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
self.move(hpos, vpos)
|
self.move(hpos, vpos)
|
||||||
|
|
||||||
self.animTimer = QtCore.QTimer()
|
self.animTimer = QtCore.QTimer()
|
||||||
self.animTimer.timeout.connect(self.updateAnim)
|
self.animTimer.timeout.connect(self.updateAnim) # type: ignore
|
||||||
# QtCore.QObject.connect(self.animTimer, QtCore.SIGNAL('timeout()'), self.updateAnim)
|
# QtCore.QObject.connect(self.animTimer, QtCore.SIGNAL('timeout()'), self.updateAnim)
|
||||||
|
|
||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
@ -99,7 +103,12 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
'UDS Plugin Error'
|
'UDS Plugin Error'
|
||||||
) # In fact, main window is hidden, so this is not visible... :)
|
) # In fact, main window is hidden, so this is not visible... :)
|
||||||
self.closeWindow()
|
self.closeWindow()
|
||||||
QtWidgets.QMessageBox.critical(None, 'UDS Plugin Error', '{}'.format(error), QtWidgets.QMessageBox.Ok) # type: ignore
|
QtWidgets.QMessageBox.critical(
|
||||||
|
None, # type: ignore
|
||||||
|
'UDS Plugin Error',
|
||||||
|
'{}'.format(error),
|
||||||
|
QtWidgets.QMessageBox.Ok
|
||||||
|
)
|
||||||
self.withError = True
|
self.withError = True
|
||||||
|
|
||||||
def cancelPushed(self):
|
def cancelPushed(self):
|
||||||
@ -129,6 +138,12 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
try:
|
try:
|
||||||
self.api.getVersion()
|
self.api.getVersion()
|
||||||
except InvalidVersion as e:
|
except InvalidVersion as e:
|
||||||
|
QtWidgets.QMessageBox.critical(
|
||||||
|
self,
|
||||||
|
'Upgrade required',
|
||||||
|
'A newer connector version is required.\nA browser will be opened to download it.',
|
||||||
|
QtWidgets.QMessageBox.Ok
|
||||||
|
)
|
||||||
webbrowser.open(e.downloadUrl)
|
webbrowser.open(e.downloadUrl)
|
||||||
self.closeWindow()
|
self.closeWindow()
|
||||||
return
|
return
|
||||||
@ -145,14 +160,15 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
if 'darwin' in sys.platform:
|
if 'darwin' in sys.platform:
|
||||||
self.showMinimized()
|
self.showMinimized()
|
||||||
|
|
||||||
# Execute the waiting task...
|
|
||||||
threading.Thread(target=endScript).start()
|
|
||||||
|
|
||||||
# QtCore.QTimer.singleShot(3000, self.endScript)
|
# QtCore.QTimer.singleShot(3000, self.endScript)
|
||||||
# self.hide()
|
# self.hide()
|
||||||
self.closeWindow()
|
self.closeWindow()
|
||||||
|
|
||||||
exec(script, globals(), {'parent': self, 'sp': params})
|
exec(script, globals(), {'parent': self, 'sp': params})
|
||||||
|
|
||||||
|
# Execute the waiting tasks...
|
||||||
|
threading.Thread(target=endScript).start()
|
||||||
|
|
||||||
except RetryException as e:
|
except RetryException as e:
|
||||||
self.ui.info.setText(str(e) + ', retrying access...')
|
self.ui.info.setText(str(e) + ', retrying access...')
|
||||||
# Retry operation in ten seconds
|
# Retry operation in ten seconds
|
||||||
@ -169,26 +185,29 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
QtCore.QTimer.singleShot(100, self.getVersion)
|
QtCore.QTimer.singleShot(100, self.getVersion)
|
||||||
|
|
||||||
def endScript():
|
def endScript():
|
||||||
|
# Wait a bit before start processing ending sequence
|
||||||
|
time.sleep(3)
|
||||||
# After running script, wait for stuff
|
# After running script, wait for stuff
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Wating for tasks to finish...')
|
||||||
tools.waitForTasks()
|
tools.waitForTasks()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Unlinking files')
|
||||||
tools.unlinkFiles()
|
tools.unlinkFiles()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Removing
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Executing threads before exit')
|
||||||
tools.execBeforeExit()
|
tools.execBeforeExit()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
logger.debug('endScript done')
|
||||||
def done(data) -> None:
|
|
||||||
QtWidgets.QMessageBox.critical(None, 'Notice', str(data.data), QtWidgets.QMessageBox.Ok) # type: ignore
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
# Ask user to approve endpoint
|
# Ask user to approve endpoint
|
||||||
@ -239,6 +258,42 @@ def sslError(hostname: str, serial):
|
|||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
return approved
|
return approved
|
||||||
|
|
||||||
|
def minimal(api: RestApi, ticket: str, scrambler: str):
|
||||||
|
try:
|
||||||
|
logger.info('M1 Execution')
|
||||||
|
logger.debug('Getting version')
|
||||||
|
try:
|
||||||
|
api.getVersion()
|
||||||
|
except InvalidVersion as e:
|
||||||
|
QtWidgets.QMessageBox.critical(
|
||||||
|
None, # type: ignore
|
||||||
|
'Upgrade required',
|
||||||
|
'A newer connector version is required.\nA browser will be opened to download it.',
|
||||||
|
QtWidgets.QMessageBox.Ok
|
||||||
|
)
|
||||||
|
webbrowser.open(e.downloadUrl)
|
||||||
|
return 0
|
||||||
|
logger.debug('Transport data')
|
||||||
|
script, params = api.getScriptAndParams(ticket, scrambler)
|
||||||
|
|
||||||
|
# Execute UDS transport script
|
||||||
|
exec(script, globals(), {'parent': None, 'sp': params})
|
||||||
|
# Execute the waiting task...
|
||||||
|
threading.Thread(target=endScript).start()
|
||||||
|
|
||||||
|
except RetryException as e:
|
||||||
|
QtWidgets.QMessageBox.warning(
|
||||||
|
None, # type: ignore
|
||||||
|
'Service not ready',
|
||||||
|
'{}'.format('.\n'.join(str(e).split('.'))) + '\n\nPlease, retry again in a while.' ,
|
||||||
|
QtWidgets.QMessageBox.Ok
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception('Got exception on getTransportData')
|
||||||
|
raise e
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
logger.exception('Uncaught exception')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logger.debug('Initializing connector')
|
logger.debug('Initializing connector')
|
||||||
@ -266,7 +321,7 @@ if __name__ == "__main__":
|
|||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
ssl = uri[3] == 's'
|
ssl = uri[3] == 's'
|
||||||
host, UDSClient.ticket, UDSClient.scrambler = uri.split('//')[1].split('/') # type: ignore
|
host, ticket, scrambler = uri.split('//')[1].split('/') # type: ignore
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'ssl:%s, host:%s, ticket:%s, scrambler:%s',
|
'ssl:%s, host:%s, ticket:%s, scrambler:%s',
|
||||||
ssl,
|
ssl,
|
||||||
@ -289,6 +344,13 @@ if __name__ == "__main__":
|
|||||||
['http', 'https'][ssl], host
|
['http', 'https'][ssl], host
|
||||||
), sslError)
|
), sslError)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if platform.mac_ver()[2] == 'arm64':
|
||||||
|
minimal(api, ticket, scrambler)
|
||||||
|
sys.exit(0)
|
||||||
|
except Exception:
|
||||||
|
pass # Ignore check (should not be any problem)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.debug('Starting execution')
|
logger.debug('Starting execution')
|
||||||
|
|
||||||
@ -296,7 +358,7 @@ if __name__ == "__main__":
|
|||||||
if approveHost(host) is False:
|
if approveHost(host) is False:
|
||||||
raise Exception('Host {} was not approved'.format(host))
|
raise Exception('Host {} was not approved'.format(host))
|
||||||
|
|
||||||
win = UDSClient(api)
|
win = UDSClient(api, ticket, scrambler)
|
||||||
win.show()
|
win.show()
|
||||||
|
|
||||||
win.start()
|
win.start()
|
||||||
|
Reference in New Issue
Block a user