PreMiD / Extension-old

🧩 Source code of the official PreMiD extension.
https://premid.app/
Mozilla Public License 2.0
75 stars 28 forks source link

RPC keeps showing even after I switch/close tab #240

Closed karimawi closed 1 month ago

karimawi commented 2 years ago

I use only 2 presences, AniMixPlay and Twitch, both of them keep sticking to my Discord profile even after I switch tabs or even close them, it eventually closes (sometimes doesn't at all) but it's so random, sometimes it closes after a couple of minutes, some times an hour, sometimes even more

What it's supposed to do: Remove the presence from profile as soon as I switch/close the tab with the presence, or add an option for every presence (or all presences if adding the setting for everyone would be a pain) to toggle the sticky presence thing, whether it should keep the presence even when you switch tabs or not, and for closing tabs I don't think it should keep the presence at all, that's clearly a bug, and I don't know if someone else is having it.

Version: PreMiD v2.2.0 | Ext v2.2.3 OS: Windows 10 64-Bit Version 21H1 Browser: Google Chrome Version 104.0.5112.81 (Official Build) (64-bit)

EncryptedDev commented 2 years ago

This is a known bug. The following may help:

karimawi commented 2 years ago

I didn't actually try to reinstall it so I'm going to try that, but for the antivirus part I only use Windows Defender and it didn't recognize PreMiD or any of its connections as suspicious afaict so, I'll just try reinstalling it, if the issue presists, I'll let you know, thanks for the resppnse.

EncryptedDev commented 2 years ago

Awesome. For this sort of issue, it is best if you raise your issue in our Support Discord server. discord.gg/premid

karimawi commented 2 years ago

Sure, so I keep this issue open? Then when I try the reinstall I go to the Discord? Right?

karimawi commented 2 years ago

Hey, I reinstalled, got the same issue, reached out to Discord support, here's the ticket conversation:

Screenshot_20220815-164132_Discord

Can this toggle be implemented? Cause I find it very annoying to have a presence stuck on your profile the whole time when it's not even what you're doing/watching/hearing etc..

Timeraa commented 1 year ago

Moving this to the Extension repo as it's a Extension bug but also Application bug could cause this. Should be fixed with v2.5

karimawi commented 5 months ago

I don't know if something like that would work for Chrome, using the "active" and the "lastFocusedWindow" bools alongside each other to determine whether the tab is focused or not, there's already an implementation for this in tabPriority.ts async function but I'm not experienced enough with JS/TS to know why it's not working properly.

function checkTabFocusState(tabId, callback) {
  chrome.tabs.query({ active: true, lastFocusedWindow: true }, function(tabs) {
    if (tabs.length > 0) {
      const currentTab = tabs[0];
      const isFocused = (currentTab.id === tabId);
      callback(isFocused);
    } else {
      callback(false);
    }
  });
}

And then use some event listeners to implement the above function:

chrome.tabs.onActivated.addListener(function(activeInfo) {
  checkTabFocusState(activeInfo.tabId, function(isFocused) {
    if (isFocused) {
      console.log(`Tab ${activeInfo.tabId} is now focused.`);
    }
  });
});

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  if (changeInfo.status === 'complete') {
    checkTabFocusState(tabId, function(isFocused) {
      if (isFocused) {
        console.log(`Tab ${tabId} is now focused.`);
      }
    });
  }
});

The "chrome.windows.onFocusChanged" can be used as well to detect if Chrome is even focused by the system in the first place, maybe the tab is focused but chrome is minimized, and if it's minimized the presence can still be show if a site is playing media which can be detected using the "audible" bool property for the tab object that is equivalent to the speaker icon appearing on the tab (as described in the docs)

An alternative would be using the visibilitychange API but I don't actually think that would work properly across all browsers as it's not exactly designed for tab changes, I just thought I'd throw it here if it sparks something.

karimawi commented 5 months ago

Moving this to the Extension repo as it's a Extension bug but also Application bug could cause this. Should be fixed with v2.5

Hey, @Timeraa thanks for the transfer (just noticed your comment a year+ later 💀, srry), I'm running 2.6, I have a new device now running Win11, I'm having the same exact issue as well as some other people who opened issues in the wrong repo again (idk who'd do such thing that's very weird).

Timeraa commented 5 months ago

It should be a lot better now but we're working hard on it all