Dynamically import poTokenAndroid

This commit is contained in:
WardPearce
2024-09-19 20:46:50 +12:00
parent 7c0d5a6fb0
commit e5a137d7b4
2 changed files with 8 additions and 6 deletions
@@ -11,16 +11,18 @@ export async function getPoToken(): Promise<PoTokens> {
const messageListener = async (data: any) => {
await InAppBrowser.close();
resolve(data);
InAppBrowser.removeAllListeners(); // Clean up the listener
await InAppBrowser.clearAllCookies();
await InAppBrowser.clearCache();
await InAppBrowser.removeAllListeners();
};
const closeListener = async () => {
await InAppBrowser.clearAllCookies();
await InAppBrowser.clearCache();
await InAppBrowser.removeAllListeners();
};
const urlChangeListener = async () => {
await InAppBrowser.clearAllCookies();
await InAppBrowser.clearCache();
// Code must be minified to ensure runs correctly.
await InAppBrowser.executeScript({
@@ -67,7 +69,7 @@ attemptClickPlayButton();
InAppBrowser.addListener('urlChangeEvent', urlChangeListener);
setTimeout(() => {
reject(new Error('Timeout waiting for message'));
reject(new Error('Timeout trying to pull Po tokens'));
InAppBrowser.removeAllListeners();
}, 10000);
+2 -2
View File
@@ -3,7 +3,7 @@ import { numberWithCommas } from '$lib/misc';
import { poTokenCacheStore } from '$lib/store';
import { Capacitor } from '@capacitor/core';
import { get } from 'svelte/store';
import { getPoToken, type PoTokens } from './poTokenAndroid';
import { type PoTokens } from './poTokenAndroid';
export async function patchYoutubeJs(videoId: string): Promise<VideoPlay> {
const innertube = (await import('youtubei.js')).Innertube;
@@ -15,7 +15,7 @@ export async function patchYoutubeJs(videoId: string): Promise<VideoPlay> {
if (Capacitor.getPlatform() === 'electron') {
tokens = await (window as any).electron.generatePoToken();
} else if (Capacitor.getPlatform() === 'android') {
tokens = await getPoToken();
tokens = await (await import('../../lib/patches/poTokenAndroid')).getPoToken();
} else {
throw new Error('This platform cant generate po tokens');
}