Skip to content

Commit

Permalink
Added a default token delete option for failed auths.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownpersonog committed Jul 11, 2024
1 parent f51fd60 commit bb2ce85
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ def upload_to_drive(self):
self.authenticate_drive()
except Exception as e:
QMessageBox.warning(self, "Authentication Error", f"Failed to authenticate: {str(e)}")
return
return

try:
with open(os.path.join(STUDY_MATERIAL_ROOT, '.token.json'), 'r') as token:
token_info = json.load(token)
Expand All @@ -609,7 +609,21 @@ def upload_to_drive(self):
)
self.drive_service = build('drive', 'v3', credentials=self.credentials)
except Exception as e:
QMessageBox.warning(self, "Drive Service Error", f"Failed to create Drive service: {str(e)}")
msg_box = QMessageBox(self)
msg_box.setIcon(QMessageBox.Warning)
msg_box.setWindowTitle("Drive Service Error")
msg_box.setText(f"Failed to create Drive service: {str(e)}")
msg_box.setInformativeText("Would you like to delete the token.json file?")
msg_box.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
delete_button = msg_box.addButton("Delete", QMessageBox.DestructiveRole)
msg_box.exec_()

if msg_box.clickedButton() == delete_button:
try:
os.remove(os.path.join(STUDY_MATERIAL_ROOT, '.token.json'))
QMessageBox.information(self, "Token Deleted", "The token.json file has been deleted. Please re-authenticate.")
except Exception as del_e:
QMessageBox.warning(self, "Deletion Error", f"Failed to delete token.json: {str(del_e)}")
return

if self.drive_service:
Expand Down

0 comments on commit bb2ce85

Please sign in to comment.