Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run as admin suggestion for Windows #78

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def setLaunchMode(self,mode):
' <dict>',
' <key>Label</key>',
' <string>NSO-RPC.app</string>',
' <key>Program</key>',
' <key>Program</key>',
' <string>'+applicationPath+'</string>',
' <key>RunAtLoad</key>',
' <true/>',
Expand Down Expand Up @@ -437,6 +437,8 @@ def changeState(self):
self.startOnLaunch.setChecked(settings.get('startOnLaunch', False))
self.startOnLaunch.toggled.connect(self.setLaunchMode)

self.checkDiscordError()

# Set home
self.switchMe()

Expand Down Expand Up @@ -514,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("<a style='color: orange;'>Unable to connect to Discord!<br>%s</a>" % 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
Expand Down Expand Up @@ -621,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):
Expand Down
10 changes: 5 additions & 5 deletions client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down