Skip to content

Commit

Permalink
[AMR-17] fix: executing macOS script on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
N0chteil committed Oct 24, 2022
1 parent f664f1b commit 56567e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/darwin/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AppleBridge } from "../index";
import { exec } from "child-process-promise";

import * as path from "path";

setInterval(fetchAll, 1000);
if (process.platform === "darwin") setInterval(fetchAll, 1000);

function fetchAll() {
fetchAppleMusic();
Expand All @@ -15,10 +16,13 @@ function fetchAll() {
*/
async function fetchAppleMusic() {
if (
AppleBridge.getInstance().emitter.listenerCount("music:playing") ===
process.platform !== "darwin" ||
(AppleBridge.getInstance().emitter.listenerCount("music:playing") ===
0 &&
AppleBridge.getInstance().emitter.listenerCount("music:paused") === 0 &&
AppleBridge.getInstance().emitter.listenerCount("music:stopped") === 0
AppleBridge.getInstance().emitter.listenerCount("music:paused") ===
0 &&
AppleBridge.getInstance().emitter.listenerCount("music:stopped") ===
0)
)
return;

Expand All @@ -45,6 +49,8 @@ export async function getPlayerState(): Promise<PlayerState> {

export const fetchApp = {
appleMusic: async (): Promise<TrackData> => {
if (process.platform !== "darwin") return;

const data: string[] = (
await exec(
`osascript ${path.resolve(
Expand Down
14 changes: 10 additions & 4 deletions src/win32/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AppleBridge } from "../index";
import { execSync } from "child_process";

import * as path from "path";

setInterval(fetchAll, 1000);
if (process.platform === "win32") setInterval(fetchAll, 1000);

function fetchAll() {
fetchAppleMusic();
Expand All @@ -15,10 +16,13 @@ function fetchAll() {
*/
function fetchAppleMusic() {
if (
AppleBridge.getInstance().emitter.listenerCount("music:playing") ===
process.platform !== "win32" ||
(AppleBridge.getInstance().emitter.listenerCount("music:playing") ===
0 &&
AppleBridge.getInstance().emitter.listenerCount("music:paused") === 0 &&
AppleBridge.getInstance().emitter.listenerCount("music:stopped") === 0
AppleBridge.getInstance().emitter.listenerCount("music:paused") ===
0 &&
AppleBridge.getInstance().emitter.listenerCount("music:stopped") ===
0)
)
return;

Expand All @@ -38,6 +42,8 @@ export function getPlayerState(): PlayerState {
}

export function fetchITunes(type = "currentTrack") {
if (process.platform !== "win32") return;

const data = execSync(
`cscript //Nologo "${path.join(
__dirname,
Expand Down

0 comments on commit 56567e4

Please sign in to comment.