From 01d96efe8407c6f2cc2991f849ad39dcf595f50c Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Wed, 1 Sep 2021 22:52:50 -0400 Subject: [PATCH] resolve path correctly when intercepting requests to load files --- main/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/index.js b/main/index.js index a20c10328..f86c62892 100644 --- a/main/index.js +++ b/main/index.js @@ -10,6 +10,7 @@ app.commandLine.appendSwitch('force-color-profile', 'srgb') const log = require('electron-log') const path = require('path') +const url = require('url') const data = require('./data') const windows = require('./windows') @@ -170,11 +171,14 @@ app.on('ready', () => { // setTimeout(windows.tray, 800) // } if (app.dock) app.dock.hide() + protocol.interceptFileProtocol('file', (req, cb) => { const appOrigin = path.resolve(__dirname, '../') - const filePath = path.resolve(__dirname, req.url.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')) - if (filePath.startsWith(appOrigin)) cb({path: filePath}) // eslint-disable-line + const filePath = url.fileURLToPath(req.url) + + if (filePath.startsWith(appOrigin)) cb({ path: filePath }) // eslint-disable-line }) + store.observer(_ => { if (store('dash.showing')) { windows.showDash()