From b0ac869ad13e87b8a17d3bfc32c655373f4fe754 Mon Sep 17 00:00:00 2001 From: Phoenix / Hotaru Date: Wed, 31 May 2023 12:23:09 +0100 Subject: [PATCH 1/2] Add run as admin suggestion for windows --- client/app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/app.py b/client/app.py index cc36464..92014fa 100644 --- a/client/app.py +++ b/client/app.py @@ -437,6 +437,15 @@ def changeState(self): self.startOnLaunch.setChecked(settings.get('startOnLaunch', False)) self.startOnLaunch.toggled.connect(self.setLaunchMode) + # This just assumes that if client.rpc is set to None, that their was a permission issue preventing NSO-RPC. + # Their was an attempt at catching the [Access is denied] event in the cli, however i had scope and timing issues with it. + # We also assume that only Windows users would experence this permission oversight. + if not client.rpc and platform.system() == 'Windows': + self.label_12.setFixedWidth(self.label_12.width()+120) + self.label_12.setFixedHeight(self.label_12.height()+15) + self.label_12.setText("Unable to connect to Discord,
Try running NSO-RPC with Administrator.
") + self.toggleDiscord.setHidden(True) + # Set home self.switchMe() From 76b7e6f86c277c361444d38ae47c704cc66b88f7 Mon Sep 17 00:00:00 2001 From: Deltaion Lee <32529306+MCMi460@users.noreply.github.com> Date: Wed, 31 May 2023 15:08:04 -0500 Subject: [PATCH 2/2] Fix to what Phoenix probably wanted --- client/app.py | 35 ++++++++++++++++++++++++++--------- client/cli.py | 10 +++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/client/app.py b/client/app.py index 92014fa..0e823a8 100644 --- a/client/app.py +++ b/client/app.py @@ -243,7 +243,7 @@ def setLaunchMode(self,mode): ' ', ' Label', ' NSO-RPC.app', - ' Program', + ' Program', ' '+applicationPath+'', ' RunAtLoad', ' ', @@ -437,14 +437,7 @@ def changeState(self): self.startOnLaunch.setChecked(settings.get('startOnLaunch', False)) self.startOnLaunch.toggled.connect(self.setLaunchMode) - # This just assumes that if client.rpc is set to None, that their was a permission issue preventing NSO-RPC. - # Their was an attempt at catching the [Access is denied] event in the cli, however i had scope and timing issues with it. - # We also assume that only Windows users would experence this permission oversight. - if not client.rpc and platform.system() == 'Windows': - self.label_12.setFixedWidth(self.label_12.width()+120) - self.label_12.setFixedHeight(self.label_12.height()+15) - self.label_12.setText("Unable to connect to Discord,
Try running NSO-RPC with Administrator.
") - self.toggleDiscord.setHidden(True) + self.checkDiscordError() # Set home self.switchMe() @@ -523,6 +516,29 @@ def e(event = None): userSelected = user.nsaId + def checkDiscordError(self): + print('test') + # This just assumes that if client.rpc is set to None, then there was a permission issue preventing NSO-RPC. + # There was an attempt at catching the [Access is denied] event in the cli, however I had scope and timing issues with it. + # We also assume that only Windows users would experence this permission oversight. + # Updated by MCMi460 -- works for Admin issues as well as Discord is not running issues. + if not client.rpc: + ret = client.connect() + if not ret[0]: + msg = '' + if 'WinError 5' in str(ret[1]): + msg = 'Try running NSO-RPC with Administrator.' + elif 'Could not find Discord' in str(ret[1]): + msg = 'Try opening Discord first.' + self.label_12.setFixedWidth(self.label_12.width()+120) + self.label_12.setFixedHeight(36) + self.label_12.setText("Unable to connect to Discord!
%s
" % msg) + self.toggleDiscord.setHidden(True) + else: + self.toggleDiscord.setHidden(False) + self.label_12.setFixedHeight(21) + self.label_12.setText('Discord:') + def updateProfile(self, new): if new: client.api.targetID = userSelected @@ -630,6 +646,7 @@ def switchFriends(self): self.stackedWidget_2.setCurrentIndex(1) def switchSettings(self): + self.checkDiscordError() self.stackedWidget_2.setCurrentIndex(2) def openPfp(self, event = None): diff --git a/client/cli.py b/client/cli.py index 817ae34..8f1371f 100644 --- a/client/cli.py +++ b/client/cli.py @@ -13,7 +13,7 @@ class Discord(): def __init__(self, session_token = None, user_lang = None, rpc = False, targetID = None, version = None): self.rpc = None if rpc: - if not self.connect(): + if not self.connect()[0]: sys.exit("Failed to connect to Discord") self.running = False self.api = None @@ -38,9 +38,9 @@ def createCTX(self, session_token, user_lang, targetID = None, version = None): def connect(self): try: self.rpc = pypresence.Presence('637692124539650048') - except: + except Exception as e: self.rpc = None - return False + return (False, e) fails = 0 while True: # Attempt to connect to Discord. Will wait until it connects @@ -52,9 +52,9 @@ def connect(self): if fails > 500: print(log('Error, failed after 500 attempts\n\'%s\'' % e)) self.rpc = None - return False + return (False, e) continue - return True + return (True,) def disconnect(self): if self.rpc: