Skip to content

Commit 1d81557

Browse files
committed
fix: MusicKit failing playback on Android
This makes it so CapacitorHttp patched fetch is available under window.capacitorFetch rather than overwriting window.fetch
1 parent a1c055e commit 1d81557

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/electron.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* This module gets ran on the initialization on Electron
2+
* This module gets ran on the initialization of Electron
33
* @module
44
*/
5-
/* eslint-disable no-var */
65

76
declare global {
7+
// eslint-disable-next-line no-var
88
var __IS_ELECTRON__: boolean;
99

1010
interface $ElectronMusicPlayer {
@@ -26,11 +26,14 @@ declare global {
2626
readFile: (path: string) => Promise<Uint8Array>;
2727
traverseDirectory: (path: string) => Promise<string[]>;
2828
}
29+
30+
// eslint-disable-next-line no-var
2931
var $ElectronMusicPlayer: $ElectronMusicPlayer | undefined;
3032

3133
interface ElectronMusicPlayer extends $ElectronMusicPlayer {
3234
fetchShim: typeof globalThis.fetch;
3335
}
36+
// eslint-disable-next-line no-var
3437
var ElectronMusicPlayer: ElectronMusicPlayer | undefined;
3538
}
3639

src/main.ts

+3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ import "@ionic/vue/css/palettes/dark.system.css";
3636

3737
/* Theme variables */
3838
import "./theme/variables.css";
39+
import { isMobilePlatform } from "./utils/os";
3940

4041
/* Vue store */
4142
const pinia = createPinia();
4243

4344
if (__IS_ELECTRON__) {
4445
await import("./electron");
46+
} else if (isMobilePlatform()) {
47+
void import("./mobile");
4548
}
4649

4750
const app = createApp(App).use(IonicVue).use(pinia).use(router);

src/mobile.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* This module gets ran on the initialization of Mobile devices
3+
* @module
4+
*/
5+
6+
declare global {
7+
// eslint-disable-next-line no-var
8+
var capacitorFetch: typeof window.fetch;
9+
}
10+
11+
const capacitorPatchedFetch = window.fetch;
12+
const webFetch = "CapacitorWebFetch" in window && (window.CapacitorWebFetch as typeof window.fetch);
13+
14+
if (webFetch) {
15+
window.fetch = webFetch;
16+
window.capacitorFetch = capacitorPatchedFetch;
17+
}
18+
19+
export {};

src/services/MusicPlayer/YouTubeMusicPlayerService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class YouTubeMusicPlayerService extends MusicPlayerService<YouTubeSong> {
158158
// youtube.js seems to be destructurizing fetch somewhere, which causes
159159
// "Illegal Invocation error", so we just provide our own
160160
// TODO: Proxy for web support
161-
const fetch = isElectron() ? ElectronMusicPlayer!.fetchShim : window.fetch.bind(window);
161+
const fetch = isElectron() ? ElectronMusicPlayer!.fetchShim : window.capacitorFetch;
162162

163163
const tmp = await Innertube.create({
164164
generate_session_locally: false,

0 commit comments

Comments
 (0)