From 52769a228087d8c226755098828ea25dded263c9 Mon Sep 17 00:00:00 2001 From: nukeop Date: Thu, 14 Apr 2022 02:07:54 +0200 Subject: [PATCH] Fix importing ipcRenderer in the webview-imported script --- .../app/app/containers/SpotifyPlaylistImporter/hooks.tsx | 3 ++- packages/core/src/helpers/playlist/spotify.ts | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/app/app/containers/SpotifyPlaylistImporter/hooks.tsx b/packages/app/app/containers/SpotifyPlaylistImporter/hooks.tsx index 658152c3c4..df716206c7 100644 --- a/packages/app/app/containers/SpotifyPlaylistImporter/hooks.tsx +++ b/packages/app/app/containers/SpotifyPlaylistImporter/hooks.tsx @@ -61,7 +61,8 @@ export const useSpotifyPlaylistImporterProps = (t: TFunction) => { const ipcRenderer = window.require('electron').ipcRenderer; (${extractPlaylist.toString()})() })()` - .replaceAll('electron__WEBPACK_IMPORTED_MODULE_0__.', ''); + .replaceAll('electron__WEBPACK_IMPORTED_MODULE_0__.', '') + .replaceAll('a(\'electron\')', 'window.require(\'electron\'))'); w.executeJavaScript(js); }, 1500); diff --git a/packages/core/src/helpers/playlist/spotify.ts b/packages/core/src/helpers/playlist/spotify.ts index 8958d2e7c0..2b285e1b2b 100644 --- a/packages/core/src/helpers/playlist/spotify.ts +++ b/packages/core/src/helpers/playlist/spotify.ts @@ -1,5 +1,5 @@ -import { ipcRenderer } from 'electron'; - +/* eslint-disable node/no-extraneous-require */ +/* eslint-disable @typescript-eslint/no-var-requires */ type SpotifyTrack = { index: number; id?: string; @@ -19,6 +19,8 @@ type SpotifyPlaylist = { } export default (async function () { + const { ipcRenderer } = window.require('electron'); + function getPlaylistGeneralInfo() { const tracklistContainer = document.querySelector('div[data-testid="playlist-tracklist"]'); const totalTracks = parseInt( @@ -45,7 +47,6 @@ export default (async function () { } function getTracksFromDOM(processedIndex) { - const nodeTracks = document.querySelector('div[data-testid="top-sentinel"] + div').childNodes as NodeListOf; const tracks = []; @@ -139,7 +140,6 @@ export default (async function () { y += scrollHeight; await wait(1000); - } playlist.tracks = extractedTracks;