Skip to content

Commit

Permalink
Allow online indicator on first login #28
Browse files Browse the repository at this point in the history
  • Loading branch information
mak448a committed Aug 11, 2024
1 parent 5e1df54 commit b6f17c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/discord_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# DISCLAIMER: Some of this code has been written by ChatGPT. Be warned.


import threading
import json
import time
Expand All @@ -10,13 +9,9 @@
import websocket


# Get Discord token
if os.path.isfile(platformdirs.user_config_dir("QTCord") + "/discordauth.txt"):
with open(platformdirs.user_config_dir("QTCord") + "/discordauth.txt") as f:
bot_token = f.read()

# This will be set later
heartbeat_interval = None
bot_token = None


def _start():
Expand Down Expand Up @@ -80,4 +75,13 @@ def send_heartbeat():


def keep_online():
# Get Discord token
if os.path.isfile(platformdirs.user_config_dir("QTCord") + "/discordauth.txt"):
with open(platformdirs.user_config_dir("QTCord") + "/discordauth.txt") as f:
bot_token = f.read()

# Stop if bot token isn't defined
if not bot_token:
return

threading.Thread(target=_start, daemon=True).start()
11 changes: 9 additions & 2 deletions src/login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PySide6.QtWidgets import QMainWindow
from ui import login_ui
from discord_integration import login, load_token
from discord_integration import login, load_token, keep_online
import platformdirs


Expand All @@ -18,12 +18,14 @@ def __init__(self, switcher, parent=None):
self.ui.password.returnPressed.connect(self.switch)

def switch(self):
# Grab email and password from the UI fields
email = self.ui.email.text()
password = self.ui.password.text()
# Check on our end before validating with Discord
valid = email and password

if valid:
# Reset our UI elements
# Reset UI elements
self.ui.email.setText("")
self.ui.password.setText("")
self.ui.info_frame.hide()
Expand All @@ -32,13 +34,18 @@ def switch(self):
_token = login(email, password)

if _token:
# Save the token
with open(
platformdirs.user_config_dir("QTCord") + "/discordauth.txt", "w"
) as f:
f.write(_token)

# Load the token
load_token()

# Open a connection to Discord to add the online indicator
keep_online()

# Switch the page to the chat page
self.switcher.setCurrentIndex(self.switcher.currentIndex() + 1)
else:
Expand Down
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def _update_text(self, messages):
self.ui.textBrowser.verticalScrollBar().setValue(self.ui.textBrowser.verticalScrollBar().maximum())

def setup(self):
discord_integration.keep_online()
if auth:
discord_integration.keep_online()

self.connect_signal_slots()

self.ui.lineEdit.setFocus()
Expand Down

0 comments on commit b6f17c6

Please sign in to comment.