diff --git a/forge/files/src/handle-file-urls.js b/forge/files/src/handle-file-urls.js index f6eeb170..9bd4e484 100644 --- a/forge/files/src/handle-file-urls.js +++ b/forge/files/src/handle-file-urls.js @@ -1,4 +1,5 @@ -const { fileURLToPath } = require('url'); +const { net } = require('electron'); +const { fileURLToPath, pathToFileURL } = require('url'); const path = require('path'); const fs = require('fs'); const { promisify } = require('util'); @@ -34,9 +35,20 @@ async function getAssetPath(emberAppDir, url) { module.exports = function handleFileURLs(emberAppDir) { const { protocol } = require('electron'); - protocol.interceptFileProtocol('file', async ({ url }, callback) => { - callback(await getAssetPath(emberAppDir, url)); - }); + if (protocol.handle) { + // Electron >= 25 + protocol.handle('file', async ({ url }) => { + let path = await getAssetPath(emberAppDir, url); + return net.fetch(pathToFileURL(path), { + bypassCustomProtocolHandlers: true, + }); + }); + } else { + // Electron < 25 + protocol.interceptFileProtocol('file', async ({ url }, callback) => { + callback(await getAssetPath(emberAppDir, url)); + }); + } }; module.exports.getAssetPath = getAssetPath;