Skip to content

Commit

Permalink
fixed tiny livestream issues
Browse files Browse the repository at this point in the history
  • Loading branch information
XFG16 committed Jun 3, 2022
1 parent 30b5896 commit 0ac4465
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "YouTubeDiscordPresence",
"author": "Michael Ren",
"description": "An extension used to create a detailed rich presence for YouTube videos and livestreams on Discord.",
"description": "An extension used to create a detailed rich presence for YouTube videos on Discord.",
"version": "1.2",
"manifest_version": 3,
"content_scripts": [
Expand Down
11 changes: 7 additions & 4 deletions Host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const bool LOGGING = false;

std::unique_ptr<discord::Core> core;
std::time_t elapsedTime = 0;
int previousTimeLeft = 0; // USED FOR SWITCHING TO LIVESTREAM PURPOSES

std::string previousTitle;
std::string previousAuthor;

// CREATE A DISCORD PRESENCE IF ONE DOESN'T ALREADY EXIST

Expand All @@ -48,7 +50,6 @@ void destroyPresence(void) {
return;
}
core.reset(nullptr);
previousTimeLeft = 0;
if (LOGGING && !core) {
std::cout << "Discord presence has been destroyed" << std::endl;
}
Expand Down Expand Up @@ -101,7 +102,7 @@ void updatePresence(const std::string& title, const std::string& author, const s
timeStamp.SetEnd(std::time(nullptr) + timeLeft);
}
else {
if (previousTimeLeft >= 0) {
if (!(previousTitle == title && previousAuthor == author)) { // MIGHT JUST BE BETTER TO HAVE BACKGROUND.JS SEND THE VIDEO ID
elapsedTime = std::time(nullptr);
}
strcpy_s(authorCString, ACTIVITY_BUFFER_SIZE, ("[LIVE] on " + author).c_str());
Expand All @@ -118,7 +119,9 @@ void updatePresence(const std::string& title, const std::string& author, const s
activityAssets.SetSmallImage("githubmark2");
activityAssets.SetSmallText("YouTubeDiscordPresence on GitHub by XFG16 (2309#2309)"); // keep this here please, so others can find the extension

previousTimeLeft = timeLeft;
previousTitle = title;
previousAuthor = author;

bool presenceUpdated = false, updatedOnce = false;
core->ActivityManager().UpdateActivity(activity, [&presenceUpdated](discord::Result result) {
presenceUpdated = true;
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# Installation (no need to download additional libraries)
1. Download the `YTDPsetup.msi` file in the [**<ins>releases section</ins>**](https://github.com/XFG16/YouTubeDiscordPresence/releases/tag/1.0) and run it on your computer
- It's gonna say Windows **blocked an unknown app** because the publisher is unknown. Just click more info and run anyway. If you run this through VirusTotal, there are gonna be several **false positives**. Sorry, but my word is the only thing I can really offer here since at the moment, I can't purchase a digital certificate.
- Otherwise, you can just **build** the whole thing yourself with **Visual Studio 2022**. Just download the `Host` directory from this repository and open `YTDPwin.sln` under `Host/YTDPwin` in Visual Studio. Also, make sure to have the **Microsoft Visual Studio Installer Project** extension installed.
2. Add the [<ins>**Chrome Extension**</ins>](https://chrome.google.com/webstore/detail/youtubediscordpresence/hnmeidgkfcbpjjjpmjmpehjdljlaeaaa) from the **Chrome Web Store** and turn it on **after installing the desktop component.** If you installed the extension before installing the desktop component, just turn it **off and back on** after the desktop component is installed.
- Otherwise, you can just **build** the whole thing yourself with **Visual Studio 2022**. Just download the `Host` directory from this repository and open `YTDPwin.sln` under `Host/YTDPwin` in Visual Studio. Also, make sure to have the **Microsoft Visual Studio Installer Project** extension installed
2. Add the [<ins>**Chrome Extension**</ins>](https://chrome.google.com/webstore/detail/youtubediscordpresence/hnmeidgkfcbpjjjpmjmpehjdljlaeaaa) from the **Chrome Web Store** and turn it on **after installing the desktop component.** If you installed the extension before installing the desktop component, just turn it **off and back on** after the desktop component is installed
3. You should be all set and ready to go! To turn this application **on or off**, just go to `chrome://extensions` and **toggle the switch** for the extension


Expand All @@ -29,10 +29,8 @@
- If Discord is closed **while the extension is running**, just switch the extension **off and back on**, and the presence should **reappear** on your profile

## Known Issues
- If you go from one livestream to another, the elapsed time continues without restarting from zero
- The appearance and disappearance of the rich presence on your profile can be delayed because Discord limits the processing of rich presence update requests to 15 seconds
- The rich presence can also randomly disappear and reappear within a few seconds because Chrome forcibly unloads and reloads the `background.js` as part of Manifest V3
- Will also cause the elapsed time for livestreams to restart

## Other Notes/Suggestions
- REMEMBER TO **TURN OFF LOGGING** FOR RELEASE VERSIONS
Expand Down

0 comments on commit 0ac4465

Please sign in to comment.