This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move rich presence to separate process
- Loading branch information
1 parent
ae539d4
commit 38cf5f1
Showing
5 changed files
with
74 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from ui import UserInterface | ||
from session import Session | ||
from player import Player | ||
from presence import Presence | ||
|
||
player = Player() | ||
ui = UserInterface(player) | ||
session = Session(ui, player) | ||
if __name__ == "__main__": | ||
presence = Presence() | ||
player = Player() | ||
ui = UserInterface(player, presence) | ||
session = Session(ui, player, presence) | ||
|
||
ui.mainloop() | ||
ui.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pypresence | ||
from tkinter import messagebox | ||
from multiprocessing import Process, shared_memory, Queue | ||
from time import sleep | ||
|
||
|
||
class Presence: | ||
def __init__(self) -> None: | ||
self.q = Queue() | ||
Process(target=self.process, daemon=True, args=(self.q,)).start() | ||
|
||
def process(self, q): | ||
self.configure() | ||
while True: | ||
item = q.get() | ||
if item != 'clear': | ||
self.apply_update(item[0], item[1], item[2]) | ||
else: | ||
self.presence.clear() | ||
sleep(1) | ||
|
||
def configure(self): | ||
try: | ||
print("start presence") | ||
self.presence = pypresence.Presence("970102086194827294") | ||
self.presence.connect() | ||
print("presence connected") | ||
except: | ||
messagebox.showerror( | ||
title="Error!", message="Could not connect to Discord.") | ||
quit() | ||
|
||
def apply_update(self, artist, track, end): | ||
self.presence.update(state="by {}".format(artist), | ||
details=track, | ||
end=end, | ||
large_image='nightwave') | ||
|
||
def update(self, artist, track, end): | ||
self.q.put((artist, track, end)) | ||
|
||
def clear(self): | ||
self.q.put('clear') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters