Skip to content

Commit

Permalink
fix: uncaught exception
Browse files Browse the repository at this point in the history
  • Loading branch information
N0chteil committed Jun 22, 2023
1 parent 600df15 commit 19d52a7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/managers/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { appDependencies, lastFM } from "../index";

import { dialog, shell } from "electron";
import { AppleBridge, fetchITunes } from "apple-bridge";
import { fetchApp } from "apple-bridge/dist/darwin";

import getAppDataPath from "../utils/getAppDataPath";

Expand All @@ -14,7 +15,7 @@ import * as path from "path";

export class Bridge {
private discord: Discord = new Discord();
private currentTrack: any = fetchITunes();
private currentTrack;
private currentlyPlaying = {
name: "",
artist: "",
Expand Down Expand Up @@ -44,6 +45,8 @@ export class Bridge {
return;
}

this.setCurrentTrack()

setTimeout(() => {
if (
this.currentTrack &&
Expand All @@ -63,6 +66,10 @@ export class Bridge {
Bridge.instance = this;
}

private async setCurrentTrack() {
this.currentTrack = await Bridge.fetchMusic();
}

private initListeners() {
this.bridge.on("playing", "music", (currentTrack) => {
if (
Expand Down Expand Up @@ -125,8 +132,8 @@ export class Bridge {
if (this.scrobbleTimeout) clearTimeout(this.scrobbleTimeout);

this.scrobbleTimeout = setTimeout(
() => {
const newTrack = fetchITunes(),
async () => {
const newTrack = await Bridge.fetchMusic(),
oldTrack = currentTrack;

delete oldTrack.snowflake;
Expand Down Expand Up @@ -297,7 +304,9 @@ export class Bridge {
return true;
}

public static getCurrentTrackArtwork(logWarn: boolean = true) {
public static async getCurrentTrackArtwork(logWarn: boolean = true) {
if (process.platform !== "win32") return;

const artwork: string | undefined = fetchITunes(
`currentTrackArtwork "${path.join(getAppDataPath(), "artwork")}"`
)?.artwork;
Expand All @@ -307,6 +316,11 @@ export class Bridge {

return artwork;
}

public static async fetchMusic() {
if (process.platform === "win32") return fetchITunes();
else return await fetchApp.appleMusic()
}
}

function generateSnowflake() {
Expand Down

0 comments on commit 19d52a7

Please sign in to comment.