diff --git a/forge/files/src/handle-file-urls.js b/forge/files/src/handle-file-urls.js index f6eeb170..52bd653f 100644 --- a/forge/files/src/handle-file-urls.js +++ b/forge/files/src/handle-file-urls.js @@ -1,4 +1,4 @@ -const { fileURLToPath } = require('url'); +const { fileURLToPath, pathToFileURL } = require('url'); const path = require('path'); const fs = require('fs'); const { promisify } = require('util'); @@ -32,11 +32,22 @@ async function getAssetPath(emberAppDir, url) { } module.exports = function handleFileURLs(emberAppDir) { - const { protocol } = require('electron'); + const { protocol, net } = 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;