Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidal HiFi Juggling Having Discord See Updates of Tracks/Songs/Etc #351

Closed
irishgordo opened this issue Feb 19, 2024 · 1 comment · Fixed by #373
Closed

Tidal HiFi Juggling Having Discord See Updates of Tracks/Songs/Etc #351

irishgordo opened this issue Feb 19, 2024 · 1 comment · Fixed by #373
Assignees
Labels
bug Something isn't working

Comments

@irishgordo
Copy link

Hey there, this project is awesome!

I was noticing some strange issues with Tidal HiFi updating Discord with either a:

  • .deb install
  • .snap install

On my loadout (system) of:

pop-os➜  tidal-hifi : master ✘ :✹ ᐅ  cat /etc/os-release
NAME="Pop!_OS"
VERSION="22.04 LTS"
ID=pop
ID_LIKE="ubuntu debian"
PRETTY_NAME="Pop!_OS 22.04 LTS"
VERSION_ID="22.04"
HOME_URL="https://pop.system76.com"
SUPPORT_URL="https://support.system76.com"
BUG_REPORT_URL="https://github.com/pop-os/pop/issues"
PRIVACY_POLICY_URL="https://system76.com/privacy"
VERSION_CODENAME=jammy
UBUNTU_CODENAME=jammy
LOGO=distributor-logo-pop-os

I decided to try to build it from source (after uninstalling either .snap or .deb) utilizing:

  • node v20.11.1
  • npm v10.2.4

And after tossing some Logger.log messages inside the src.scripts.discord.ts I was noticing that it seems to be resolving itself mostly!

The one thing is that I guess on launch, if a music file was already present in tidal hifi, like picking up where the user was previously listening to the track, I was catching a lot of logs w/ my custom log entry of media is paused... but the media wasn't paused it was playing.

In the discord.ts I had just modified this chunk to see some log data:

const getActivity = (): Presence => {
  const presence: Presence = { ...defaultPresence };

  if (mediaInfo.status === MediaStatus.paused) {
    Logger.log("media is paused...")
    presence.details =
      settingsStore.get<string, string>(settings.discord.idleText) ?? "Browsing Tidal";
  } else {
    const showSong = settingsStore.get<string, boolean>(settings.discord.showSong) ?? false;
    Logger.log("show song is?: " + showSong);
    if (showSong) {
      Logger.log("show song is present --- : " + showSong)
      const { includeTimestamps, detailsPrefix, buttonText } = getFromStore();
      includeTimeStamps(includeTimestamps);
      setPresenceFromMediaInfo(detailsPrefix, buttonText);
    } else {
      presence.details =
        settingsStore.get<string, string>(settings.discord.usingText) ?? "Playing media on TIDAL";
      Logger.log("showing the details of the precense but no song? ...");
    }
  }
  return presence;

  function getFromStore() {
    const includeTimestamps =
      settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
    const detailsPrefix =
      settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
    const buttonText =
      settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";

    Logger.log("detailsPrefix is: " + detailsPrefix);
    return { includeTimestamps, detailsPrefix, buttonText };
  }

  function setPresenceFromMediaInfo(detailsPrefix: any, buttonText: any) {
    if (mediaInfo.url) {
      Logger.log("Here is mediaInfo.url: " + mediaInfo.url);
      presence.details = `${detailsPrefix}${mediaInfo.title}`;
      presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)";
      presence.largeImageKey = mediaInfo.image;
      if (mediaInfo.album) {
        presence.largeImageText = mediaInfo.album;
      }
      presence.buttons = [{ label: buttonText, url: mediaInfo.url }];
    } else {
      presence.details = `Watching ${mediaInfo.title}`;
      presence.state = mediaInfo.artists;
    }
  }

  function includeTimeStamps(includeTimestamps: any) {
    if (includeTimestamps) {
      const currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
      const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
      const date = new Date();
      const now = (date.getTime() / 1000) | 0;
      const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
      presence.startTimestamp = now;
      presence.endTimestamp = remaining;
    }
  }
};

/**
 * Set up the discord rpc and listen on globalEvents.updateInfo
 */
export const initRPC = () => {
  rpc = new Client({ transport: "ipc" });
  rpc.login({ clientId }).then(
    () => {
      rpc.on("ready", () => {
        Logger.log("rpc is ready...")
        rpc.setActivity(getActivity());
      });
      ipcMain.on(globalEvents.updateInfo, observer);
    },
    () => {
      Logger.log("Can't connect to Discord, is it running?");
    }
  );
};

Workaround

Even if it is displaying media is paused when the media is playing at first launch, the moment you switch to another track it resolves itself to actually show that track information in Discord accurately.

Questions

  • I guess I'm curious as to what the difference is between running this from source off the master branch in comparison to running this off a .deb / .snap package.
    As with running from an installed .deb package in my system, for some reason, Discord isn't really getting any updates from Tidal HiFi, it just seems to hang at "Browsing Tidal".

Additional context, Discord is installed on my little rig via just the package manager.

I think for now, just doing an npm compile & npm run start alleviates Discord from not seeing updates - wondering though if it's possible to debug the .deb package to see what differences might be in the loadout.

Screenshot from 2024-02-19 13-20-27

@Mastermindzh
Copy link
Owner

Mastermindzh commented Feb 21, 2024

Will have to look at the startup sequence & variable instantiation 😄.
Thanks for the solid issue!
Luckily it doesn't affect anything after the first song.

I guess I'm curious as to what the difference is between running this from source off the master branch in comparison to running this off a .deb / .snap package.
As with running from an installed .deb package in my system, for some reason, Discord isn't really getting any updates from Tidal HiFi, it just seems to hang at "Browsing Tidal".

Snaps are sandboxed by default and need to be allowed to talk to system interfaces.

@Mastermindzh Mastermindzh self-assigned this Feb 29, 2024
@Mastermindzh Mastermindzh added the bug Something isn't working label Feb 29, 2024
Mastermindzh added a commit that referenced this issue Mar 24, 2024
@Mastermindzh Mastermindzh mentioned this issue Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants